From a84ec12a27f1085d7c863780d695142bdfb908a8 Mon Sep 17 00:00:00 2001 From: gsovereignty Date: Mon, 15 Jul 2024 13:11:30 +0800 Subject: [PATCH] problem: not clear when there are no votes --- src/components/MeritSummaryCard.svelte | 57 +++++++++++++++----------- src/lib/event_helpers/merits.ts | 3 ++ 2 files changed, 36 insertions(+), 24 deletions(-) diff --git a/src/components/MeritSummaryCard.svelte b/src/components/MeritSummaryCard.svelte index 427315f..c930555 100644 --- a/src/components/MeritSummaryCard.svelte +++ b/src/components/MeritSummaryCard.svelte @@ -4,7 +4,7 @@ import { ndk } from '@/ndk'; import type { NDKEvent, NDKKind } from '@nostr-dev-kit/ndk'; import { Avatar, Name } from '@nostr-dev-kit/ndk-svelte-components'; - import { ExternalLink } from 'lucide-svelte'; + import { ExternalLink, Info } from 'lucide-svelte'; import { onDestroy } from 'svelte'; import VoteOnMeritRequest from './VoteOnMeritRequest.svelte'; @@ -16,42 +16,47 @@ import { unixToRelativeTime } from '@/helpers'; import { derived } from 'svelte/store'; - import { Button } from "$lib/components/ui/button/index.js"; - import { Label } from "$lib/components/ui/label/index.js"; - import { Textarea } from "$lib/components/ui/textarea/index.js"; - import CornerDownLeft from "lucide-svelte/icons/corner-down-left"; + import { Button } from '$lib/components/ui/button/index.js'; + import { Label } from '$lib/components/ui/label/index.js'; + import { Textarea } from '$lib/components/ui/textarea/index.js'; + import CornerDownLeft from 'lucide-svelte/icons/corner-down-left'; + import Alert from '@/components/ui/alert/alert.svelte'; export let merit: MeritRequest; export let rocket: NDKEvent; let _votes = $ndk.storeSubscribe( - { '#a': [RocketATagFilter(rocket)], kinds: [1410 as NDKKind] }, + { '#a': [RocketATagFilter(rocket)], '#e': [merit.ID], kinds: [1410 as NDKKind] }, { - subId: merit.RocketTag!.split(':')[2] + '_votes' + subId: merit.ID } ); + onDestroy(() => { + _votes.unsubscribe(); + }); + let votes = derived(_votes, ($_votes) => { let vMap = new Map(); for (let v of $_votes) { let vote = new Vote(v); - if (vote.BasicValidation() && vote.ValidateAgainstRocket(new Rocket(rocket))) { + if ( + vote.BasicValidation() && + vote.ValidateAgainstRocket(new Rocket(rocket)) && + vote.ValidateAgainstMeritRequest(merit) + ) { vMap.set(vote.ID, vote); //only show the latest vote from each pubkey } } - let pMap = new Map() + let pMap = new Map(); for (let [_, v] of vMap) { - let existing = pMap.get(v.Pubkey) - if (!existing || existing && existing.TimeStamp < v.TimeStamp) { - pMap.set(v.Pubkey, v) + let existing = pMap.get(v.Pubkey); + if (!existing || (existing && existing.TimeStamp < v.TimeStamp)) { + pMap.set(v.Pubkey, v); } } return pMap; }); - - onDestroy(() => { - _votes.unsubscribe(); - }); @@ -68,7 +73,7 @@ pubkey={merit.Pubkey} class="h-10 w-10 flex-none rounded-full object-cover" /> - + {#if merit.Problem().length > 20}{merit.Problem()}{/if} @@ -111,6 +116,7 @@
Votes
+ {#if $votes.size == 0}Waiting for existing {new Rocket(rocket).Name()} Merit holders to vote {/if} {#each $votes as [id, vote], _ (id)} @@ -119,7 +125,11 @@ console.log(vote.Event.rawEvent()); goto(`${base}/rockets/merits/${vote.ID}`); }} - class="cursor-pointer {vote.VoteDirection == "ratify"?"bg-lime-600":"bg-red-700"} {vote.VoteDirection == "ratify"?"hover:bg-lime-700":"hover:bg-red-800"}" + class="cursor-pointer {vote.VoteDirection == 'ratify' + ? 'bg-lime-600' + : 'bg-red-700'} {vote.VoteDirection == 'ratify' + ? 'hover:bg-lime-700' + : 'hover:bg-red-800'}" >
@@ -131,12 +141,12 @@
- {unixToRelativeTime(vote.TimeStamp * 1000)} @@ -151,10 +161,11 @@
- Discussion -
+