import { useMemo, useState, MouseEvent } from 'react'; import { Link } from 'react-router-dom'; import { MessageSquare, Link as LinkIcon } from 'lucide-react'; import type { SharedLinksResponse, TSharedLink } from 'librechat-data-provider'; import { useDeleteSharedLinkMutation, useSharedLinksInfiniteQuery } from '~/data-provider'; import { useAuthContext, useLocalize, useNavScrolling } from '~/hooks'; import { NotificationSeverity } from '~/common'; import { useToastContext } from '~/Providers'; import { cn } from '~/utils'; import { Spinner, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, TrashIcon, } from '~/components'; function SharedLinkDeleteButton({ shareId, setIsDeleting, }: { shareId: string; setIsDeleting: (isDeleting: boolean) => void; }) { const localize = useLocalize(); const { showToast } = useToastContext(); const mutation = useDeleteSharedLinkMutation({ onError: () => { showToast({ message: localize('com_ui_share_delete_error'), severity: NotificationSeverity.ERROR, showIcon: true, }); setIsDeleting(false); }, }); const handleDelete = async (e: MouseEvent) => { e.preventDefault(); if (mutation.isLoading) { return; } setIsDeleting(true); await mutation.mutateAsync({ shareId }); setIsDeleting(false); }; return ( {localize('com_ui_delete')} ); } function SourceChatButton({ conversationId }: { conversationId: string }) { const localize = useLocalize(); return ( {localize('com_nav_source_chat')} ); } function ShareLinkRow({ sharedLink }: { sharedLink: TSharedLink }) { const [isDeleting, setIsDeleting] = useState(false); return ( {sharedLink.title}
{new Date(sharedLink.createdAt).toLocaleDateString('en-US', { month: 'long', day: 'numeric', year: 'numeric', })}
{sharedLink.conversationId && ( <>
)}
); } export default function ShareLinkTable({ className }: { className?: string }) { const localize = useLocalize(); const { isAuthenticated } = useAuthContext(); const [showLoading, setShowLoading] = useState(false); const { data, fetchNextPage, hasNextPage, isFetchingNextPage, isError, isLoading } = useSharedLinksInfiniteQuery({ pageNumber: '1', isPublic: true }, { enabled: isAuthenticated }); const { containerRef } = useNavScrolling({ setShowLoading, hasNextPage: hasNextPage, fetchNextPage: fetchNextPage, isFetchingNextPage: isFetchingNextPage, }); const sharedLinks = useMemo(() => data?.pages.flatMap((page) => page.sharedLinks) || [], [data]); const classProp: { className?: string } = { className: 'p-1 hover:text-black dark:hover:text-white', }; if (className) { classProp.className = className; } if (isLoading) { return ; } if (isError) { return (
{localize('com_ui_share_retrieve_error')}
); } if (!sharedLinks || sharedLinks.length === 0) { return
{localize('com_nav_shared_links_empty')}
; } return (
{sharedLinks.map((sharedLink) => ( ))}
{localize('com_nav_shared_links_name')} {localize('com_nav_shared_links_date_shared')}
{(isFetchingNextPage || showLoading) && ( )}
); }