import { LNURL } from "@snort/shared"; import { CachedMetadata, encodeTLVEntries, NostrPrefix, TLVEntryType } from "@snort/system"; import React, { useMemo, useState } from "react"; import { FormattedMessage, useIntl } from "react-intl"; import { Link, useNavigate } from "react-router-dom"; import IconButton from "@/Components/Button/IconButton"; import Copy from "@/Components/Copy/Copy"; import Modal from "@/Components/Modal/Modal"; import QrCode from "@/Components/QrCode"; import { SpotlightMediaModal } from "@/Components/Spotlight/SpotlightMedia"; import Avatar from "@/Components/User/Avatar"; import FollowButton from "@/Components/User/FollowButton"; import ProfileImage from "@/Components/User/ProfileImage"; import ZapModal from "@/Components/ZapModal/ZapModal"; import { hexToBech32 } from "@/Utils"; import { LoginSessionType, LoginStore } from "@/Utils/Login"; import { ZapTarget } from "@/Utils/Zapper"; const AvatarSection = ({ user, id, loginPubKey, readonly, lnurl, }: { user?: CachedMetadata; id?: string; loginPubKey?: string; lnurl?: LNURL; readonly?: boolean; }) => { const [showProfileQr, setShowProfileQr] = useState(false); const [modalImage, setModalImage] = useState(""); const [showLnQr, setShowLnQr] = useState(false); const profileId = useMemo(() => hexToBech32(CONFIG.profileLinkPrefix, id), [id]); const navigate = useNavigate(); const isMe = loginPubKey === id; const canWrite = !!loginPubKey && !readonly; const intl = useIntl(); const renderButtons = () => { if (!id) return null; return ( <> setShowProfileQr(true)} icon={{ name: "qr", size: 16 }} /> {showProfileQr && ( setShowProfileQr(false)}>
)} {isMe ? ( <> ) : ( <> {lnurl && setShowLnQr(true)} icon={{ name: "zap", size: 16 }} />} {canWrite && ( navigate( `/messages/${encodeTLVEntries("chat4" as NostrPrefix, { type: TLVEntryType.Author, length: 32, value: id, })}`, ) } icon={{ name: "envelope", size: 16 }} /> )} {!canWrite && !isMe && ( { if (confirm(intl.formatMessage({ defaultMessage: "View as user?", id: "LBAnc7" }))) { LoginStore.loginWithPubkey(id, LoginSessionType.PublicKey); } }} icon={{ name: "openeye", size: 16, className: "translate-y-0.5" }} /> )} )} ); }; return (
setModalImage(user?.picture || "")} className="pointer" size={100} />
{renderButtons()} {!isMe && id && }
{modalImage && setModalImage("")} media={[modalImage]} idx={0} />} setShowLnQr(false)} />
); }; export default AvatarSection;