diff --git a/package.json b/package.json index 4292745d..4aeaa94d 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "zap.cooking", "license": "MIT", - "version": "4.2.121", + "version": "4.2.123", "private": true, "scripts": { "dev": "vite dev", diff --git a/src/components/PollDisplay.svelte b/src/components/PollDisplay.svelte index 6d788df3..e0681617 100644 --- a/src/components/PollDisplay.svelte +++ b/src/components/PollDisplay.svelte @@ -5,6 +5,7 @@ import { addClientTagToEvent } from '$lib/nip89'; import { publishQueue } from '$lib/publishQueue'; import NoteContent from './NoteContent.svelte'; + import { formatDistanceToNow } from 'date-fns'; import { parsePollFromEvent, isPollExpired, @@ -41,6 +42,11 @@ $: maxVoteCount = pollData ? Math.max(...pollData.options.map((o) => results.counts.get(o.id) || 0), 0) : 0; + $: endDateText = pollData?.endsAt + ? expired + ? `Ended ${formatDistanceToNow(new Date(pollData.endsAt * 1000), { addSuffix: true })}` + : `Ends ${formatDistanceToNow(new Date(pollData.endsAt * 1000), { addSuffix: true })}` + : ''; onMount(() => { pollData = parsePollFromEvent(event); @@ -101,559 +107,521 @@ } -
- {#if pollData} - - {#if pollData.question} -
- -
- {/if} - - -
- - {pollData.pollType === 'multiplechoice' ? 'Multiple choice' : 'Single choice'} - - {#if pollData.endsAt} - - {#if expired} - Ended - {:else} - Ends {new Date(pollData.endsAt * 1000).toLocaleDateString()} - {/if} - - {/if} +{#if pollData} + + {#if pollData.question} +
+
+ {/if} - - {#if hasImages} - -
- {#each pollData.options as option, i (option.id)} - {@const voteCount = results.counts.get(option.id) || 0} - {@const pct = results.totalVoters === 0 ? 0 : Math.round((voteCount / results.totalVoters) * 100)} - {@const isUserChoice = userSelectedOptions.includes(option.id)} - {@const isSelected = selectedOptions.has(option.id)} - {@const isWinner = displayResults && voteCount > 0 && voteCount === maxVoteCount} - {@const isLast = i === pollData.options.length - 1 && pollData.options.length % 2 !== 0} - - {#if displayResults} - -
-
- {#if option.image} - {option.label - {:else} -
+ + {#if hasImages} +
+ {#each pollData.options as option, i (option.id)} + {@const voteCount = results.counts.get(option.id) || 0} + {@const pct = results.totalVoters === 0 ? 0 : Math.round((voteCount / results.totalVoters) * 100)} + {@const isUserChoice = userSelectedOptions.includes(option.id)} + {@const isSelected = selectedOptions.has(option.id)} + {@const isWinner = displayResults && voteCount > 0 && voteCount === maxVoteCount} + + {#if displayResults} +
+
+ {#if option.image} + {option.label + {:else} +
+ {/if} +
+ {pct}% + {#if option.label} + {option.label} {/if} - - - {#if pollData.pollType === 'singlechoice'} - - {:else} - - {/if} - - -
-
- {pct}% ({voteCount}) +
+
- {#if option.label} -
{option.label}
+ {#if isUserChoice} + + + + + {/if}
- {:else} - - - {/if} - {/each} -
- {:else} - -
- {#each pollData.options as option, i (option.id)} - {@const voteCount = results.counts.get(option.id) || 0} - {@const pct = results.totalVoters === 0 ? 0 : Math.round((voteCount / results.totalVoters) * 100)} - {@const isUserChoice = userSelectedOptions.includes(option.id)} - {@const isSelected = selectedOptions.has(option.id)} - {@const isLast = i === pollData.options.length - 1 && pollData.options.length % 2 !== 0} - - {#if displayResults} -
-
-
- - {option.label} - {#if isUserChoice} - - {/if} + {#if isSelected} + + + + - {pct}% -
-
{voteCount}
+ {/if}
- {:else} - - {/if} - {/each} -
- {/if} - - - {#if voteError} -

{voteError}

- {/if} - - -
- - {results.totalVoters} vote{results.totalVoters !== 1 ? 's' : ''} - + + {/if} + {/each} +
- {#if !displayResults && !expired} -
+ + {:else} +
+ {#each pollData.options as option, i (option.id)} + {@const voteCount = results.counts.get(option.id) || 0} + {@const pct = results.totalVoters === 0 ? 0 : Math.round((voteCount / results.totalVoters) * 100)} + {@const isUserChoice = userSelectedOptions.includes(option.id)} + {@const isSelected = selectedOptions.has(option.id)} + + {#if displayResults} +
+
+ + {option.label} + {#if isUserChoice} + + + + {/if} + + {pct}% +
+ {:else} - {#if $userPublickey && selectedOptions.size > 0} - - {/if} -
- {:else if displayResults && !userVoted && !expired && !voted} - - {/if} + {/if} + {/each}
{/if} -
-