From 40aeab5879d47efd0df692a26429ad5fb1a32dac Mon Sep 17 00:00:00 2001 From: "@s.roertgen" Date: Wed, 30 Apr 2025 10:08:43 +0200 Subject: [PATCH] only react one time per browser --- src/lib/components/Comment.svelte | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/lib/components/Comment.svelte b/src/lib/components/Comment.svelte index 8eafdcb..6342054 100644 --- a/src/lib/components/Comment.svelte +++ b/src/lib/components/Comment.svelte @@ -8,6 +8,7 @@ import { login } from '$lib'; let reactions = writable([]); + let reacted = writable(window.localStorage.getItem(event.id)); async function sendReaction() { const reactionEvent = new NDKEvent($ndk, { @@ -16,9 +17,11 @@ tags: [['e', event.id]] }); await reactionEvent.publish(); - const r = await $ndk.fetchEvents({kinds: [7], "#e": [event.id]}) - console.log("r", r) - $reactions = Array.from(r); + const r = await $ndk.fetchEvents({ kinds: [7], '#e': [event.id] }); + console.log('r', r); + $reactions = Array.from(r); + window.localStorage.setItem(event.id, 'true'); + $reacted = true; } onMount(async () => { @@ -26,15 +29,21 @@ console.log('no user, logging in'); login(); } - const r = await $ndk.fetchEvents({kinds: [7], "#e": [event.id]}) - console.log("r", r) - $reactions = Array.from(r); + const r = await $ndk.fetchEvents({ kinds: [7], '#e': [event.id] }); + console.log('r', r); + $reactions = Array.from(r); }); -

{event.content}

- -

Reaction Count: {$reactions.length}

+
+ {#if $reacted} + πŸ‘ {$reactions.length} + Danke fΓΌr deinen Vote! + {:else} + + {$reactions.length} + {/if} +