chore: cleanup

This commit is contained in:
2023-11-01 00:40:12 +09:00
parent 8f90daa840
commit c65bb7a992
56 changed files with 344 additions and 221 deletions

View File

@ -0,0 +1,39 @@
import { useEffect, useState } from "react";
import { NostrEvent, NostrLink, TaggedNostrEvent } from "@snort/system";
import PageSpinner from "Element/PageSpinner";
import Note from "Element/Event/Note";
import NostrBandApi from "External/NostrBand";
import { useReactions } from "Feed/Reactions";
import { ErrorOrOffline } from "Element/ErrorOrOffline";
export default function TrendingNotes() {
const [posts, setPosts] = useState<Array<NostrEvent>>();
const [error, setError] = useState<Error>();
const related = useReactions("trending", posts?.map(a => NostrLink.fromEvent(a)) ?? []);
async function loadTrendingNotes() {
const api = new NostrBandApi();
const trending = await api.trendingNotes();
setPosts(trending.notes.map(a => a.event));
}
useEffect(() => {
loadTrendingNotes().catch(e => {
if (e instanceof Error) {
setError(e);
}
});
}, []);
if (error) return <ErrorOrOffline error={error} onRetry={loadTrendingNotes} className="p" />;
if (!posts) return <PageSpinner />;
return (
<>
{posts.map(e => (
<Note key={e.id} data={e as TaggedNostrEvent} related={related?.data ?? []} depth={0} />
))}
</>
);
}