2023-05-10 11:32:09 +00:00
|
|
|
import { useEffect, useState } from "react";
|
2023-09-19 08:30:01 +00:00
|
|
|
import { NostrEvent, NostrLink, TaggedNostrEvent } from "@snort/system";
|
2023-05-10 11:32:09 +00:00
|
|
|
|
|
|
|
import PageSpinner from "Element/PageSpinner";
|
|
|
|
import Note from "Element/Note";
|
2023-05-15 08:51:17 +00:00
|
|
|
import NostrBandApi from "External/NostrBand";
|
2023-09-21 20:02:59 +00:00
|
|
|
import { useReactions } from "Feed/Reactions";
|
2023-05-10 11:32:09 +00:00
|
|
|
|
|
|
|
export default function TrendingNotes() {
|
2023-06-01 21:03:28 +00:00
|
|
|
const [posts, setPosts] = useState<Array<NostrEvent>>();
|
2023-09-19 08:30:01 +00:00
|
|
|
const related = useReactions("trending", posts?.map(a => NostrLink.fromEvent(a)) ?? []);
|
2023-05-10 11:32:09 +00:00
|
|
|
|
|
|
|
async function loadTrendingNotes() {
|
|
|
|
const api = new NostrBandApi();
|
|
|
|
const trending = await api.trendingNotes();
|
|
|
|
setPosts(trending.notes.map(a => a.event));
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
loadTrendingNotes().catch(console.error);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (!posts) return <PageSpinner />;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{posts.map(e => (
|
2023-08-24 15:54:20 +00:00
|
|
|
<Note key={e.id} data={e as TaggedNostrEvent} related={related?.data ?? []} depth={0} />
|
2023-05-10 11:32:09 +00:00
|
|
|
))}
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|