import React, { useRef } from "react"; import { Box, ButtonGroup, Card, CardBody, CardFooter, CardHeader, CardProps, Flex, IconButton, Link, LinkBox, Text, useDisclosure, } from "@chakra-ui/react"; import { NostrEvent } from "../../types/nostr-event"; import UserAvatarLink from "../user-avatar-link"; import { Link as RouterLink } from "react-router-dom"; import NoteMenu from "./note-menu"; import UserLink from "../user-link"; import { UserDnsIdentityIcon } from "../user-dns-identity-icon"; import NoteZapButton from "./note-zap-button"; import { ExpandProvider } from "../../providers/local/expanded"; import useSubject from "../../hooks/use-subject"; import appSettings from "../../services/settings/app-settings"; import EventVerificationIcon from "../event-verification-icon"; import RepostButton from "./components/repost-button"; import QuoteRepostButton from "./components/quote-repost-button"; import { ReplyIcon } from "../icons"; import NoteContentWithWarning from "./note-content-with-warning"; import { TrustProvider } from "../../providers/local/trust"; import { useRegisterIntersectionEntity } from "../../providers/local/intersection-observer"; import BookmarkButton from "./components/bookmark-button"; import useCurrentAccount from "../../hooks/use-current-account"; import NoteReactions from "./components/note-reactions"; import ReplyForm from "../../views/thread/components/reply-form"; import { getReferences, truncatedId } from "../../helpers/nostr/events"; import Timestamp from "../timestamp"; import OpenInDrawerButton from "../open-in-drawer-button"; import { getSharableEventAddress } from "../../helpers/nip19"; import { useBreakpointValue } from "../../providers/global/breakpoint-provider"; import HoverLinkOverlay from "../hover-link-overlay"; import NoteCommunityMetadata from "./note-community-metadata"; import useSingleEvent from "../../hooks/use-single-event"; import { CompactNoteContent } from "../compact-note-content"; import NoteProxyLink from "./components/note-proxy-link"; import { NoteDetailsButton } from "./components/note-details-button"; import EventInteractionDetailsModal from "../event-interactions-modal"; import singleEventService from "../../services/single-event"; import { AddressPointer, EventPointer } from "nostr-tools/lib/types/nip19"; import { nip19 } from "nostr-tools"; function ReplyToE({ pointer }: { pointer: EventPointer }) { const event = useSingleEvent(pointer.id, pointer.relays); if (!event) { const nevent = nip19.neventEncode(pointer); return ( Replying to{" "} {truncatedId(nevent)} ); } return ( <> Replying to ); } function ReplyToA({ pointer }: { pointer: AddressPointer }) { const naddr = nip19.naddrEncode(pointer); return ( Replying to{" "} {truncatedId(naddr)} ); } function ReplyLine({ event }: { event: NostrEvent }) { const refs = getReferences(event); if (!refs.reply) return null; return ( {refs.reply.type === "nevent" ? : } ); } export type NoteProps = Omit & { event: NostrEvent; variant?: CardProps["variant"]; showReplyButton?: boolean; showReplyLine?: boolean; hideDrawerButton?: boolean; registerIntersectionEntity?: boolean; clickable?: boolean; }; export const Note = React.memo( ({ event, variant = "outline", showReplyButton, showReplyLine = true, hideDrawerButton, registerIntersectionEntity = true, clickable = true, ...props }: NoteProps) => { const account = useCurrentAccount(); const { showReactions, showSignatureVerification } = useSubject(appSettings); const replyForm = useDisclosure(); const detailsModal = useDisclosure(); // if there is a parent intersection observer, register this card const ref = useRef(null); useRegisterIntersectionEntity(ref, event.id); const showReactionsOnNewLine = useBreakpointValue({ base: true, lg: false }); const reactionButtons = showReactions && ; return ( {clickable && ( singleEventService.handleEvent(event)} /> )} {showSignatureVerification && } {!hideDrawerButton && ( singleEventService.handleEvent(event)} /> )} {showReplyLine && } {showReactionsOnNewLine && reactionButtons} {showReplyButton && ( } aria-label="Reply" title="Reply" onClick={replyForm.onOpen} /> )} {!showReactionsOnNewLine && reactionButtons} {replyForm.isOpen && ( )} {detailsModal.isOpen && } ); }, ); export default Note;