import React, { useState, useEffect } from 'react'; import { useRecoilValue } from 'recoil'; import { QRCodeSVG } from 'qrcode.react'; import { Copy, CopyCheck } from 'lucide-react'; import { useGetSharedLinkQuery } from 'librechat-data-provider/react-query'; import { OGDialogTemplate, Button, Spinner, OGDialog } from '@librechat/client'; import { useLocalize, useCopyToClipboard } from '~/hooks'; import SharedLinkButton from './SharedLinkButton'; import { cn } from '~/utils'; import store from '~/store'; export default function ShareButton({ conversationId, open, onOpenChange, triggerRef, children, }: { conversationId: string; open: boolean; onOpenChange: React.Dispatch>; triggerRef?: React.RefObject; children?: React.ReactNode; }) { const localize = useLocalize(); const [showQR, setShowQR] = useState(false); const [sharedLink, setSharedLink] = useState(''); const [isCopying, setIsCopying] = useState(false); const copyLink = useCopyToClipboard({ text: sharedLink }); const latestMessage = useRecoilValue(store.latestMessageFamily(0)); const { data: share, isLoading } = useGetSharedLinkQuery(conversationId); useEffect(() => { if (share?.shareId !== undefined) { const link = `${window.location.protocol}//${window.location.host}/share/${share.shareId}`; setSharedLink(link); } }, [share]); const button = isLoading === true ? null : ( ); const shareId = share?.shareId ?? ''; return ( {children}
{(() => { if (isLoading === true) { return ; } return share?.success === true ? localize('com_ui_share_update_message') : localize('com_ui_share_create_message'); })()}
{showQR && (
)} {shareId && (
{sharedLink}
)}
} />
); }