import React, { useMemo, useRef } from "react"; import dayjs from "dayjs"; import { Box, ButtonGroup, Card, CardBody, CardFooter, CardHeader, CardProps, Flex, IconButton, Link, } from "@chakra-ui/react"; import { NostrEvent } from "../../types/nostr-event"; import { UserAvatarLink } from "../user-avatar-link"; import { NoteMenu } from "./note-menu"; import { EventRelays } from "./note-relays"; import { UserLink } from "../user-link"; import { UserDnsIdentityIcon } from "../user-dns-identity-icon"; import ReactionButton from "./buttons/reaction-button"; import NoteZapButton from "./note-zap-button"; import { ExpandProvider } from "./expanded"; import useSubject from "../../hooks/use-subject"; import appSettings from "../../services/settings/app-settings"; import EventVerificationIcon from "../event-verification-icon"; import { ReplyButton } from "./buttons/reply-button"; import { RepostButton } from "./buttons/repost-button"; import { QuoteRepostButton } from "./buttons/quote-repost-button"; import { ExternalLinkIcon } from "../icons"; import NoteContentWithWarning from "./note-content-with-warning"; import { TrustProvider } from "../../providers/trust"; import { NoteLink } from "../note-link"; import { useRegisterIntersectionEntity } from "../../providers/intersection-observer"; export type NoteProps = { event: NostrEvent; variant?: CardProps["variant"]; }; export const Note = React.memo(({ event, variant = "outline" }: NoteProps) => { const { showReactions, showSignatureVerification } = useSubject(appSettings); // if there is a parent intersection observer, register this card const ref = useRef(null); useRegisterIntersectionEntity(ref, event.id); // find mostr external link const externalLink = useMemo(() => event.tags.find((t) => t[0] === "mostr" || t[0] === "proxy"), [event])?.[1]; return ( {showSignatureVerification && } {dayjs.unix(event.created_at).fromNow()} {showReactions && } {externalLink && ( } aria-label="Open External" href={externalLink} size="sm" variant="link" target="_blank" /> )} ); });