mirror of
https://github.com/edufeed-org/polloer.git
synced 2025-12-09 16:24:31 +00:00
only react one time per browser
This commit is contained in:
parent
333da0ceb6
commit
40aeab5879
1 changed files with 18 additions and 9 deletions
|
|
@ -8,6 +8,7 @@
|
||||||
import { login } from '$lib';
|
import { login } from '$lib';
|
||||||
|
|
||||||
let reactions = writable([]);
|
let reactions = writable([]);
|
||||||
|
let reacted = writable(window.localStorage.getItem(event.id));
|
||||||
|
|
||||||
async function sendReaction() {
|
async function sendReaction() {
|
||||||
const reactionEvent = new NDKEvent($ndk, {
|
const reactionEvent = new NDKEvent($ndk, {
|
||||||
|
|
@ -16,9 +17,11 @@
|
||||||
tags: [['e', event.id]]
|
tags: [['e', event.id]]
|
||||||
});
|
});
|
||||||
await reactionEvent.publish();
|
await reactionEvent.publish();
|
||||||
const r = await $ndk.fetchEvents({kinds: [7], "#e": [event.id]})
|
const r = await $ndk.fetchEvents({ kinds: [7], '#e': [event.id] });
|
||||||
console.log("r", r)
|
console.log('r', r);
|
||||||
$reactions = Array.from(r);
|
$reactions = Array.from(r);
|
||||||
|
window.localStorage.setItem(event.id, 'true');
|
||||||
|
$reacted = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
|
|
@ -26,15 +29,21 @@
|
||||||
console.log('no user, logging in');
|
console.log('no user, logging in');
|
||||||
login();
|
login();
|
||||||
}
|
}
|
||||||
const r = await $ndk.fetchEvents({kinds: [7], "#e": [event.id]})
|
const r = await $ndk.fetchEvents({ kinds: [7], '#e': [event.id] });
|
||||||
console.log("r", r)
|
console.log('r', r);
|
||||||
$reactions = Array.from(r);
|
$reactions = Array.from(r);
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="w-full border p-2">
|
<div class="w-full border p-2">
|
||||||
<p>{event.content}</p>
|
<p>{event.content}</p>
|
||||||
<button onclick={() => sendReaction()}>👍</button>
|
<div class="flex gap-2">
|
||||||
<p>Reaction Count: {$reactions.length}</p>
|
{#if $reacted}
|
||||||
|
<span>👍 {$reactions.length}</span>
|
||||||
|
<span>Danke für deinen Vote!</span>
|
||||||
|
{:else}
|
||||||
|
<button onclick={() => sendReaction()}>👍</button>
|
||||||
|
<span>{$reactions.length}</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue