diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index cbfe5d95..56342ead 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -22,6 +22,7 @@ import { } from './conversation/conversationSlice'; import ConversationTile from './conversation/ConversationTile'; import { useDarkTheme, useMediaQuery, useOutsideAlerter } from './hooks'; +import useDefaultDocument from './hooks/useDefaultDocument'; import DeleteConvModal from './modals/DeleteConvModal'; import { ActiveState } from './models/misc'; import APIKeyModal from './preferences/APIKeyModal'; @@ -39,7 +40,6 @@ import { setSelectedDocs, setSourceDocs, } from './preferences/preferenceSlice'; -import SelectDocsModal from './preferences/SelectDocsModal'; import Upload from './upload/Upload'; interface NavigationProps { @@ -192,6 +192,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { useEffect(() => { setNavOpen(!isMobile); }, [isMobile]); + useDefaultDocument(); return ( <> {!navOpen && ( @@ -398,12 +399,6 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { /> - - { + getDocs().then((data) => { + dispatch(setSourceDocs(data)); + if (!selectedDoc) + data?.forEach((doc: Doc) => { + if (doc.model && doc.name === 'default') { + dispatch(setSelectedDocs(doc)); + } + }); + }); + }; + + React.useEffect(() => { + fetchDocs(); + }, []); +} diff --git a/frontend/src/preferences/SelectDocsModal.tsx b/frontend/src/preferences/SelectDocsModal.tsx deleted file mode 100644 index edb2714b..00000000 --- a/frontend/src/preferences/SelectDocsModal.tsx +++ /dev/null @@ -1,117 +0,0 @@ -import { useEffect, useState } from 'react'; -import { useDispatch, useSelector } from 'react-redux'; -import { ActiveState } from '../models/misc'; -import Modal from '../modals'; -import { - setSelectedDocs, - setSourceDocs, - selectSourceDocs, - selectSelectedDocs, -} from './preferenceSlice'; -import { getDocs, Doc } from './preferenceApi'; - -export default function APIKeyModal({ - modalState, - setModalState, - isCancellable = true, -}: { - modalState: ActiveState; - setModalState: (val: ActiveState) => void; - isCancellable?: boolean; -}) { - const dispatch = useDispatch(); - const docs = useSelector(selectSourceDocs); - const selectedDoc = useSelector(selectSelectedDocs); - const [localSelectedDocs, setLocalSelectedDocs] = useState( - selectedDoc, - ); - const [isDocsListOpen, setIsDocsListOpen] = useState(false); - const [isError, setIsError] = useState(false); - - function handleSubmit() { - if (!localSelectedDocs) { - setIsError(true); - } else { - dispatch(setSelectedDocs(localSelectedDocs)); - setModalState('INACTIVE'); - setIsError(false); - } - } - - function handleCancel() { - setIsError(false); - setModalState('INACTIVE'); - } - - useEffect(() => { - async function requestDocs() { - const data = await getDocs(); - dispatch(setSourceDocs(data)); - } - - requestDocs(); - }, []); - return ( - { - return ( -
-

Select Source Documentation

-

- Please select the library of documentation that you would like to - use with our app. -

-
-
setIsDocsListOpen(!isDocsListOpen)} - > - {!localSelectedDocs ? ( -

Select

- ) : ( -

- {localSelectedDocs.name} {localSelectedDocs.version} -

- )} -
- {isDocsListOpen && ( -
- {docs ? ( - docs.map((doc, index) => { - if (doc.model) { - return ( -
{ - setLocalSelectedDocs(doc); - setIsDocsListOpen(false); - }} - className="h-10 w-full cursor-pointer border-x-2 border-b-2 hover:bg-gray-100" - > -

- {doc.name} {doc.version} -

-
- ); - } - }) - ) : ( -
-

No default documentation.

-
- )} -
- )} -
-
- ); - }} - /> - ); -}