refactor: simplify useEventReactions hook

This commit is contained in:
2023-11-14 12:55:46 +00:00
parent c794a9e393
commit 7174ed2502
8 changed files with 14 additions and 28 deletions

View File

@ -1,7 +1,7 @@
import "./LongFormText.css";
import { CSSProperties, useCallback, useRef, useState } from "react";
import { FormattedMessage, FormattedNumber } from "react-intl";
import { TaggedNostrEvent } from "@snort/system";
import { NostrLink, TaggedNostrEvent } from "@snort/system";
import { useEventReactions } from "@snort/system-react";
import { findTag } from "SnortUtils";
@ -26,7 +26,7 @@ export function LongFormText(props: LongFormTextProps) {
const { proxy } = useImgProxy();
const [reading, setReading] = useState(false);
const ref = useRef<HTMLDivElement>(null);
const { reactions, reposts, zaps } = useEventReactions(props.ev, props.related);
const { reactions, reposts, zaps } = useEventReactions(NostrLink.fromEvent(props.ev), props.related);
function previewText() {
return (

View File

@ -36,7 +36,7 @@ export function NoteInner(props: NoteProps) {
const { isEventMuted } = useModeration();
const { ref, inView } = useInView({ triggerOnce: true });
const { reactions, reposts, deletions, zaps } = useEventReactions(ev, related);
const { reactions, reposts, deletions, zaps } = useEventReactions(NostrLink.fromEvent(ev), related);
const login = useLogin();
const { pinned, bookmarked } = login;
const { publisher, system } = useEventPublisher();

View File

@ -1,7 +1,6 @@
import { useMemo } from "react";
import { EventKind, RequestBuilder, parseZap, NostrLink, NoteCollection } from "@snort/system";
import { useRequestBuilder } from "@snort/system-react";
import { UserCache } from "Cache";
export default function useZapsFeed(link?: NostrLink) {
const sub = useMemo(() => {
@ -15,7 +14,7 @@ export default function useZapsFeed(link?: NostrLink) {
const zaps = useMemo(() => {
if (zapsFeed.data) {
const profileZaps = zapsFeed.data.map(a => parseZap(a, UserCache)).filter(z => z.valid);
const profileZaps = zapsFeed.data.map(a => parseZap(a)).filter(z => z.valid);
profileZaps.sort((a, b) => b.amount - a.amount);
return profileZaps;
}

View File

@ -295,7 +295,7 @@ function NotificationGroup({ evs, onClick }: { evs: Array<TaggedNostrEvent>; onC
const navigate = useNavigate();
const zaps = useMemo(() => {
return evs.filter(a => a.kind === EventKind.ZapReceipt).map(a => parseZap(a, UserCache));
return evs.filter(a => a.kind === EventKind.ZapReceipt).map(a => parseZap(a));
}, [evs]);
const pubkeys = dedupe(
evs.map(a => {