import { useEffect, useRef, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { NavLink, useNavigate } from 'react-router-dom'; import DocsGPT3 from './assets/cute_docsgpt3.svg'; import Discord from './assets/discord.svg'; import Expand from './assets/expand.svg'; import Github from './assets/github.svg'; import Hamburger from './assets/hamburger.svg'; import HamburgerDark from './assets/hamburger-dark.svg'; import Info from './assets/info.svg'; import SettingGear from './assets/settingGear.svg'; import Twitter from './assets/TwitterX.svg'; import Add from './assets/add.svg'; import UploadIcon from './assets/upload.svg'; import { ActiveState } from './models/misc'; import APIKeyModal from './preferences/APIKeyModal'; import DeleteConvModal from './modals/DeleteConvModal'; import { selectApiKeyStatus, selectSelectedDocs, selectSelectedDocsStatus, selectSourceDocs, setSelectedDocs, selectConversations, setConversations, selectConversationId, selectModalStateDeleteConv, setModalStateDeleteConv, setSourceDocs, } from './preferences/preferenceSlice'; import { setConversation, updateConversationId, } from './conversation/conversationSlice'; import { useMediaQuery, useOutsideAlerter } from './hooks'; import Upload from './upload/Upload'; import { Doc, getConversations, getDocs } from './preferences/preferenceApi'; import SelectDocsModal from './preferences/SelectDocsModal'; import ConversationTile from './conversation/ConversationTile'; import { useDarkTheme } from './hooks'; import SourceDropdown from './components/SourceDropdown'; import { useTranslation } from 'react-i18next'; interface NavigationProps { navOpen: boolean; setNavOpen: React.Dispatch>; } /* const NavImage: React.FC<{ Light: string | undefined; Dark: string | undefined; }> = ({ Light, Dark }) => { return ( <> icon icon ); }; NavImage.propTypes = { Light: PropTypes.string, Dark: PropTypes.string, }; */ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { const dispatch = useDispatch(); const docs = useSelector(selectSourceDocs); const selectedDocs = useSelector(selectSelectedDocs); const conversations = useSelector(selectConversations); const modalStateDeleteConv = useSelector(selectModalStateDeleteConv); const conversationId = useSelector(selectConversationId); const { isMobile } = useMediaQuery(); const [isDarkTheme] = useDarkTheme(); const [isDocsListOpen, setIsDocsListOpen] = useState(false); const { t } = useTranslation(); const isApiKeySet = useSelector(selectApiKeyStatus); const [apiKeyModalState, setApiKeyModalState] = useState('INACTIVE'); const isSelectedDocsSet = useSelector(selectSelectedDocsStatus); const [selectedDocsModalState, setSelectedDocsModalState] = useState(isSelectedDocsSet ? 'INACTIVE' : 'ACTIVE'); const [uploadModalState, setUploadModalState] = useState('INACTIVE'); const navRef = useRef(null); const apiHost = import.meta.env.VITE_API_HOST || 'https://docsapi.arc53.com'; const navigate = useNavigate(); useEffect(() => { if (!conversations) { fetchConversations(); } }, [conversations, dispatch]); async function fetchConversations() { return await getConversations() .then((fetchedConversations) => { dispatch(setConversations(fetchedConversations)); }) .catch((error) => { console.error('Failed to fetch conversations: ', error); }); } const handleDeleteAllConversations = () => { fetch(`${apiHost}/api/delete_all_conversations`, { method: 'POST', }) .then(() => { fetchConversations(); }) .catch((error) => console.error(error)); }; const handleDeleteConversation = (id: string) => { fetch(`${apiHost}/api/delete_conversation?id=${id}`, { method: 'POST', }) .then(() => { fetchConversations(); }) .catch((error) => console.error(error)); }; const handleDeleteClick = (doc: Doc) => { const docPath = `indexes/local/${doc.name}`; fetch(`${apiHost}/api/delete_old?path=${docPath}`, { method: 'GET', }) .then(() => { // remove the image element from the DOM // const imageElement = document.querySelector( // `#img-${index}`, // ) as HTMLElement; // const parentElement = imageElement.parentNode as HTMLElement; // parentElement.parentNode?.removeChild(parentElement); return getDocs(); }) .then((updatedDocs) => { dispatch(setSourceDocs(updatedDocs)); dispatch( setSelectedDocs( updatedDocs?.find((doc) => doc.name.toLowerCase() === 'default'), ), ); }) .catch((error) => console.error(error)); }; const handleConversationClick = (index: string) => { // fetch the conversation from the server and setConversation in the store fetch(`${apiHost}/api/get_single_conversation?id=${index}`, { method: 'GET', }) .then((response) => response.json()) .then((data) => { navigate('/'); dispatch(setConversation(data)); dispatch( updateConversationId({ query: { conversationId: index }, }), ); }); }; async function updateConversationName(updatedConversation: { name: string; id: string; }) { await fetch(`${apiHost}/api/update_conversation_name`, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(updatedConversation), }) .then((response) => response.json()) .then((data) => { if (data) { navigate('/'); fetchConversations(); } }) .catch((err) => { console.error(err); }); } useOutsideAlerter( navRef, () => { if (isMobile && navOpen && apiKeyModalState === 'INACTIVE') { setNavOpen(false); setIsDocsListOpen(false); } }, [navOpen, isDocsListOpen, apiKeyModalState], ); /* Needed to fix bug where if mobile nav was closed and then window was resized to desktop, nav would still be closed but the button to open would be gone, as per #1 on issue #146 */ useEffect(() => { setNavOpen(!isMobile); }, [isMobile]); return ( <> {!navOpen && ( )}

DocsGPT

{ dispatch(setConversation([])); dispatch( updateConversationId({ query: { conversationId: null }, }), ); }} className={({ isActive }) => `${ isActive ? 'bg-gray-3000 dark:bg-transparent' : '' } group sticky mx-4 mt-4 flex cursor-pointer gap-2.5 rounded-3xl border border-silver p-3 hover:border-rainy-gray hover:bg-gray-3000 dark:border-purple-taupe dark:text-white dark:hover:bg-transparent` } > new

{t('newChat')}

{conversations && conversations.length > 0 ? (

{t('chats')}

{conversations?.map((conversation) => ( handleConversationClick(id)} onDeleteConversation={(id) => handleDeleteConversation(id)} onSave={(conversation) => updateConversationName(conversation) } /> ))}
) : ( <> )}
setUploadModalState('ACTIVE')} >

{t('sourceDocs')}

`my-auto mx-4 flex h-9 cursor-pointer gap-4 rounded-3xl hover:bg-gray-100 dark:hover:bg-[#28292E] ${ isActive ? 'bg-gray-3000 dark:bg-transparent' : '' }` } > icon

{t('settings.label')}

`my-auto mx-4 flex h-9 cursor-pointer gap-4 rounded-3xl hover:bg-gray-100 dark:hover:bg-[#28292E] ${ isActive ? 'bg-gray-3000 dark:bg-[#28292E]' : '' }` } > icon

{t('about')}

discord x github
); }