snort/packages/app/src/Element/Event/Note.tsx

85 lines
2.6 KiB
TypeScript
Raw Normal View History

2022-12-18 14:51:47 +00:00
import "./Note.css";
2023-11-14 10:38:02 +00:00
import { ReactNode } from "react";
2023-10-13 10:22:58 +00:00
import { EventKind, NostrEvent, TaggedNostrEvent } from "@snort/system";
2023-11-17 11:52:10 +00:00
import { NostrFileElement } from "@/Element/Event/NostrFileHeader";
import ZapstrEmbed from "@/Element/Embed/ZapstrEmbed";
import PubkeyList from "@/Element/Embed/PubkeyList";
import { LiveEvent } from "@/Element/LiveEvent";
import { ZapGoal } from "@/Element/Event/ZapGoal";
import NoteReaction from "@/Element/Event/NoteReaction";
import ProfilePreview from "@/Element/User/ProfilePreview";
import { NoteInner } from "./NoteInner";
2023-10-11 10:44:53 +00:00
import { LongFormText } from "./LongFormText";
import ErrorBoundary from "@/Element/ErrorBoundary";
2023-02-08 21:10:26 +00:00
2023-01-16 17:48:25 +00:00
export interface NoteProps {
2023-08-17 18:54:14 +00:00
data: TaggedNostrEvent;
className?: string;
2023-08-17 18:54:14 +00:00
related: readonly TaggedNostrEvent[];
highlight?: boolean;
ignoreModeration?: boolean;
2023-08-17 18:54:14 +00:00
onClick?: (e: TaggedNostrEvent) => void;
2023-04-18 21:20:13 +00:00
depth?: number;
2023-08-30 10:44:42 +00:00
searchedValue?: string;
2023-10-13 10:22:58 +00:00
threadChains?: Map<string, Array<NostrEvent>>;
2023-11-14 10:38:02 +00:00
context?: ReactNode;
2023-01-31 11:52:55 +00:00
options?: {
2023-11-27 13:06:07 +00:00
isRoot?: boolean;
showHeader?: boolean;
2023-08-23 12:19:48 +00:00
showContextMenu?: boolean;
2023-12-12 12:04:38 +00:00
showProfileCard?: boolean;
showTime?: boolean;
showPinned?: boolean;
showBookmarked?: boolean;
showFooter?: boolean;
2023-02-12 12:31:48 +00:00
showReactionsLink?: boolean;
2023-08-23 12:19:48 +00:00
showMedia?: boolean;
canUnpin?: boolean;
canUnbookmark?: boolean;
2023-03-31 22:43:07 +00:00
canClick?: boolean;
2023-09-25 12:59:31 +00:00
showMediaSpotlight?: boolean;
2023-10-11 10:44:53 +00:00
longFormPreview?: boolean;
2023-11-25 18:52:58 +00:00
truncate?: boolean;
};
2023-01-16 17:48:25 +00:00
}
export default function Note(props: NoteProps) {
2023-09-05 13:57:50 +00:00
const { data: ev, className } = props;
let content;
2023-09-05 13:57:50 +00:00
if (ev.kind === EventKind.Repost) {
content = <NoteReaction data={ev} key={ev.id} root={undefined} depth={(props.depth ?? 0) + 1} />;
2023-09-05 13:57:50 +00:00
}
if (ev.kind === EventKind.FileHeader) {
content = <NostrFileElement ev={ev} />;
}
2023-05-22 10:32:12 +00:00
if (ev.kind === EventKind.ZapstrTrack) {
content = <ZapstrEmbed ev={ev} />;
2023-05-15 12:52:29 +00:00
}
2023-11-23 13:09:23 +00:00
if (ev.kind === EventKind.FollowSet || ev.kind === EventKind.ContactList) {
content = <PubkeyList ev={ev} className={className} />;
2023-05-22 10:32:12 +00:00
}
2023-06-17 11:53:38 +00:00
if (ev.kind === EventKind.LiveEvent) {
content = <LiveEvent ev={ev} />;
2023-06-17 11:53:38 +00:00
}
2023-09-05 13:57:50 +00:00
if (ev.kind === EventKind.SetMetadata) {
content = <ProfilePreview actions={<></>} pubkey={ev.pubkey} />;
2023-09-05 13:57:50 +00:00
}
2023-08-20 21:51:56 +00:00
if (ev.kind === (9041 as EventKind)) {
content = <ZapGoal ev={ev} />;
2023-08-20 21:51:56 +00:00
}
2023-10-11 10:44:53 +00:00
if (ev.kind === EventKind.LongFormTextNote) {
content = (
2023-10-16 12:45:51 +00:00
<LongFormText
ev={ev}
related={props.related}
isPreview={props.options?.longFormPreview ?? false}
onClick={() => props.onClick?.(ev)}
truncate={props.options?.truncate}
2023-10-16 12:45:51 +00:00
/>
);
2023-10-11 10:44:53 +00:00
}
2023-05-22 10:32:12 +00:00
content = <NoteInner {...props} />;
return <ErrorBoundary>{content}</ErrorBoundary>;
2023-09-05 13:57:50 +00:00
}