import { useEffect, useRef, useState } from 'react'; import { NavLink } from 'react-router-dom'; import Arrow1 from './assets/arrow.svg'; import Arrow2 from './assets/dropdown-arrow.svg'; import Exit from './assets/exit.svg'; import Message from './assets/message.svg'; import Hamburger from './assets/hamburger.svg'; import Key from './assets/key.svg'; import Info from './assets/info.svg'; import Link from './assets/link.svg'; import UploadIcon from './assets/upload.svg'; import { ActiveState } from './models/misc'; import APIKeyModal from './preferences/APIKeyModal'; import SelectDocsModal from './preferences/SelectDocsModal'; import { useDispatch, useSelector } from 'react-redux'; import { selectApiKeyStatus, selectSelectedDocs, selectSelectedDocsStatus, selectSourceDocs, setSelectedDocs, } from './preferences/preferenceSlice'; import { useOutsideAlerter } from './hooks'; import Upload from './upload/Upload'; import { Doc } from './preferences/preferenceApi'; export default function Navigation({ navState, setNavState, }: { navState: ActiveState; setNavState: React.Dispatch>; }) { const dispatch = useDispatch(); const docs = useSelector(selectSourceDocs); const selectedDocs = useSelector(selectSelectedDocs); const [isDocsListOpen, setIsDocsListOpen] = useState(false); const isApiKeySet = useSelector(selectApiKeyStatus); const [apiKeyModalState, setApiKeyModalState] = useState( isApiKeySet ? 'INACTIVE' : 'ACTIVE', ); 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 handleDeleteClick = (index: number, 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); }) .catch((error) => console.error(error)); }; useOutsideAlerter( navRef, () => { if ( window.matchMedia('(max-width: 768px)').matches && navState === 'ACTIVE' && apiKeyModalState === 'INACTIVE' ) { setNavState('INACTIVE'); setIsDocsListOpen(false); } }, [navState, 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(() => { window.addEventListener('resize', () => { if (window.matchMedia('(min-width: 768px)').matches) { setNavState('ACTIVE'); } else { setNavState('INACTIVE'); } }); }, []); return ( <>
`${ isActive ? 'bg-gray-3000' : '' } my-auto mx-4 mt-4 flex h-12 cursor-pointer gap-4 rounded-md hover:bg-gray-100` } >

Chat

setIsDocsListOpen(!isDocsListOpen)} > {selectedDocs && (

{selectedDocs.name} {selectedDocs.version}

)} arrow
setUploadModalState('ACTIVE')} > {isDocsListOpen && (
{docs ? ( docs.map((doc, index) => { if (doc.model) { return (
{ dispatch(setSelectedDocs(doc)); setIsDocsListOpen(false); }} className="flex h-10 w-full cursor-pointer items-center justify-between border-x-2 border-b-2 hover:bg-gray-100" >

{doc.name} {doc.version}

{doc.location === 'local' ? ( Exit { event.stopPropagation(); handleDeleteClick(index, doc); }} /> ) : null}
); } }) ) : (

No default documentation.

)} )
)}

Source Docs

{ setApiKeyModalState('ACTIVE'); }} > key

Reset Key

`my-auto mx-4 flex h-12 cursor-pointer gap-4 rounded-md hover:bg-gray-100 ${ isActive ? 'bg-gray-3000' : '' }` } > info

About

link

Discord

link

Github

); }