import { useEffect, useState } from "react"; import { NostrEvent, NostrLink, TaggedNostrEvent } from "@snort/system"; import { useReactions } from "@snort/system-react"; import PageSpinner from "Element/PageSpinner"; import Note from "Element/Event/Note"; import NostrBandApi from "External/NostrBand"; import { ErrorOrOffline } from "Element/ErrorOrOffline"; import { useLocale } from "IntlProvider"; import useModeration from "Hooks/useModeration"; export default function TrendingNotes() { const [posts, setPosts] = useState>(); const [error, setError] = useState(); const { lang } = useLocale(); const { isEventMuted } = useModeration(); const related = useReactions("trending", posts?.map(a => NostrLink.fromEvent(a)) ?? [], undefined, true); async function loadTrendingNotes() { const api = new NostrBandApi(); const trending = await api.trendingNotes(lang); setPosts(trending.notes.map(a => a.event)); } useEffect(() => { loadTrendingNotes().catch(e => { if (e instanceof Error) { setError(e); } }); }, []); if (error) return ; if (!posts) return ; return ( <> {posts .filter(a => !isEventMuted(a)) .map(e => ( ))} ); }