refactor: upgrade snort libs
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { EventKind, NoteCollection, RequestBuilder, TaggedNostrEvent } from "@snort/system";
|
||||
import { EventKind, RequestBuilder, TaggedNostrEvent } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
|
||||
import { findTag, getTagValues, toAddress } from "@/utils";
|
||||
@ -19,7 +19,7 @@ export function useBadges(
|
||||
return rb;
|
||||
}, [pubkey, since]);
|
||||
|
||||
const { data: badgeEvents } = useRequestBuilder(NoteCollection, rb);
|
||||
const badgeEvents = useRequestBuilder(rb);
|
||||
|
||||
const rawBadges = useMemo(() => {
|
||||
if (badgeEvents) {
|
||||
@ -41,8 +41,8 @@ export function useBadges(
|
||||
return rb;
|
||||
}, [rawBadges]);
|
||||
|
||||
const acceptedStream = useRequestBuilder(NoteCollection, acceptedSub);
|
||||
const acceptedEvents = acceptedStream.data ?? [];
|
||||
const acceptedStream = useRequestBuilder(acceptedSub);
|
||||
const acceptedEvents = acceptedStream ?? [];
|
||||
|
||||
const badges = useMemo(() => {
|
||||
return rawBadges.map(e => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { NoteCollection, ReplaceableNoteStore, RequestBuilder, TaggedNostrEvent } from "@snort/system";
|
||||
import { RequestBuilder, TaggedNostrEvent } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
|
||||
import { CARD, USER_CARDS } from "@/const";
|
||||
@ -33,7 +33,7 @@ export function useUserCards(pubkey: string, userCards: Array<string[]>, leaveOp
|
||||
return rb;
|
||||
}, [pubkey, related]);
|
||||
|
||||
const { data } = useRequestBuilder(NoteCollection, subRelated);
|
||||
const data = useRequestBuilder(subRelated);
|
||||
|
||||
const cards = useMemo(() => {
|
||||
return related
|
||||
@ -62,12 +62,12 @@ export function useCards(pubkey?: string, leaveOpen = false): TaggedNostrEvent[]
|
||||
return b;
|
||||
}, [pubkey, leaveOpen]);
|
||||
|
||||
const { data: userCards } = useRequestBuilder(ReplaceableNoteStore, sub);
|
||||
const userCards = useRequestBuilder(sub);
|
||||
|
||||
const related = useMemo(() => {
|
||||
// filtering to only show CARD kinds for now, but in the future we could link and render anything
|
||||
if (userCards) {
|
||||
return userCards.tags.filter(t => t.at(0) === "a" && t.at(1)?.startsWith(`${CARD}:`));
|
||||
if (userCards.length > 0) {
|
||||
return userCards[0].tags.filter(t => t.at(0) === "a" && t.at(1)?.startsWith(`${CARD}:`));
|
||||
}
|
||||
return [];
|
||||
}, [userCards]);
|
||||
@ -90,7 +90,7 @@ export function useCards(pubkey?: string, leaveOpen = false): TaggedNostrEvent[]
|
||||
return rb;
|
||||
}, [pubkey, related]);
|
||||
|
||||
const { data } = useRequestBuilder(NoteCollection, subRelated);
|
||||
const data = useRequestBuilder(subRelated);
|
||||
const cardEvents = data ?? [];
|
||||
|
||||
const cards = useMemo(() => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { unwrap } from "@snort/shared";
|
||||
import { NostrEvent, NostrLink, NostrPrefix, NoteCollection, RequestBuilder, TaggedNostrEvent } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
import { NostrEvent, NostrLink, NostrPrefix, RequestBuilder, TaggedNostrEvent } from "@snort/system";
|
||||
import { useRequestBuilderAdvanced } from "@snort/system-react";
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { LIVE_STREAM } from "@/const";
|
||||
@ -27,16 +27,16 @@ export function useCurrentStreamFeed(link: NostrLink, leaveOpen = false, evPrelo
|
||||
return b;
|
||||
}, [link.id, leaveOpen]);
|
||||
|
||||
const q = useRequestBuilder(NoteCollection, sub);
|
||||
const q = useRequestBuilderAdvanced(sub);
|
||||
|
||||
if (evPreload) {
|
||||
q.add(evPreload as TaggedNostrEvent);
|
||||
q?.feed.add([evPreload as TaggedNostrEvent]);
|
||||
}
|
||||
|
||||
return useMemo(() => {
|
||||
const hosting = q.data?.filter(
|
||||
const hosting = q?.snapshot?.filter(
|
||||
a => a.pubkey === author || a.tags.some(b => b[0] === "p" && b[1] === author && b[3] === "host")
|
||||
);
|
||||
return [...(hosting ?? [])].sort((a, b) => (b.created_at > a.created_at ? 1 : -1)).at(0);
|
||||
}, [q.data]);
|
||||
}, [q]);
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { NostrEvent, NoteCollection, ReplaceableNoteStore, RequestBuilder } from "@snort/system";
|
||||
import { NostrEvent, RequestBuilder } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
import { findTag, uniqBy } from "@/utils";
|
||||
import { EMOJI_PACK, USER_EMOJIS } from "@/const";
|
||||
@ -55,7 +55,7 @@ export function useUserEmojiPacks(pubkey?: string, userEmoji?: Tags) {
|
||||
return rb;
|
||||
}, [pubkey, related]);
|
||||
|
||||
const { data: relatedData } = useRequestBuilder(NoteCollection, subRelated);
|
||||
const relatedData = useRequestBuilder(subRelated);
|
||||
|
||||
const emojiPacks = useMemo(() => {
|
||||
return relatedData ?? [];
|
||||
@ -79,8 +79,8 @@ export default function useEmoji(pubkey?: string) {
|
||||
return rb;
|
||||
}, [pubkey]);
|
||||
|
||||
const { data: userEmoji } = useRequestBuilder(ReplaceableNoteStore, sub);
|
||||
const userEmoji = useRequestBuilder(sub);
|
||||
|
||||
const emojis = useUserEmojiPacks(pubkey, userEmoji?.tags ?? []);
|
||||
const emojis = useUserEmojiPacks(pubkey, userEmoji?.at(0)?.tags ?? []);
|
||||
return emojis;
|
||||
}
|
||||
|
@ -1,32 +0,0 @@
|
||||
import { useMemo } from "react";
|
||||
import { NostrLink, NostrPrefix, ReplaceableNoteStore, RequestBuilder } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
|
||||
export default function useEventFeed(link: NostrLink, leaveOpen = false) {
|
||||
const sub = useMemo(() => {
|
||||
const b = new RequestBuilder(`event:${link.id.slice(0, 12)}`);
|
||||
b.withOptions({
|
||||
leaveOpen,
|
||||
});
|
||||
if (link.type === NostrPrefix.Address) {
|
||||
const f = b.withFilter().tag("d", [link.id]);
|
||||
if (link.author) {
|
||||
f.authors([link.author]);
|
||||
}
|
||||
if (link.kind) {
|
||||
f.kinds([link.kind]);
|
||||
}
|
||||
} else {
|
||||
const f = b.withFilter().ids([link.id]);
|
||||
if (link.relays) {
|
||||
link.relays.slice(0, 2).forEach(r => f.relay(r));
|
||||
}
|
||||
if (link.author) {
|
||||
f.authors([link.author]);
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}, [link, leaveOpen]);
|
||||
|
||||
return useRequestBuilder(ReplaceableNoteStore, sub);
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { type NostrLink, NostrPrefix, ReplaceableNoteStore, RequestBuilder } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
|
||||
export function useAddress(kind: number, pubkey: string, identifier: string) {
|
||||
const sub = useMemo(() => {
|
||||
const b = new RequestBuilder(`event:${kind}:${identifier}`);
|
||||
b.withFilter().kinds([kind]).authors([pubkey]).tag("d", [identifier]);
|
||||
return b;
|
||||
}, [kind, pubkey, identifier]);
|
||||
|
||||
const { data } = useRequestBuilder(ReplaceableNoteStore, sub);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
export function useEvent(link: NostrLink) {
|
||||
const sub = useMemo(() => {
|
||||
const b = new RequestBuilder(`event:${link.id.slice(0, 12)}`);
|
||||
if (link.type === NostrPrefix.Address) {
|
||||
const f = b.withFilter().tag("d", [link.id]);
|
||||
if (link.author) {
|
||||
f.authors([link.author]);
|
||||
}
|
||||
if (link.kind) {
|
||||
f.kinds([link.kind]);
|
||||
}
|
||||
} else {
|
||||
const f = b.withFilter().ids([link.id]);
|
||||
if (link.relays) {
|
||||
link.relays.slice(0, 2).forEach(r => f.relay(r));
|
||||
}
|
||||
if (link.author) {
|
||||
f.authors([link.author]);
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}, [link]);
|
||||
|
||||
const { data } = useRequestBuilder(ReplaceableNoteStore, sub);
|
||||
|
||||
return data;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
import { useMemo } from "react";
|
||||
import { FlatNoteStore, ReplaceableNoteStore, RequestBuilder } from "@snort/system";
|
||||
import { RequestBuilder } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
import { GOAL } from "@/const";
|
||||
|
||||
@ -11,9 +11,8 @@ export function useZapGoal(id?: string) {
|
||||
return b;
|
||||
}, [id]);
|
||||
|
||||
const { data } = useRequestBuilder(ReplaceableNoteStore, sub);
|
||||
|
||||
return data;
|
||||
const data = useRequestBuilder(sub);
|
||||
return data.at(0);
|
||||
}
|
||||
|
||||
export function useGoals(pubkey?: string, leaveOpen = false) {
|
||||
@ -25,7 +24,6 @@ export function useGoals(pubkey?: string, leaveOpen = false) {
|
||||
return b;
|
||||
}, [pubkey, leaveOpen]);
|
||||
|
||||
const { data } = useRequestBuilder(FlatNoteStore, sub);
|
||||
|
||||
const data = useRequestBuilder(sub);
|
||||
return data;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { ReplaceableNoteStore, RequestBuilder } from "@snort/system";
|
||||
import { RequestBuilder } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
|
||||
import { MUTED } from "@/const";
|
||||
@ -15,9 +15,9 @@ export function useMutedPubkeys(host?: string, leaveOpen = false) {
|
||||
return rb;
|
||||
}, [host]);
|
||||
|
||||
const { data: muted } = useRequestBuilder(ReplaceableNoteStore, mutedSub);
|
||||
const muted = useRequestBuilder(mutedSub);
|
||||
const mutedPubkeys = useMemo(() => {
|
||||
return new Set(getTagValues(muted?.tags ?? [], "p"));
|
||||
return new Set(getTagValues(muted?.at(0)?.tags ?? [], "p"));
|
||||
}, [muted]);
|
||||
|
||||
return mutedPubkeys;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { NostrLink, NoteCollection, RequestBuilder } from "@snort/system";
|
||||
import { NostrLink, RequestBuilder } from "@snort/system";
|
||||
import { useReactions, useRequestBuilder } from "@snort/system-react";
|
||||
import { unixNow } from "@snort/shared";
|
||||
import { useMemo } from "react";
|
||||
@ -17,13 +17,13 @@ export function useLiveChatFeed(link?: NostrLink, eZaps?: Array<string>, limit =
|
||||
return rb;
|
||||
}, [link?.id, since, eZaps]);
|
||||
|
||||
const feed = useRequestBuilder(NoteCollection, sub);
|
||||
const feed = useRequestBuilder(sub);
|
||||
|
||||
const messages = useMemo(() => {
|
||||
return (feed.data ?? []).filter(
|
||||
return (feed ?? []).filter(
|
||||
ev => ev.kind === LIVE_STREAM_CHAT || ev.kind === LIVE_STREAM_RAID || ev.kind === LIVE_STREAM_CLIP
|
||||
);
|
||||
}, [feed.data]);
|
||||
}, [feed]);
|
||||
|
||||
const reactions = useReactions(
|
||||
`live:${link?.id}:${link?.author}:reactions`,
|
||||
@ -31,5 +31,5 @@ export function useLiveChatFeed(link?: NostrLink, eZaps?: Array<string>, limit =
|
||||
undefined,
|
||||
true
|
||||
);
|
||||
return { messages, reactions: reactions.data ?? [] };
|
||||
return { messages, reactions: reactions ?? [] };
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { NostrEvent, NoteCollection, RequestBuilder } from "@snort/system";
|
||||
import { NostrEvent, RequestBuilder } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
|
||||
import { unixNow } from "@snort/shared";
|
||||
@ -53,17 +53,17 @@ export function useStreamsFeed(tag?: string) {
|
||||
return bStart > aStart ? 1 : -1;
|
||||
}
|
||||
|
||||
const feed = useRequestBuilder(NoteCollection, rb);
|
||||
const feed = useRequestBuilder(rb);
|
||||
const feedSorted = useMemo(() => {
|
||||
if (feed.data) {
|
||||
if (feed) {
|
||||
if (__XXX) {
|
||||
return [...feed.data].filter(
|
||||
return [...feed].filter(
|
||||
a =>
|
||||
findTag(a, "content-warning") !== undefined &&
|
||||
(!import.meta.env.VITE_SINGLE_PUBLISHER || import.meta.env.VITE_SINGLE_PUBLISHER === getHost(a))
|
||||
);
|
||||
} else {
|
||||
return [...feed.data].filter(
|
||||
return [...feed].filter(
|
||||
a =>
|
||||
findTag(a, "content-warning") === undefined &&
|
||||
(!import.meta.env.VITE_SINGLE_PUBLISHER || import.meta.env.VITE_SINGLE_PUBLISHER === getHost(a))
|
||||
@ -71,7 +71,7 @@ export function useStreamsFeed(tag?: string) {
|
||||
}
|
||||
}
|
||||
return [];
|
||||
}, [feed.data]);
|
||||
}, [feed]);
|
||||
|
||||
const live = feedSorted.filter(a => findTag(a, "status") === StreamState.Live).sort(sortStarts);
|
||||
const planned = feedSorted.filter(a => findTag(a, "status") === StreamState.Planned).sort(sortStarts);
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
||||
|
||||
import { EventKind, NoteCollection, RequestBuilder } from "@snort/system";
|
||||
import { EventKind, RequestBuilder } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
|
||||
import { useUserEmojiPacks } from "@/hooks/emoji";
|
||||
@ -42,7 +42,7 @@ export function useLoginEvents(pubkey?: string, leaveOpen = false) {
|
||||
return b;
|
||||
}, [pubkey, leaveOpen]);
|
||||
|
||||
const { data } = useRequestBuilder(NoteCollection, sub);
|
||||
const data = useRequestBuilder(sub);
|
||||
|
||||
useEffect(() => {
|
||||
if (!data) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { useMemo } from "react";
|
||||
import { NostrLink, NoteCollection, RequestBuilder } from "@snort/system";
|
||||
import { NostrLink, RequestBuilder } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
import { LIVE_STREAM } from "@/const";
|
||||
import { useZaps } from "./zaps";
|
||||
@ -19,11 +19,11 @@ export function useProfile(link: NostrLink, leaveOpen = false) {
|
||||
return b;
|
||||
}, [link, leaveOpen]);
|
||||
|
||||
const streams = useRequestBuilder(NoteCollection, sub);
|
||||
const streams = useRequestBuilder(sub);
|
||||
const zaps = useZaps(link);
|
||||
|
||||
const sortedStreams = useMemo(() => {
|
||||
const sorted = [...(streams.data ?? [])].sort((a, b) => b.created_at - a.created_at);
|
||||
const sorted = [...(streams ?? [])].sort((a, b) => b.created_at - a.created_at);
|
||||
return sorted;
|
||||
}, [streams]);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { bech32ToHex } from "@snort/shared";
|
||||
import { EventKind, ReplaceableNoteStore, RequestBuilder } from "@snort/system";
|
||||
import { EventKind, RequestBuilder } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
import { useMemo } from "react";
|
||||
|
||||
@ -20,11 +20,11 @@ export function useRates(symbol: string, leaveOpen = true) {
|
||||
return rb;
|
||||
}, [symbol]);
|
||||
|
||||
const data = useRequestBuilder(ReplaceableNoteStore, sub);
|
||||
const data = useRequestBuilder(sub);
|
||||
|
||||
const tag = data?.data?.tags.find(a => a[0] === "d" && a[1] === symbol);
|
||||
const tag = data?.at(0)?.tags.find(a => a[0] === "d" && a[1] === symbol);
|
||||
return {
|
||||
time: data.data?.created_at,
|
||||
time: data?.at(0)?.created_at,
|
||||
ask: Number(tag?.[2]),
|
||||
bid: Number(tag?.[3]),
|
||||
low: Number(tag?.[4]),
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { useMemo } from "react";
|
||||
|
||||
import { EventKind, ReplaceableNoteStore, RequestBuilder } from "@snort/system";
|
||||
import { EventKind, RequestBuilder } from "@snort/system";
|
||||
import { useRequestBuilder } from "@snort/system-react";
|
||||
|
||||
type StatusTag = "general" | "music";
|
||||
@ -17,6 +17,6 @@ export function useStatus(tag: StatusTag, author?: string, leaveOpen = true) {
|
||||
return b;
|
||||
}, [author]);
|
||||
|
||||
const { data } = useRequestBuilder(ReplaceableNoteStore, sub);
|
||||
return data;
|
||||
const data = useRequestBuilder(sub);
|
||||
return data.at(0);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ export function useZaps(link?: NostrLink, leaveOpen = false) {
|
||||
return null;
|
||||
}, [link, leaveOpen]);
|
||||
|
||||
const { data: zaps } = useRequestBuilder(NoteCollection, sub);
|
||||
const zaps = useRequestBuilder(sub);
|
||||
|
||||
return (
|
||||
[...(zaps ?? [])]
|
||||
|
Reference in New Issue
Block a user