You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

34 lines
842 B

import { Controller } from '@hotwired/stimulus';
/**
* Shows or hides the "Edit magazine" footer link when auth changes without a full page reload.
*/
export default class extends Controller {
static values = {
publisherNpub: String,
};
connect() {
this.boundOnAuth ??= this.onAuthChanged.bind(this);
window.removeEventListener('unfold:auth-changed', this.boundOnAuth);
window.addEventListener('unfold:auth-changed', this.boundOnAuth);
}
disconnect() {
window.removeEventListener('unfold:auth-changed', this.boundOnAuth);
}
onAuthChanged(event) {
const d = event.detail;
if (!d) {
return;
}
if (d.loggedIn === false) {
this.element.hidden = true;
return;
}
if (d.loggedIn && d.npub === this.publisherNpubValue) {
this.element.hidden = false;
}
}
}