feat: add NIP-88 poll support

This commit is contained in:
Bhavishy
2026-04-03 01:09:00 +05:30
parent d1b868e7ba
commit 7a44bd1677
6 changed files with 30 additions and 12 deletions
+3 -1
View File
@@ -35,7 +35,9 @@
{/if}
</p>
</div>
<p class="whitespace-nowrap text-xs opacity-50">{$results.voters} voter{$results.voters === 1 ? "" : "s"}</p>
<p class="whitespace-nowrap text-xs opacity-50">
{$results.voters} voter{$results.voters === 1 ? "" : "s"}
</p>
</div>
<div class="flex flex-col gap-2">
+9 -2
View File
@@ -118,7 +118,11 @@
{#each options as option, index (index)}
<div class="flex items-center gap-2">
<label class="input input-bordered flex w-full items-center gap-2">
<input bind:value={options[index]} class="grow" type="text" placeholder={`Option ${index + 1}`} />
<input
bind:value={options[index]}
class="grow"
type="text"
placeholder={`Option ${index + 1}`} />
</label>
<Button class="btn btn-ghost btn-sm" onclick={() => removeOption(index)}>
<Icon icon={MinusCircle} size={4} />
@@ -150,7 +154,10 @@
Ends at
{/snippet}
{#snippet input()}
<input bind:value={endsAt} class="input input-bordered w-full max-w-xs" type="datetime-local" />
<input
bind:value={endsAt}
class="input input-bordered w-full max-w-xs"
type="datetime-local" />
{/snippet}
</FieldInline>
</div>
+3 -1
View File
@@ -18,7 +18,9 @@
const h = getTagValue("h", event.tags)
</script>
<Link class="cv col-2 card2 bg-alt w-full cursor-pointer shadow-md" href={makePollPath(url, event.id)}>
<Link
class="cv col-2 card2 bg-alt w-full cursor-pointer shadow-md"
href={makePollPath(url, event.id)}>
<NoteContent {event} {url} />
<div class="flex w-full flex-col items-end justify-between gap-2 sm:flex-row">
<span class="whitespace-nowrap py-1 text-sm opacity-75">
+9 -6
View File
@@ -33,10 +33,11 @@
const endsAt = getPollEndsAt(event)
const results = $derived.by(() => getPollResults(event, $responses))
const ownResponse = $derived.by(() =>
$responses
.filter(response => response.pubkey === $pubkey)
.sort((left, right) => right.created_at - left.created_at)[0],
const ownResponse = $derived.by(
() =>
$responses
.filter(response => response.pubkey === $pubkey)
.sort((left, right) => right.created_at - left.created_at)[0],
)
const submit = async () => {
@@ -111,9 +112,11 @@
{/if}
<span class="truncate">{option.label}</span>
</label>
<span class="whitespace-nowrap text-xs opacity-75">{current?.votes || 0} vote{(current?.votes || 0) === 1 ? "" : "s"}</span>
<span class="whitespace-nowrap text-xs opacity-75"
>{current?.votes || 0} vote{(current?.votes || 0) === 1 ? "" : "s"}</span>
</div>
<progress class="progress progress-primary" value={current?.votes || 0} max={maxVotes}></progress>
<progress class="progress progress-primary" value={current?.votes || 0} max={maxVotes}
></progress>
</div>
{/each}
</div>