mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 16:43:16 +00:00
refactor/chore: migrated away from manually removing a deleted source doc from UI / latest docs are fetched after deletion to update UI
This commit is contained in:
@@ -27,6 +27,7 @@ import {
|
||||
selectConversationId,
|
||||
selectModalStateDeleteConv,
|
||||
setModalStateDeleteConv,
|
||||
setSourceDocs,
|
||||
} from './preferences/preferenceSlice';
|
||||
import {
|
||||
setConversation,
|
||||
@@ -34,7 +35,7 @@ import {
|
||||
} from './conversation/conversationSlice';
|
||||
import { useMediaQuery, useOutsideAlerter } from './hooks';
|
||||
import Upload from './upload/Upload';
|
||||
import { Doc, getConversations } from './preferences/preferenceApi';
|
||||
import { Doc, getConversations, getDocs } from './preferences/preferenceApi';
|
||||
import SelectDocsModal from './preferences/SelectDocsModal';
|
||||
import ConversationTile from './conversation/ConversationTile';
|
||||
import { useDarkTheme } from './hooks';
|
||||
@@ -124,21 +125,29 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
|
||||
.catch((error) => console.error(error));
|
||||
};
|
||||
|
||||
const handleDeleteClick = (index: number, doc: Doc) => {
|
||||
const docPath = 'indexes/' + 'local' + '/' + doc.name;
|
||||
const handleDeleteClick = (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);
|
||||
// const imageElement = document.querySelector(
|
||||
// `#img-${index}`,
|
||||
// ) as HTMLElement;
|
||||
// const parentElement = imageElement.parentNode as HTMLElement;
|
||||
// parentElement.parentNode?.removeChild(parentElement);
|
||||
|
||||
dispatch(setSelectedDocs(docs?.find((doc) => doc.name == 'default')));
|
||||
return getDocs();
|
||||
})
|
||||
.then((updatedDocs) => {
|
||||
dispatch(setSourceDocs(updatedDocs));
|
||||
dispatch(
|
||||
setSelectedDocs(
|
||||
updatedDocs?.find((doc) => doc.name.toLowerCase() === 'default'),
|
||||
),
|
||||
);
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user