mirror of
https://github.com/arc53/DocsGPT
synced 2024-11-19 21:25:39 +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:
parent
c6e804fa10
commit
7bc7b500f5
@ -27,6 +27,7 @@ import {
|
|||||||
selectConversationId,
|
selectConversationId,
|
||||||
selectModalStateDeleteConv,
|
selectModalStateDeleteConv,
|
||||||
setModalStateDeleteConv,
|
setModalStateDeleteConv,
|
||||||
|
setSourceDocs,
|
||||||
} from './preferences/preferenceSlice';
|
} from './preferences/preferenceSlice';
|
||||||
import {
|
import {
|
||||||
setConversation,
|
setConversation,
|
||||||
@ -34,7 +35,7 @@ import {
|
|||||||
} from './conversation/conversationSlice';
|
} from './conversation/conversationSlice';
|
||||||
import { useMediaQuery, useOutsideAlerter } from './hooks';
|
import { useMediaQuery, useOutsideAlerter } from './hooks';
|
||||||
import Upload from './upload/Upload';
|
import Upload from './upload/Upload';
|
||||||
import { Doc, getConversations } from './preferences/preferenceApi';
|
import { Doc, getConversations, getDocs } from './preferences/preferenceApi';
|
||||||
import SelectDocsModal from './preferences/SelectDocsModal';
|
import SelectDocsModal from './preferences/SelectDocsModal';
|
||||||
import ConversationTile from './conversation/ConversationTile';
|
import ConversationTile from './conversation/ConversationTile';
|
||||||
import { useDarkTheme } from './hooks';
|
import { useDarkTheme } from './hooks';
|
||||||
@ -124,21 +125,29 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) {
|
|||||||
.catch((error) => console.error(error));
|
.catch((error) => console.error(error));
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleDeleteClick = (index: number, doc: Doc) => {
|
const handleDeleteClick = (doc: Doc) => {
|
||||||
const docPath = 'indexes/' + 'local' + '/' + doc.name;
|
const docPath = `indexes/local/${doc.name}`;
|
||||||
|
|
||||||
fetch(`${apiHost}/api/delete_old?path=${docPath}`, {
|
fetch(`${apiHost}/api/delete_old?path=${docPath}`, {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
// remove the image element from the DOM
|
// remove the image element from the DOM
|
||||||
const imageElement = document.querySelector(
|
// const imageElement = document.querySelector(
|
||||||
`#img-${index}`,
|
// `#img-${index}`,
|
||||||
) as HTMLElement;
|
// ) as HTMLElement;
|
||||||
const parentElement = imageElement.parentNode as HTMLElement;
|
// const parentElement = imageElement.parentNode as HTMLElement;
|
||||||
parentElement.parentNode?.removeChild(parentElement);
|
// 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));
|
.catch((error) => console.error(error));
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user