diff --git a/src/helpers/thread.ts b/src/helpers/thread.ts
index 5a29175e7..311dfa4bc 100644
--- a/src/helpers/thread.ts
+++ b/src/helpers/thread.ts
@@ -1,12 +1,16 @@
import { NostrEvent } from "../types/nostr-event";
import { EventReferences, getReferences } from "./nostr-event";
+export function countReplies(thread: ThreadItem): number {
+ return thread.replies.reduce((c, item) => c + countReplies(item), 0) + thread.replies.length;
+}
+
export type ThreadItem = {
event: NostrEvent;
root?: ThreadItem;
reply?: ThreadItem;
refs: EventReferences;
- children: ThreadItem[];
+ replies: ThreadItem[];
};
export function linkEvents(events: NostrEvent[]) {
@@ -24,7 +28,7 @@ export function linkEvents(events: NostrEvent[]) {
replies.set(event.id, {
event,
refs,
- children: [],
+ replies: [],
});
}
@@ -33,7 +37,7 @@ export function linkEvents(events: NostrEvent[]) {
reply.reply = reply.refs.replyId ? replies.get(reply.refs.replyId) : undefined;
- reply.children = idToChildren[id]?.map((e) => replies.get(e.id) as ThreadItem) ?? [];
+ reply.replies = idToChildren[id]?.map((e) => replies.get(e.id) as ThreadItem) ?? [];
}
return replies;
diff --git a/src/views/home/index.tsx b/src/views/home/index.tsx
index db9ee62ac..0045e8287 100644
--- a/src/views/home/index.tsx
+++ b/src/views/home/index.tsx
@@ -25,7 +25,7 @@ export const HomeView = () => {
>
{tabs.map(({ label }) => (
- {label}
+ {label}
))}
diff --git a/src/views/note/thread-post.tsx b/src/views/note/thread-post.tsx
index 400b4e215..c9581a763 100644
--- a/src/views/note/thread-post.tsx
+++ b/src/views/note/thread-post.tsx
@@ -1,7 +1,7 @@
import { Button, Flex, useDisclosure } from "@chakra-ui/react";
import { useState } from "react";
import { Note } from "../../components/note";
-import { ThreadItem as ThreadItemData } from "../../helpers/thread";
+import { countReplies, ThreadItem as ThreadItemData } from "../../helpers/thread";
export type ThreadItemProps = {
post: ThreadItemData;
@@ -12,17 +12,19 @@ export const ThreadPost = ({ post, initShowReplies }: ThreadItemProps) => {
const [showReplies, setShowReplies] = useState(!!initShowReplies);
const toggle = () => setShowReplies((v) => !v);
+ const numberOfReplies = countReplies(post);
+
return (
- {post.children.length > 0 && (
+ {post.replies.length > 0 && (
<>
{showReplies && (
- {post.children.map((child) => (
+ {post.replies.map((child) => (
))}
diff --git a/src/views/user/index.tsx b/src/views/user/index.tsx
index 2688b358b..f520dc16f 100644
--- a/src/views/user/index.tsx
+++ b/src/views/user/index.tsx
@@ -21,7 +21,6 @@ const UserView = () => {
const matches = useMatches();
const lastMatch = matches[matches.length - 1];
- console.log(lastMatch);
const activeTab = tabs.indexOf(tabs.find((t) => lastMatch.pathname.includes(t.path)) ?? tabs[0]);
@@ -55,7 +54,7 @@ const UserView = () => {
>
{tabs.map(({ label }) => (
- {label}
+ {label}
))}