Browse Source

Pass error info

imwald
Nuša Pukšič 3 months ago
parent
commit
3e1b50bed7
  1. 18
      assets/controllers/login_controller.js
  2. 1
      templates/components/UserMenu.html.twig

18
assets/controllers/login_controller.js

@ -2,10 +2,25 @@ import { Controller } from '@hotwired/stimulus';
import { getComponent } from '@symfony/ux-live-component'; import { getComponent } from '@symfony/ux-live-component';
export default class extends Controller { export default class extends Controller {
static targets = ['nostrError'];
async initialize() { async initialize() {
this.component = await getComponent(this.element); this.component = await getComponent(this.element);
} }
async loginAct() { async loginAct(event) {
if (!window.nostr) {
if (this.hasNostrErrorTarget) {
this.nostrErrorTarget.textContent = 'Extension is not available.';
this.nostrErrorTarget.style.display = 'block';
}
event?.preventDefault();
return;
}
if (this.hasNostrErrorTarget) {
this.nostrErrorTarget.textContent = '';
this.nostrErrorTarget.style.display = 'none';
}
const tags = [ const tags = [
['u', window.location.origin + '/login'], ['u', window.location.origin + '/login'],
['method', 'POST'], ['method', 'POST'],
@ -35,4 +50,3 @@ export default class extends Controller {
} }
} }
} }

1
templates/components/UserMenu.html.twig

@ -31,6 +31,7 @@
</span> </span>
<ul> <ul>
<li> <li>
<div data-login-target="nostrError" class="nostr-error-message" style="display:none;color:#b00;margin-bottom:0.5em;"></div>
<twig:Atoms:Button {{ ...stimulus_action('login', 'loginAct') }} tag="a" variant="accent">Extension</twig:Atoms:Button> <twig:Atoms:Button {{ ...stimulus_action('login', 'loginAct') }} tag="a" variant="accent">Extension</twig:Atoms:Button>
</li> </li>
<li> <li>

Loading…
Cancel
Save