snort/packages/app/src/Components/Event/EventComponent.tsx

94 lines
2.7 KiB
TypeScript
Raw Normal View History

import "./EventComponent.css";
2024-01-04 17:01:18 +00:00
2023-10-13 10:22:58 +00:00
import { EventKind, NostrEvent, TaggedNostrEvent } from "@snort/system";
2024-01-08 08:27:26 +00:00
import { memo, ReactNode } from "react";
2024-01-04 17:01:18 +00:00
import PubkeyList from "@/Components/Embed/PubkeyList";
2024-01-04 17:01:18 +00:00
import ZapstrEmbed from "@/Components/Embed/ZapstrEmbed";
import ErrorBoundary from "@/Components/ErrorBoundary";
import { NostrFileElement } from "@/Components/Event/NostrFileHeader";
import NoteReaction from "@/Components/Event/NoteReaction";
2024-01-04 17:01:18 +00:00
import { ZapGoal } from "@/Components/Event/ZapGoal";
import { LiveEvent } from "@/Components/LiveStream/LiveEvent";
import ProfilePreview from "@/Components/User/ProfilePreview";
2024-01-04 17:01:18 +00:00
2023-10-11 10:44:53 +00:00
import { LongFormText } from "./LongFormText";
2024-01-08 12:06:24 +00:00
import { Note } from "./Note/Note";
export interface NotePropsOptions {
isRoot?: boolean;
showHeader?: boolean;
showContextMenu?: boolean;
showProfileCard?: boolean;
showTime?: boolean;
showPinned?: boolean;
showBookmarked?: boolean;
showFooter?: boolean;
showReactionsLink?: boolean;
showMedia?: boolean;
canUnpin?: boolean;
canUnbookmark?: boolean;
canClick?: boolean;
showMediaSpotlight?: boolean;
longFormPreview?: boolean;
truncate?: boolean;
}
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;
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;
2024-01-08 12:06:24 +00:00
options?: NotePropsOptions;
2024-01-02 07:33:22 +00:00
waitUntilInView?: boolean;
2023-01-16 17:48:25 +00:00
}
2024-01-08 12:06:24 +00:00
export default memo(function EventComponent(props: NoteProps) {
2023-09-05 13:57:50 +00:00
const { data: ev, className } = props;
2023-12-18 11:24:04 +00:00
let content;
2023-12-18 11:24:04 +00:00
switch (ev.kind) {
case EventKind.Repost:
content = <NoteReaction data={ev} key={ev.id} root={undefined} depth={(props.depth ?? 0) + 1} />;
break;
case EventKind.FileHeader:
content = <NostrFileElement ev={ev} />;
break;
case EventKind.ZapstrTrack:
content = <ZapstrEmbed ev={ev} />;
break;
case EventKind.FollowSet:
case EventKind.ContactList:
content = <PubkeyList ev={ev} className={className} />;
break;
case EventKind.LiveEvent:
content = <LiveEvent ev={ev} />;
break;
case EventKind.SetMetadata:
content = <ProfilePreview actions={<></>} pubkey={ev.pubkey} />;
break;
case 9041: // Assuming 9041 is a valid EventKind
content = <ZapGoal ev={ev} />;
break;
case EventKind.LongFormTextNote:
content = (
<LongFormText
ev={ev}
isPreview={props.options?.longFormPreview ?? false}
onClick={() => props.onClick?.(ev)}
truncate={props.options?.truncate}
/>
);
break;
default:
2024-01-08 12:06:24 +00:00
content = <Note {...props} />;
2023-10-11 10:44:53 +00:00
}
2023-05-22 10:32:12 +00:00
return <ErrorBoundary>{content}</ErrorBoundary>;
2024-01-08 08:27:26 +00:00
});