diff --git a/application/api/user/routes.py b/application/api/user/routes.py index de5a3c07..4ab0d007 100644 --- a/application/api/user/routes.py +++ b/application/api/user/routes.py @@ -37,6 +37,12 @@ def delete_conversation(): return {"status": "ok"} +@user.route("/api/delete_all_conversations", methods=["POST"]) +def delete_all_conversations(): + user_id = "local" + conversations_collection.delete_many({"user":user_id}) + return {"status": "ok"} + @user.route("/api/get_conversations", methods=["get"]) def get_conversations(): # provides a list of conversations diff --git a/frontend/package.json b/frontend/package.json index 6e8d8e60..5c6ef827 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -58,4 +58,5 @@ "vite": "^5.0.13", "vite-plugin-svgr": "^4.2.0" } + } diff --git a/frontend/src/Modal/index.tsx b/frontend/src/Modal/index.tsx index ff3ed075..bc5f0254 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 && (
+ + Action; + handleDeleteAllConv: () => void; +}) { + const dispatch = useDispatch(); + const modalRef = useRef(null); + const { isMobile } = useMediaQuery(); + + useOutsideAlerter( + modalRef, + () => { + if (isMobile && modalState === 'ACTIVE') { + dispatch(setModalState('INACTIVE')); + } + }, + [modalState], + ); + + function handleSubmit() { + handleDeleteAllConv(); + dispatch(setModalState('INACTIVE')); + } + + function handleCancel() { + dispatch(setModalState('INACTIVE')); + } + + return ( + { + return ( +
+

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

+

+
+ ); + }} + /> + ); +} diff --git a/frontend/src/preferences/preferenceSlice.ts b/frontend/src/preferences/preferenceSlice.ts index dc72fae1..ca68df70 100644 --- a/frontend/src/preferences/preferenceSlice.ts +++ b/frontend/src/preferences/preferenceSlice.ts @@ -1,10 +1,12 @@ import { + PayloadAction, createListenerMiddleware, createSlice, isAnyOf, } from '@reduxjs/toolkit'; import { Doc, setLocalApiKey, setLocalRecentDocs } from './preferenceApi'; import { RootState } from '../store'; +import { ActiveState } from '../models/misc'; interface Preference { apiKey: string; @@ -13,6 +15,7 @@ interface Preference { chunks: string; sourceDocs: Doc[] | null; conversations: { name: string; id: string }[] | null; + modalState: ActiveState; } const initialState: Preference = { @@ -32,6 +35,7 @@ const initialState: Preference = { } as Doc, sourceDocs: null, conversations: null, + modalState: 'INACTIVE', }; export const prefSlice = createSlice({ @@ -56,6 +60,9 @@ export const prefSlice = createSlice({ setChunks: (state, action) => { state.chunks = action.payload; }, + setModalStateDeleteConv: (state, action: PayloadAction) => { + state.modalState = action.payload; + }, }, }); @@ -66,6 +73,7 @@ export const { setConversations, setPrompt, setChunks, + setModalStateDeleteConv, } = prefSlice.actions; export default prefSlice.reducer; @@ -114,6 +122,8 @@ export const selectSelectedDocsStatus = (state: RootState) => !!state.preference.selectedDocs; export const selectSourceDocs = (state: RootState) => state.preference.sourceDocs; +export const selectModalStateDeleteConv = (state: RootState) => + state.preference.modalState; export const selectSelectedDocs = (state: RootState) => state.preference.selectedDocs; export const selectConversations = (state: RootState) => diff --git a/frontend/src/settings/General.tsx b/frontend/src/settings/General.tsx index 215628e5..6af23b98 100644 --- a/frontend/src/settings/General.tsx +++ b/frontend/src/settings/General.tsx @@ -8,6 +8,7 @@ import { setPrompt, setChunks, selectChunks, + setModalStateDeleteConv, } from '../preferences/preferenceSlice'; const apiHost = import.meta.env.VITE_API_HOST || 'https://docsapi.arc53.com'; @@ -43,6 +44,7 @@ const General: React.FC = () => { }; fetchPrompts(); }, []); + return (
@@ -93,6 +95,19 @@ const General: React.FC = () => { apiHost={apiHost} />
+
+

+ Delete all conversations +

+ +
); }; diff --git a/frontend/src/store.ts b/frontend/src/store.ts index c217648e..e394d998 100644 --- a/frontend/src/store.ts +++ b/frontend/src/store.ts @@ -34,6 +34,7 @@ const store = configureStore({ model: '1.0', }, ], + modalState: 'INACTIVE', }, }, reducer: {