From 9230fd3bd6086688b728642b2124c9898253441a Mon Sep 17 00:00:00 2001 From: ManishMadan2882 Date: Thu, 20 Mar 2025 09:47:29 +0530 Subject: [PATCH] Revert "(feat:nav) clean-up source dropdown" This reverts commit 561a125c92af41679aac956915c79f6a3dfc8786. --- frontend/src/Navigation.tsx | 100 +++++++++++++++++++++++++++++++++--- 1 file changed, 94 insertions(+), 6 deletions(-) diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index 2b2bf943..6195baa9 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -3,6 +3,7 @@ import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; import { NavLink, useNavigate } from 'react-router-dom'; import conversationService from './api/services/conversationService'; +import userService from './api/services/userService'; import Add from './assets/add.svg'; import openNewChat from './assets/openNewChat.svg'; import Hamburger from './assets/hamburger.svg'; @@ -12,6 +13,8 @@ import Expand from './assets/expand.svg'; import Github from './assets/github.svg'; import SettingGear from './assets/settingGear.svg'; import Twitter from './assets/TwitterX.svg'; +import UploadIcon from './assets/upload.svg'; +import SourceDropdown from './components/SourceDropdown'; import { setConversation, updateConversationId, @@ -21,18 +24,26 @@ import ConversationTile from './conversation/ConversationTile'; import { useDarkTheme, useMediaQuery } from './hooks'; import useDefaultDocument from './hooks/useDefaultDocument'; import DeleteConvModal from './modals/DeleteConvModal'; -import { getConversations } from './preferences/preferenceApi'; +import { ActiveState, Doc } from './models/misc'; +import { getConversations, getDocs } from './preferences/preferenceApi'; import { selectApiKeyStatus, selectConversationId, selectConversations, selectModalStateDeleteConv, + selectSelectedDocs, + selectSourceDocs, + selectPaginatedDocuments, setConversations, setModalStateDeleteConv, + setSelectedDocs, + setSourceDocs, + setPaginatedDocuments, } from './preferences/preferenceSlice'; import Spinner from './assets/spinner.svg'; import SpinnerDark from './assets/spinner-dark.svg'; import { selectQueries } from './conversation/conversationSlice'; +import Upload from './upload/Upload'; import Help from './components/Help'; interface NavigationProps { @@ -43,17 +54,25 @@ interface NavigationProps { export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { const dispatch = useDispatch(); const queries = useSelector(selectQueries); + const docs = useSelector(selectSourceDocs); + const selectedDocs = useSelector(selectSelectedDocs); const conversations = useSelector(selectConversations); const modalStateDeleteConv = useSelector(selectModalStateDeleteConv); const conversationId = useSelector(selectConversationId); + const paginatedDocuments = useSelector(selectPaginatedDocuments); const [isDeletingConversation, setIsDeletingConversation] = useState(false); const { isMobile } = useMediaQuery(); const [isDarkTheme] = useDarkTheme(); + const [isDocsListOpen, setIsDocsListOpen] = useState(false); const { t } = useTranslation(); const isApiKeySet = useSelector(selectApiKeyStatus); + const [uploadModalState, setUploadModalState] = + useState('INACTIVE'); + const navRef = useRef(null); + const navigate = useNavigate(); useEffect(() => { @@ -98,6 +117,32 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { .catch((error) => console.error(error)); }; + const handleDeleteClick = (doc: Doc) => { + userService + .deletePath(doc.id ?? '') + .then(() => { + return getDocs(); + }) + .then((updatedDocs) => { + dispatch(setSourceDocs(updatedDocs)); + const updatedPaginatedDocs = paginatedDocuments?.filter( + (document) => document.id !== doc.id, + ); + dispatch( + setPaginatedDocuments(updatedPaginatedDocs || paginatedDocuments), + ); + dispatch( + setSelectedDocs( + Array.isArray(updatedDocs) && + updatedDocs?.find( + (doc: Doc) => doc.name.toLowerCase() === 'default', + ), + ), + ); + }) + .catch((error) => console.error(error)); + }; + const handleConversationClick = (index: string) => { conversationService .getConversation(index) @@ -157,7 +202,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { return ( <> {!navOpen && ( -
+