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'; @@ -2,10 +2,25 @@ import { Controller } from '@hotwired/stimulus';
import { getComponent } from '@symfony/ux-live-component';
export default class extends Controller {
static targets = ['nostrError'];
async initialize() {
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 = [
['u', window.location.origin + '/login'],
['method', 'POST'],
@ -35,4 +50,3 @@ export default class extends Controller { @@ -35,4 +50,3 @@ export default class extends Controller {
}
}
}

1
templates/components/UserMenu.html.twig

@ -31,6 +31,7 @@ @@ -31,6 +31,7 @@
</span>
<ul>
<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>
</li>
<li>

Loading…
Cancel
Save