Skip to content

Commit

Permalink
Merge pull request #143 from SpaceTurtle-Dao/feature/Reply-Count
Browse files Browse the repository at this point in the history
Feature/reply count
  • Loading branch information
coolestnick authored Nov 3, 2024
2 parents 2faaf61 + 9470702 commit 28f33ad
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion src/lib/components/posts/Post.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
export let event: any;
export let replies: any[] = [];
export let showFullPost: boolean = false;
let replyCount = 0;
let _user: any;
let profile: any;
Expand Down Expand Up @@ -95,6 +96,7 @@
}
}
}
await countReplies();
isLoading = false;
} catch (error) {
console.error('Error loading event data:', error);
Expand All @@ -114,6 +116,7 @@
function handleNewReply(replyEvent: any) {
replies = [...replies, replyEvent.detail];
replyCount += 1;
dispatch('newReply', replyEvent.detail);
}
Expand All @@ -123,6 +126,28 @@
dialogOpen = true;
}
}
async function countReplies() {
if (!event?.Id) return;
try {
let replyFilter = JSON.stringify([
{
kinds: ["1"],
tags: { marker: ["reply"] },
},
{
tags: { e: [event.Id] },
}
]);
const replies = await fetchEvents($currentUser.Process, replyFilter);
replyCount = replies.length;
} catch (error) {
console.error("Error counting replies:", error);
}
}
</script>

<div class="cursor-pointer border-b border-gray-800">
Expand Down Expand Up @@ -231,7 +256,14 @@
</a>

<div class="flex justify-between mt-3 engagement-buttons">
<Reply {event} user={_user} on:newReply={handleNewReply}/>
<div class="flex items-center">
<Reply {event} user={_user} on:newReply={handleNewReply}/>
{#if replyCount > 0}
<span class="ml-1 text-sm text-muted-foreground">
{replyCount}
</span>
{/if}
</div>
<Repost _event={isRepost ? originalEvent : event}/>
<Like _event={isRepost ? originalEvent : event}/>
<Buy />
Expand Down

0 comments on commit 28f33ad

Please sign in to comment.