login onMount

This commit is contained in:
@s.roertgen 2025-04-30 10:16:48 +02:00
parent 50f6ed9306
commit e5e53d4968
2 changed files with 27 additions and 1 deletions

View file

@ -24,6 +24,20 @@
$reacted = true;
}
async function deleteVote() {
const deletionEvent = new NDKEvent($ndk, {
kind: 5,
content: "User deleted vote",
tags: [
["e", event.id],
["k", 7]
]
})
await deletionEvent.publish()
window.localStorage.removeItem(event.id)
$reacted = false
}
onMount(async () => {
if (!$user) {
console.log('no user, logging in');
@ -41,6 +55,7 @@
{#if $reacted}
<span>👍 {$reactions.length}</span>
<span>Danke für deinen Vote!</span>
<button onclick={() => deleteVote()} class="btn">Vote zurückziehen</button>
{:else}
<button onclick={() => sendReaction()}>👍</button>
<span>{$reactions.length}</span>

View file

@ -2,10 +2,13 @@
/** @type {import('./$types').PageProps} */
let { data } = $props();
import { onMount } from 'svelte';
import Comment from '$lib/components/Comment.svelte';
import { ndk, connected, ndkReady } from '$lib/stores';
import { ndk, connected, ndkReady, user } from '$lib/stores';
import { NDKEvent } from '@nostr-dev-kit/ndk';
import { writable } from 'svelte/store';
import { login } from '$lib';
function submitComment() {
const commentEvent = new NDKEvent($ndk, {
@ -19,6 +22,14 @@
let comment = '';
let comments = writable([]);
onMount(async () => {
if (!$user) {
console.log('no user, logging in');
login();
}
});
$effect(() => {
if ($ndkReady) {
console.log('ndk ready');