fix: cleanup
This commit is contained in:
parent
5e42c5e70c
commit
f34ccf72cb
@ -2,6 +2,7 @@ import "./LongFormText.css";
|
||||
import { CSSProperties, useCallback, useRef, useState } from "react";
|
||||
import { FormattedMessage, FormattedNumber } from "react-intl";
|
||||
import { TaggedNostrEvent } from "@snort/system";
|
||||
import { useEventReactions } from "@snort/system-react";
|
||||
|
||||
import { findTag } from "SnortUtils";
|
||||
import Text from "Element/Text";
|
||||
@ -9,7 +10,6 @@ import { Markdown } from "./Markdown";
|
||||
import useImgProxy from "Hooks/useImgProxy";
|
||||
import ProfilePreview from "Element/User/ProfilePreview";
|
||||
import NoteFooter from "./NoteFooter";
|
||||
import { useEventReactions } from "Hooks/useEventReactions";
|
||||
import NoteTime from "./NoteTime";
|
||||
|
||||
interface LongFormTextProps {
|
||||
|
@ -2,13 +2,14 @@ import React, { useEffect, useState } from "react";
|
||||
import { FormattedMessage, useIntl } from "react-intl";
|
||||
import { useLongPress } from "use-long-press";
|
||||
import { TaggedNostrEvent, ParsedZap, countLeadingZeros, NostrLink } from "@snort/system";
|
||||
import { normalizeReaction } from "@snort/shared";
|
||||
import { useUserProfile } from "@snort/system-react";
|
||||
import { Menu, MenuItem } from "@szhsin/react-menu";
|
||||
import classNames from "classnames";
|
||||
|
||||
import { formatShort } from "Number";
|
||||
import useEventPublisher from "Hooks/useEventPublisher";
|
||||
import { delay, findTag, normalizeReaction } from "SnortUtils";
|
||||
import { delay, findTag } from "SnortUtils";
|
||||
import { NoteCreator } from "Element/Event/NoteCreator";
|
||||
import SendSats from "Element/SendSats";
|
||||
import { ZapsSummary } from "Element/Event/Zap";
|
||||
|
@ -4,6 +4,7 @@ import { useInView } from "react-intersection-observer";
|
||||
import { FormattedMessage, useIntl } from "react-intl";
|
||||
import classNames from "classnames";
|
||||
import { EventExt, EventKind, HexKey, Lists, NostrLink, NostrPrefix, TaggedNostrEvent } from "@snort/system";
|
||||
import { useEventReactions } from "@snort/system-react";
|
||||
|
||||
import { findTag, hexToBech32, profileLink } from "SnortUtils";
|
||||
import useModeration from "Hooks/useModeration";
|
||||
@ -23,7 +24,6 @@ import NoteFooter from "./NoteFooter";
|
||||
import Reactions from "./Reactions";
|
||||
import HiddenNote from "./HiddenNote";
|
||||
import { NoteProps } from "./Note";
|
||||
import { useEventReactions } from "Hooks/useEventReactions";
|
||||
import { chainKey } from "Hooks/useThreadContext";
|
||||
|
||||
export function NoteInner(props: NoteProps) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@snort/system-react",
|
||||
"version": "1.0.17",
|
||||
"version": "1.0.18",
|
||||
"description": "React hooks for @snort/system",
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
|
@ -4,4 +4,4 @@ export * from "./useRequestBuilder";
|
||||
export * from "./useSystemState";
|
||||
export * from "./useUserProfile";
|
||||
export * from "./useUserSearch";
|
||||
export * from "./useEventReactions";
|
||||
export * from "./useEventReactions";
|
||||
|
@ -6,33 +6,39 @@ import { SnortContext } from "./context";
|
||||
|
||||
/**
|
||||
* Parse reactions to a given event from a set of related events
|
||||
* @param ev
|
||||
* @param related
|
||||
* @returns
|
||||
* @param ev
|
||||
* @param related
|
||||
* @returns
|
||||
*/
|
||||
export function useEventReactions(ev: TaggedNostrEvent, related: ReadonlyArray<TaggedNostrEvent>) {
|
||||
const system = useContext(SnortContext);
|
||||
|
||||
return useMemo(() => {
|
||||
const link = NostrLink.fromEvent(ev);
|
||||
const reactionKinds = related.reduce((acc, v) => {
|
||||
if (link.isReplyToThis(v)) {
|
||||
acc[v.kind.toString()] ??= [];
|
||||
acc[v.kind.toString()].push(v);
|
||||
}
|
||||
return acc;
|
||||
}, {} as Record<string, Array<TaggedNostrEvent>>);
|
||||
const reactionKinds = related.reduce(
|
||||
(acc, v) => {
|
||||
if (link.isReplyToThis(v)) {
|
||||
acc[v.kind.toString()] ??= [];
|
||||
acc[v.kind.toString()].push(v);
|
||||
}
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, Array<TaggedNostrEvent>>,
|
||||
);
|
||||
|
||||
const deletions = reactionKinds[EventKind.Deletion.toString()] ?? [];
|
||||
const reactions = reactionKinds[EventKind.Reaction.toString()] ?? [];
|
||||
const reposts = reactionKinds[EventKind.Repost.toString()] ?? [];
|
||||
|
||||
const groupReactions = reactions?.reduce((acc, reaction) => {
|
||||
const kind = normalizeReaction(reaction.content);
|
||||
acc[kind] ??= [];
|
||||
acc[kind].push(reaction);
|
||||
return acc;
|
||||
}, {} as Record<Reaction, Array<TaggedNostrEvent>>);
|
||||
const groupReactions = reactions?.reduce(
|
||||
(acc, reaction) => {
|
||||
const kind = normalizeReaction(reaction.content);
|
||||
acc[kind] ??= [];
|
||||
acc[kind].push(reaction);
|
||||
return acc;
|
||||
},
|
||||
{} as Record<Reaction, Array<TaggedNostrEvent>>,
|
||||
);
|
||||
|
||||
const zaps = (reactionKinds[EventKind.ZapReceipt] ?? [])
|
||||
.map(a => parseZap(a, system.ProfileLoader.Cache, ev))
|
||||
@ -42,14 +48,17 @@ export function useEventReactions(ev: TaggedNostrEvent, related: ReadonlyArray<T
|
||||
return {
|
||||
deletions,
|
||||
reactions: {
|
||||
positive: groupReactions[Reaction.Positive],
|
||||
negative: groupReactions[Reaction.Negative],
|
||||
positive: groupReactions[Reaction.Positive] ?? [],
|
||||
negative: groupReactions[Reaction.Negative] ?? [],
|
||||
},
|
||||
reposts,
|
||||
zaps,
|
||||
others: Object.fromEntries(
|
||||
Object.entries(reactionKinds)
|
||||
.filter(([k]) => ![EventKind.Deletion, EventKind.Reaction, EventKind.Repost, EventKind.ZapReceipt].includes(Number(k))))
|
||||
Object.entries(reactionKinds).filter(
|
||||
([k]) =>
|
||||
![EventKind.Deletion, EventKind.Reaction, EventKind.Repost, EventKind.ZapReceipt].includes(Number(k)),
|
||||
),
|
||||
),
|
||||
};
|
||||
}, [ev, related]);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user