From 6f9ddeaed0e688dedc69c27db7535b328078f9ba Mon Sep 17 00:00:00 2001 From: TomasMatarazzo Date: Wed, 17 Apr 2024 19:51:29 -0300 Subject: [PATCH 01/12] Button to clean chat history --- application/api/user/routes.py | 5 ++ frontend/src/Navigation.tsx | 38 ++++++++++++- frontend/src/preferences/DeleteConvModal.tsx | 60 ++++++++++++++++++++ 3 files changed, 101 insertions(+), 2 deletions(-) create mode 100644 frontend/src/preferences/DeleteConvModal.tsx diff --git a/application/api/user/routes.py b/application/api/user/routes.py index de5a3c0..eb5d7ac 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -37,6 +37,11 @@ def delete_conversation(): return {"status": "ok"} +@user.route("/api/delete_all_conversations", methods=["POST"]) +def delete_all_conversations(): + conversations_collection.delete_many({}) + return {"status": "ok"} + @user.route("/api/get_conversations", methods=["get"]) def get_conversations(): # provides a list of conversations diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index c6b56e3..a13b37a 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -19,7 +19,9 @@ import SettingGearDark from './assets/settingGear-dark.svg'; import Add from './assets/add.svg'; import UploadIcon from './assets/upload.svg'; import { ActiveState } from './models/misc'; +import Trash from '../src/assets/trash.svg'; import APIKeyModal from './preferences/APIKeyModal'; + import { selectApiKeyStatus, selectSelectedDocs, @@ -41,6 +43,7 @@ import SelectDocsModal from './preferences/SelectDocsModal'; import ConversationTile from './conversation/ConversationTile'; import { useDarkTheme } from './hooks'; import SourceDropdown from './components/SourceDropdown'; +import DeleteConvModal from './preferences/DeleteConvModal'; interface NavigationProps { navOpen: boolean; @@ -75,6 +78,9 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { const [apiKeyModalState, setApiKeyModalState] = useState('INACTIVE'); + const [deleteConvModalState, setDeleteConvState] = + useState('INACTIVE'); + const isSelectedDocsSet = useSelector(selectSelectedDocsStatus); const [selectedDocsModalState, setSelectedDocsModalState] = useState(isSelectedDocsSet ? 'INACTIVE' : 'ACTIVE'); @@ -112,6 +118,16 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { .catch((error) => console.error(error)); }; + const handleDeleteAllConversations = () => { + fetch(`${apiHost}/api/delete_all_conversations`, { + method: 'POST', + }) + .then(() => { + fetchConversations(); + }) + .catch((error) => console.error(error)); + }; + const handleDeleteClick = (index: number, doc: Doc) => { const docPath = 'indexes/' + 'local' + '/' + doc.name; @@ -260,7 +276,20 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
{conversations && (
-

Chats

+
+

Chats

+ setDeleteConvState('ACTIVE')} + /> +
{conversations?.map((conversation) => (
-
+ + void; + handleDeleteAllConv: () => void; +}) { + // const dispatch = useDispatch() + const modalRef = useRef(null); + const { isMobile } = useMediaQuery(); + + useOutsideAlerter( + modalRef, + () => { + if (isMobile && modalState === 'ACTIVE') { + setModalState('INACTIVE'); + } + }, + [modalState], + ); + + function handleSubmit() { + handleDeleteAllConv(); + setModalState('INACTIVE'); + } + + function handleCancel() { + setModalState('INACTIVE'); + } + + return ( + { + return ( +
+

+ Are you sure you want to delete all the conversations? +

+

+
+ ); + }} + /> + ); +} From d4840f85c0b1a7f7a2c7c188641049648d6f79e2 Mon Sep 17 00:00:00 2001 From: TomasMatarazzo Date: Thu, 18 Apr 2024 13:50:08 -0300 Subject: [PATCH 02/12] change text in modal --- frontend/src/Modal/index.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/Modal/index.tsx b/frontend/src/Modal/index.tsx index ff3ed07..bc5f025 100644 --- a/frontend/src/Modal/index.tsx +++ b/frontend/src/Modal/index.tsx @@ -8,7 +8,9 @@ interface ModalProps { modalState: string; isError: boolean; errorMessage?: string; + textDelete?: boolean; } + const Modal = (props: ModalProps) => { return (
{ onClick={() => props.handleSubmit()} className="ml-auto h-10 w-20 rounded-3xl bg-violet-800 text-white transition-all hover:bg-violet-700" > - Save + {props.textDelete ? 'Delete' : 'Save'} {props.isCancellable && ( +
); }; From 480825ddd765a98daa141a7ea80bdf29471839b4 Mon Sep 17 00:00:00 2001 From: TomasMatarazzo Date: Mon, 22 Apr 2024 16:16:19 -0300 Subject: [PATCH 05/12] now is working in settings --- frontend/src/Navigation.tsx | 16 +++++++--------- frontend/src/preferences/DeleteConvModal.tsx | 9 +++++---- frontend/src/preferences/preferenceSlice.ts | 2 +- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index e669ea2..0de51dc 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -31,7 +31,8 @@ import { selectConversations, setConversations, selectConversationId, - selectModalState, + selectModalStateDeleteConv, + setModalStateDeleteConv, } from './preferences/preferenceSlice'; import { setConversation, @@ -69,7 +70,7 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { const docs = useSelector(selectSourceDocs); const selectedDocs = useSelector(selectSelectedDocs); const conversations = useSelector(selectConversations); - const modalState = useSelector(selectModalState); + const modalStateDeleteConv = useSelector(selectModalStateDeleteConv); const conversationId = useSelector(selectConversationId); const { isMobile } = useMediaQuery(); @@ -80,9 +81,6 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { const [apiKeyModalState, setApiKeyModalState] = useState('INACTIVE'); - const [deleteConvModalState, setDeleteConvState] = - useState('INACTIVE'); - const isSelectedDocsSet = useSelector(selectSelectedDocsStatus); const [selectedDocsModalState, setSelectedDocsModalState] = useState(isSelectedDocsSet ? 'INACTIVE' : 'ACTIVE'); @@ -102,8 +100,8 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { }, [conversations, dispatch]); useEffect(() => { - console.log(modalState); - }, [modalState]); + console.log(modalStateDeleteConv); + }, [modalStateDeleteConv]); async function fetchConversations() { return await getConversations() @@ -407,8 +405,8 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { isCancellable={isApiKeySet} /> void; handleDeleteAllConv: () => void; }) { - // const dispatch = useDispatch() + const dispatch = useDispatch(); const modalRef = useRef(null); const { isMobile } = useMediaQuery(); @@ -20,7 +21,7 @@ export default function DeleteConvModal({ modalRef, () => { if (isMobile && modalState === 'ACTIVE') { - setModalState('INACTIVE'); + dispatch(setModalState('INACTIVE')); } }, [modalState], @@ -28,11 +29,11 @@ export default function DeleteConvModal({ function handleSubmit() { handleDeleteAllConv(); - setModalState('INACTIVE'); + dispatch(setModalState('INACTIVE')); } function handleCancel() { - setModalState('INACTIVE'); + dispatch(setModalState('INACTIVE')); } return ( diff --git a/frontend/src/preferences/preferenceSlice.ts b/frontend/src/preferences/preferenceSlice.ts index 2d9bcb8..80eab20 100644 --- a/frontend/src/preferences/preferenceSlice.ts +++ b/frontend/src/preferences/preferenceSlice.ts @@ -121,7 +121,7 @@ export const selectSelectedDocsStatus = (state: RootState) => !!state.preference.selectedDocs; export const selectSourceDocs = (state: RootState) => state.preference.sourceDocs; -export const selectModalState = (state: RootState) => +export const selectModalStateDeleteConv = (state: RootState) => state.preference.modalState; export const selectSelectedDocs = (state: RootState) => state.preference.selectedDocs; From 8fa4ec7ad80c2e625bbd6a8773b050a2a339ab64 Mon Sep 17 00:00:00 2001 From: TomasMatarazzo Date: Mon, 22 Apr 2024 16:17:26 -0300 Subject: [PATCH 06/12] delete console.log --- frontend/src/Navigation.tsx | 4 ---- 1 file changed, 4 deletions(-) diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index 0de51dc..66572a4 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -99,10 +99,6 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { } }, [conversations, dispatch]); - useEffect(() => { - console.log(modalStateDeleteConv); - }, [modalStateDeleteConv]); - async function fetchConversations() { return await getConversations() .then((fetchedConversations) => { From fc170d303395a1bccce87955df60ccbd529534cb Mon Sep 17 00:00:00 2001 From: TomasMatarazzo Date: Mon, 22 Apr 2024 16:19:00 -0300 Subject: [PATCH 07/12] Update package.json --- frontend/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/package.json b/frontend/package.json index af29561..6e8d8e6 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -14,6 +14,7 @@ }, "lint-staged": { "**/*.{js,jsx,ts,tsx}": [ + "npm run lint-fix", "npm run format" ] }, From b84842df3d3d38a71041145b57a89e1d763bf9bf Mon Sep 17 00:00:00 2001 From: TomasMatarazzo Date: Mon, 22 Apr 2024 16:35:44 -0300 Subject: [PATCH 08/12] Fixing types --- frontend/src/preferences/DeleteConvModal.tsx | 3 ++- frontend/src/preferences/preferenceSlice.ts | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/frontend/src/preferences/DeleteConvModal.tsx b/frontend/src/preferences/DeleteConvModal.tsx index 9a600e5..f1a60e1 100644 --- a/frontend/src/preferences/DeleteConvModal.tsx +++ b/frontend/src/preferences/DeleteConvModal.tsx @@ -3,6 +3,7 @@ import { ActiveState } from '../models/misc'; import { useMediaQuery, useOutsideAlerter } from './../hooks'; import Modal from '../Modal'; import { useDispatch } from 'react-redux'; +import { Action } from '@reduxjs/toolkit'; export default function DeleteConvModal({ modalState, @@ -10,7 +11,7 @@ export default function DeleteConvModal({ handleDeleteAllConv, }: { modalState: ActiveState; - setModalState: (val: ActiveState) => void; + setModalState: (val: ActiveState) => Action; handleDeleteAllConv: () => void; }) { const dispatch = useDispatch(); diff --git a/frontend/src/preferences/preferenceSlice.ts b/frontend/src/preferences/preferenceSlice.ts index 80eab20..ca68df7 100644 --- a/frontend/src/preferences/preferenceSlice.ts +++ b/frontend/src/preferences/preferenceSlice.ts @@ -1,4 +1,5 @@ import { + PayloadAction, createListenerMiddleware, createSlice, isAnyOf, @@ -34,7 +35,7 @@ const initialState: Preference = { } as Doc, sourceDocs: null, conversations: null, - modalState: 'ACTIVE', + modalState: 'INACTIVE', }; export const prefSlice = createSlice({ @@ -59,7 +60,7 @@ export const prefSlice = createSlice({ setChunks: (state, action) => { state.chunks = action.payload; }, - setModalStateDeleteConv: (state, action) => { + setModalStateDeleteConv: (state, action: PayloadAction) => { state.modalState = action.payload; }, }, From 9804965a2074f94aa05822a816788a5851598d46 Mon Sep 17 00:00:00 2001 From: TomasMatarazzo Date: Thu, 25 Apr 2024 23:43:45 -0300 Subject: [PATCH 09/12] style in button and user in back route delete all conv --- application/api/user/routes.py | 3 ++- frontend/src/settings/General.tsx | 9 +-------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/application/api/user/routes.py b/application/api/user/routes.py index eb5d7ac..4ab0d00 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -39,7 +39,8 @@ def delete_conversation(): @user.route("/api/delete_all_conversations", methods=["POST"]) def delete_all_conversations(): - conversations_collection.delete_many({}) + user_id = "local" + conversations_collection.delete_many({"user":user_id}) return {"status": "ok"} @user.route("/api/get_conversations", methods=["get"]) diff --git a/frontend/src/settings/General.tsx b/frontend/src/settings/General.tsx index ef35b4f..6af23b9 100644 --- a/frontend/src/settings/General.tsx +++ b/frontend/src/settings/General.tsx @@ -10,7 +10,6 @@ import { selectChunks, setModalStateDeleteConv, } from '../preferences/preferenceSlice'; -import Trash from '../assets/trash.svg'; const apiHost = import.meta.env.VITE_API_HOST || 'https://docsapi.arc53.com'; @@ -101,18 +100,12 @@ const General: React.FC = () => { Delete all conversations

From ee3792181da47fae9fdbc57e10b2c570143d901d Mon Sep 17 00:00:00 2001 From: TomasMatarazzo Date: Fri, 26 Apr 2024 20:35:36 -0300 Subject: [PATCH 10/12] probando --- frontend/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/package.json b/frontend/package.json index 6e8d8e6..5c6ef82 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -58,4 +58,5 @@ "vite": "^5.0.13", "vite-plugin-svgr": "^4.2.0" } + } From eb7bbc1612c4ed406af39121034980fdfe0e5db3 Mon Sep 17 00:00:00 2001 From: TomasMatarazzo Date: Sat, 27 Apr 2024 11:04:28 -0300 Subject: [PATCH 11/12] TS2741 --- frontend/src/store.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/store.ts b/frontend/src/store.ts index c217648..e394d99 100644 --- a/frontend/src/store.ts +++ b/frontend/src/store.ts @@ -34,6 +34,7 @@ const store = configureStore({ model: '1.0', }, ], + modalState: 'INACTIVE', }, }, reducer: { From db7195aa3038bdcb56272519b057238ed31385b0 Mon Sep 17 00:00:00 2001 From: TomasMatarazzo Date: Mon, 29 Apr 2024 17:02:22 -0300 Subject: [PATCH 12/12] Update Navigation.tsx --- frontend/src/Navigation.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index 66572a4..b990459 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -103,7 +103,6 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { return await getConversations() .then((fetchedConversations) => { dispatch(setConversations(fetchedConversations)); - console.log(conversations); }) .catch((error) => { console.error('Failed to fetch conversations: ', error);