import { useMemo, useCallback } from 'react'; import { ArrowLeft } from 'lucide-react'; import { useSetRecoilState } from 'recoil'; import { useLocation } from 'react-router-dom'; import { Button, Sidebar, TooltipAnchor } from '@librechat/client'; import { usePromptGroupsContext, useDashboardContext } from '~/Providers'; import { useLocalize, useCustomLink } from '~/hooks'; import ManagePrompts from '../buttons/ManagePrompts'; import PanelNavigation from './PanelNavigation'; import List from '../lists/List'; import { cn } from '~/utils'; import store from '~/store'; export default function GroupSidePanel({ children, className = '', closePanelRef, onClose, }: { children?: React.ReactNode; className?: string; closePanelRef?: React.RefObject; onClose?: () => void; }) { const location = useLocation(); const localize = useLocalize(); const isChatRoute = useMemo(() => location.pathname?.startsWith('/c/'), [location.pathname]); const { prevLocationPath } = useDashboardContext(); const setPromptsName = useSetRecoilState(store.promptsName); const setPromptsCategory = useSetRecoilState(store.promptsCategory); const clickCallback = useCallback(() => { setPromptsName(''); setPromptsCategory(''); }, [setPromptsName, setPromptsCategory]); const lastConversationId = useMemo(() => { if (!prevLocationPath || prevLocationPath.includes('/d/')) { return 'new'; } const parts = prevLocationPath.split('/'); return parts[parts.length - 1]; }, [prevLocationPath]); const chatLinkHandler = useCustomLink('/c/' + lastConversationId, clickCallback); const promptsLinkHandler = useCustomLink('/d/prompts'); const { promptGroups, groupsQuery, nextPage, prevPage, hasNextPage, hasPreviousPage } = usePromptGroupsContext(); return (
{onClose && (
} />
)}
{children}
{isChatRoute && }
); }