feat: nreq
This commit is contained in:
32
packages/app/src/Element/Feed/Generic.tsx
Normal file
32
packages/app/src/Element/Feed/Generic.tsx
Normal file
@ -0,0 +1,32 @@
|
||||
import { NostrLink, NoteCollection, ReqFilter, RequestBuilder } from "@snort/system";
|
||||
import { useReactions, useRequestBuilder } from "@snort/system-react";
|
||||
import { useMemo } from "react";
|
||||
import { TimelineRenderer } from "./TimelineFragment";
|
||||
|
||||
export function GenericFeed({ link }: { link: NostrLink }) {
|
||||
const sub = useMemo(() => {
|
||||
console.debug(link);
|
||||
const sub = new RequestBuilder("generic");
|
||||
sub.withOptions({ leaveOpen: true });
|
||||
const reqs = JSON.parse(link.id) as Array<ReqFilter>;
|
||||
reqs.forEach(a => {
|
||||
const f = sub.withBareFilter(a);
|
||||
link.relays?.forEach(r => f.relay(r));
|
||||
});
|
||||
return sub;
|
||||
}, [link]);
|
||||
|
||||
const evs = useRequestBuilder(NoteCollection, sub);
|
||||
const reactions = useReactions("generic:reactions", evs.data?.map(a => NostrLink.fromEvent(a)) ?? []);
|
||||
|
||||
return (
|
||||
<TimelineRenderer
|
||||
frags={[{ events: evs.data ?? [], refTime: 0 }]}
|
||||
related={reactions.data ?? []}
|
||||
latest={[]}
|
||||
showLatest={() => {
|
||||
//nothing
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
@ -7,6 +7,7 @@ import { fetchNip05Pubkey } from "@snort/shared";
|
||||
import Spinner from "Icons/Spinner";
|
||||
import ProfilePage from "Pages/Profile/ProfilePage";
|
||||
import { ThreadRoute } from "Element/Event/Thread";
|
||||
import { GenericFeed } from "Element/Feed/Generic";
|
||||
|
||||
export default function NostrLinkHandler() {
|
||||
const params = useParams();
|
||||
@ -24,6 +25,8 @@ export default function NostrLinkHandler() {
|
||||
} else if (nav.type === NostrPrefix.PublicKey || nav.type === NostrPrefix.Profile) {
|
||||
const id = nav.encode();
|
||||
setRenderComponent(<ProfilePage key={id} id={id} state={state} />); // Directly render ProfilePage
|
||||
} else if (nav.type === NostrPrefix.Req) {
|
||||
setRenderComponent(<GenericFeed link={nav} />);
|
||||
}
|
||||
} else {
|
||||
if (state) {
|
||||
|
@ -18,6 +18,7 @@ import {
|
||||
NostrEvent,
|
||||
mapEventToProfile,
|
||||
PowWorker,
|
||||
encodeTLVEntries,
|
||||
} from "@snort/system";
|
||||
import { SnortContext } from "@snort/system-react";
|
||||
import { removeUndefined, throwIfOffline } from "@snort/shared";
|
||||
@ -286,3 +287,7 @@ root.render(
|
||||
</IntlProvider>
|
||||
</StrictMode>,
|
||||
);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
window.encodeTLV = encodeTLVEntries;
|
||||
|
Reference in New Issue
Block a user