- {sortedEvents.map((event) => (
- event.kind === 1 ?
+
+ {sortedEvents.map((event) =>
e.pubkey === event.pubkey && e.kind === 0) || null}
replies={sortedEvents.filter((e) => e.tags.some((tag) => tag[0] === "e" && tag[1] === event.id))}
/>
- :
-
- ))}
+
+ )}
);
diff --git a/client/src/components/routes/Home.tsx b/client/src/components/routes/Home.tsx
index 94048b7..cc2b57f 100644
--- a/client/src/components/routes/Home.tsx
+++ b/client/src/components/routes/Home.tsx
@@ -1,7 +1,6 @@
import { verifyPow } from "../../utils/mine";
import { Event } from "nostr-tools";
import NewNoteCard from "../forms/PostFormCard";
-import RepostCard from "../modals/RepostCard";
import { DEFAULT_DIFFICULTY } from "../../config";
import PostCard from "../modals/PostCard";
import { useFetchEvents } from "../../hooks/useFetchEvents";
@@ -14,10 +13,29 @@ const Home = () => {
.filter((event) =>
verifyPow(event) >= Number(filterDifficulty) &&
event.kind !== 0 &&
- (event.kind !== 1 || !event.tags.some((tag) => tag[0] === "e" || tag[0] === "a"))
+ (event.kind !== 1 || !event.tags.some((tag) => tag[0] === "e" || tag[0] === "p"))
)
- const sortedEvents = postEvents.sort((a, b) => b.created_at - a.created_at);
+ const postEventsWithReplies = postEvents.map((event) => {
+ const totalWork = Math.pow(2, verifyPow(event))
+ + noteEvents.filter((e) => e.tags.some((tag) => tag[0] === "e" && tag[1] === event.id))
+ .reduce((acc, reply) => acc + Math.pow(2, verifyPow(reply)), 0);
+ return {
+ postEvent: event,
+ replies: noteEvents.filter((e) => e.tags.some((tag) => tag[0] === "e" && tag[1] === event.id)),
+ totalWork: totalWork, // Add total work here
+ };
+ });
+
+ const sortedEvents = postEventsWithReplies
+ .sort((a, b) => {
+ // Sort by total work in descending order
+ const workDiff = b.totalWork - a.totalWork;
+ if (workDiff !== 0) return workDiff;
+
+ // If total work is the same, sort by created_at in descending order
+ return b.postEvent.created_at - a.postEvent.created_at;
+ });
// Render the component
return (
@@ -25,17 +43,13 @@ const Home = () => {
-
+
{sortedEvents.map((event) => (
- event.kind === 1 ?
e.pubkey === event.pubkey && e.kind === 0) || null}
- replies={noteEvents.filter((e) => e.tags.some((tag) => tag[0] === "e" && tag[1] === event.id))}
- />
- :
- e.pubkey === event.postEvent.pubkey && e.kind === 0) || null}
+ replies={event.replies}
/>
))}
diff --git a/client/src/components/routes/Notifications.tsx b/client/src/components/routes/Notifications.tsx
index 6fbbafc..5bcb88a 100644
--- a/client/src/components/routes/Notifications.tsx
+++ b/client/src/components/routes/Notifications.tsx
@@ -1,7 +1,6 @@
import { useState, useCallback } from "react";
import PostCard from "../modals/PostCard";
import { Event } from "nostr-tools";
-import RepostCard from "../modals/RepostCard";
import { useFetchEvents } from "../../hooks/useFetchEvents";
const Notifications = () => {
@@ -65,31 +64,21 @@ const Notifications = () => {
Your Recent Posts
{sortedEvents.map((event) => (
- event.kind === 1 ?
e.pubkey === event.pubkey && e.kind === 0) || null}
replies={countReplies(event)}
/>
- :
-
))}
Mentions
{sortedMentions.map((event) => (
- event.kind === 1 ?
e.pubkey === event.pubkey && e.kind === 0) || null}
replies={countReplies(event)}
/>
- :
-
))}
diff --git a/client/src/components/routes/Thread.tsx b/client/src/components/routes/Thread.tsx
index 3bef26c..ec8471f 100644
--- a/client/src/components/routes/Thread.tsx
+++ b/client/src/components/routes/Thread.tsx
@@ -67,7 +67,7 @@ const Thread = () => {
.sort((a, b) => a.created_at - b.created_at).map((event, index) => (
e.pubkey === event.pubkey && e.kind === 0) || null} replies={countReplies(event)} />
))}
- e.pubkey === OPEvent.pubkey && e.kind === 0) || null} replies={countReplies(OPEvent)} type={'OP'}/>
+ e.pubkey === OPEvent.pubkey && e.kind === 0) || null} replies={replyEvents} type={'OP'}/>