mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-nostr.git
synced 2025-12-13 05:26:47 +00:00
voting system with nostr added
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
import {Alpine, Livewire} from '../../vendor/livewire/livewire/dist/livewire.esm';
|
||||
|
||||
import nostrApp from "./nostrApp.js";
|
||||
import nostrLogin from "./nostrLogin.js";
|
||||
|
||||
import './bootstrap';
|
||||
|
||||
// Light switcher
|
||||
@@ -6,3 +11,12 @@ document.documentElement.classList.add('dark');
|
||||
document.querySelector('html').style.colorScheme = 'dark';
|
||||
localStorage.setItem('dark-mode', true);
|
||||
document.dispatchEvent(new CustomEvent('darkMode', { detail: { mode: 'on' } }));
|
||||
|
||||
Alpine.store('nostr', {
|
||||
user: null,
|
||||
});
|
||||
|
||||
Alpine.data('nostrApp', nostrApp);
|
||||
Alpine.data('nostrLogin', nostrLogin);
|
||||
|
||||
Livewire.start();
|
||||
|
||||
15
resources/js/nostrApp.js
Normal file
15
resources/js/nostrApp.js
Normal file
@@ -0,0 +1,15 @@
|
||||
export default (livewireComponent) => ({
|
||||
|
||||
signThisEvent: livewireComponent.entangle('signThisEvent'),
|
||||
|
||||
init() {
|
||||
// on change of signThisEvent, call the method
|
||||
this.$watch('signThisEvent', async () => {
|
||||
const toBeSigned = JSON.parse(this.signThisEvent);
|
||||
console.log(toBeSigned);
|
||||
const signedEvent = await window.nostr.signEvent(toBeSigned);
|
||||
this.$wire.call('signEvent', signedEvent);
|
||||
});
|
||||
},
|
||||
|
||||
});
|
||||
29
resources/js/nostrLogin.js
Normal file
29
resources/js/nostrLogin.js
Normal file
@@ -0,0 +1,29 @@
|
||||
export default () => ({
|
||||
|
||||
openNostrLogin() {
|
||||
window.nostr.getPublicKey();
|
||||
},
|
||||
|
||||
init() {
|
||||
// listen for nostr auth events
|
||||
document.addEventListener('nlAuth', (e) => {
|
||||
// type is login, signup or logout
|
||||
if (e.detail.type === 'login' || e.detail.type === 'signup') {
|
||||
console.log('User logged in');
|
||||
// fetch profile from /api/nostr/profile/{publicKey}
|
||||
fetch('/api/nostr/profile/' + e.detail.pubkey)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('Profile fetched', data);
|
||||
// store the profile in AlpineJS store
|
||||
Alpine.store('nostr', { user: data });
|
||||
this.$dispatch('nostrLoggedIn', {pubkey: data.pubkey});
|
||||
});
|
||||
} else {
|
||||
console.log('User logged out')
|
||||
Alpine.store('nostr', { user: null });
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user