mirror of
https://github.com/edufeed-org/polloer.git
synced 2025-12-09 16:24:31 +00:00
Merge remote-tracking branch 'origin/addressable-events'
# Conflicts: # src/lib/components/Comment.svelte # src/routes/+page.svelte # src/routes/q/[id]/+page.svelte
This commit is contained in:
commit
1a7da6d1c1
4 changed files with 46 additions and 17 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
<script>
|
<script>
|
||||||
let { event } = $props();
|
let { event, showReactions } = $props();
|
||||||
|
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
import { NDKEvent } from '@nostr-dev-kit/ndk';
|
||||||
|
|
@ -10,6 +10,9 @@
|
||||||
import 'carta-md/default.css'; /* Default theme */
|
import 'carta-md/default.css'; /* Default theme */
|
||||||
import DOMPurify from 'dompurify';
|
import DOMPurify from 'dompurify';
|
||||||
|
|
||||||
|
console.log("show reactions", showReactions)
|
||||||
|
|
||||||
|
|
||||||
// Create a new instance of Carta (you might also want to add a sanitizer if you're processing user input)
|
// Create a new instance of Carta (you might also want to add a sanitizer if you're processing user input)
|
||||||
let carta = new Carta({
|
let carta = new Carta({
|
||||||
sanitizer: DOMPurify.sanitize
|
sanitizer: DOMPurify.sanitize
|
||||||
|
|
@ -61,7 +64,7 @@
|
||||||
<span>👍 {$reactions.length}</span>
|
<span>👍 {$reactions.length}</span>
|
||||||
<span class="thanks">Danke für deinen Vote!</span>
|
<span class="thanks">Danke für deinen Vote!</span>
|
||||||
<!-- <button onclick={() => deleteVote()} class="btn">Vote zurückziehen</button> -->
|
<!-- <button onclick={() => deleteVote()} class="btn">Vote zurückziehen</button> -->
|
||||||
{:else}
|
{:else if showReactions === "true"}
|
||||||
<button onclick={() => sendReaction()} class="like">👍</button>
|
<button onclick={() => sendReaction()} class="like">👍</button>
|
||||||
<span>{$reactions.length}</span>
|
<span>{$reactions.length}</span>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,9 @@ export async function login() {
|
||||||
userStore.set(signedUser)
|
userStore.set(signedUser)
|
||||||
|
|
||||||
window.localStorage.setItem('nostrPrivateKey', JSON.stringify(privateKey.privateKey));
|
window.localStorage.setItem('nostrPrivateKey', JSON.stringify(privateKey.privateKey));
|
||||||
|
ndk.signer = signer;
|
||||||
|
console.log("ndk signer", ndk)
|
||||||
|
ndkStore.set(ndk)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@
|
||||||
let timer = 0;
|
let timer = 0;
|
||||||
let votingEnabled = false;
|
let votingEnabled = false;
|
||||||
let sessionId = '';
|
let sessionId = '';
|
||||||
|
let event = writable();
|
||||||
|
|
||||||
async function joinSession() {
|
async function joinSession() {
|
||||||
console.log('join ' + sessionId);
|
console.log('join ' + sessionId);
|
||||||
|
|
@ -35,14 +36,14 @@
|
||||||
}
|
}
|
||||||
async function postQuestion() {
|
async function postQuestion() {
|
||||||
questionShortId = 10000000 + Math.floor(Math.random() * 90000000);
|
questionShortId = 10000000 + Math.floor(Math.random() * 90000000);
|
||||||
const event = new NDKEvent($ndk, {
|
$event = new NDKEvent($ndk, {
|
||||||
kind: 1342,
|
kind: 30342,
|
||||||
content: $question,
|
content: $question,
|
||||||
tags: [['d', questionShortId + '']]
|
tags: [['d', questionShortId + '']]
|
||||||
});
|
});
|
||||||
await event.publish();
|
await $event.publishReplaceable();
|
||||||
console.log("event id", event.id)
|
console.log("event id", $event.id)
|
||||||
$questionId = event.id;
|
$questionId = `${$event.kind}:${$event.pubkey}:${$event.dTag}`;
|
||||||
$qrCodeUrl = await QRCode.toDataURL(`${window.location.origin}/q/${$questionId}`, {
|
$qrCodeUrl = await QRCode.toDataURL(`${window.location.origin}/q/${$questionId}`, {
|
||||||
width: 800,
|
width: 800,
|
||||||
});
|
});
|
||||||
|
|
@ -59,7 +60,6 @@
|
||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if ($ndkReady) {
|
if ($ndkReady) {
|
||||||
if ($ndk.activeUser) {
|
if ($ndk.activeUser) {
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,9 @@
|
||||||
|
|
||||||
let comment = writable('');
|
let comment = writable('');
|
||||||
let comments = writable([]);
|
let comments = writable([]);
|
||||||
|
let question = writable()
|
||||||
|
const [kind, pubkey, d] = data.id.split(":")
|
||||||
|
const showReactions = writable(false);
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if ($ndkReady) {
|
if ($ndkReady) {
|
||||||
|
|
@ -38,17 +41,39 @@
|
||||||
$comments = [...$comments, event];
|
$comments = [...$comments, event];
|
||||||
console.log(`${event.content}`);
|
console.log(`${event.content}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const questionSub = $ndk.subscribe({ kinds: [Number(kind)], authors: [pubkey], "#d": [d] });
|
||||||
|
questionSub.on('event', (event) => {
|
||||||
|
$question = event;
|
||||||
|
if ($question?.tags.find(t => t[0] === "reactions")[1] === "true") {
|
||||||
|
console.log("reactions enabled")
|
||||||
|
$showReactions = "true"
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
async function startReactions(event) {
|
||||||
|
console.log("start reactions", event)
|
||||||
|
let updatedEvent = new NDKEvent($ndk, event )
|
||||||
|
console.log("updated event", updatedEvent)
|
||||||
|
updatedEvent.tags.push(['reactions', "true"])
|
||||||
|
await updatedEvent.publishReplaceable();
|
||||||
|
console.log("sent!", updatedEvent)
|
||||||
|
$showReactions = "true"
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
||||||
<div class="main-layout mx-auto flex w-3/4 flex-col items-center justify-center">
|
<div class="main-layout mx-auto flex w-3/4 flex-col items-center justify-center">
|
||||||
{#key $ndkReady}
|
{#if $question}
|
||||||
{#await $ndk.fetchEvent(data.id) then question}
|
<button class="btn" onclick={() => startReactions($question)}>Start Reaktionen</button>
|
||||||
{#if question}
|
|
||||||
<div class="question mb-4 w-full rounded border p-4 text-xl">
|
<div class="question mb-4 w-full rounded border p-4 text-xl">
|
||||||
<h2 class="text-xl font-bold">Frage / Thema:</h2>
|
<h2 class="text-xl font-bold">Frage / Thema:</h2>
|
||||||
<Markdown {carta} value={question.content} />
|
<Markdown {carta} value={$question.content} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="mb-2 flex w-full flex-col items-center justify-center gap-2">
|
<div class="mb-2 flex w-full flex-col items-center justify-center gap-2">
|
||||||
|
|
@ -59,15 +84,13 @@
|
||||||
{:else}
|
{:else}
|
||||||
<p>Loading...</p>
|
<p>Loading...</p>
|
||||||
{/if}
|
{/if}
|
||||||
{:catch error}
|
|
||||||
<p>Error fetching question: {error.message}</p>
|
|
||||||
{/await}
|
|
||||||
{/key}
|
|
||||||
|
|
||||||
<div class="mx-auto flex w-full flex-col items-center justify-center gap-5">
|
<div class="mx-auto flex w-full flex-col items-center justify-center gap-5">
|
||||||
|
{#key $showReactions}
|
||||||
{#each $comments.sort((a, b) => a.created_at - b.created_at).reverse() as event}
|
{#each $comments.sort((a, b) => a.created_at - b.created_at).reverse() as event}
|
||||||
<Comment {event} />
|
<Comment event={event} showReactions={$showReactions} />
|
||||||
{/each}
|
{/each}
|
||||||
|
{/key}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue