mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-12-01 09:33:14 +00:00
fix remove button on navigation sidebar and setting/document
This commit is contained in:
@@ -8,6 +8,8 @@ import i18n from '../locale/i18n';
|
||||
import { Doc } from '../models/misc';
|
||||
import {
|
||||
selectSourceDocs,
|
||||
selectPaginatedDocuments,
|
||||
setPaginatedDocuments,
|
||||
setSourceDocs,
|
||||
} from '../preferences/preferenceSlice';
|
||||
import Analytics from './Analytics';
|
||||
@@ -26,20 +28,29 @@ export default function Settings() {
|
||||
);
|
||||
|
||||
const documents = useSelector(selectSourceDocs);
|
||||
const paginatedDocuments = useSelector(selectPaginatedDocuments);
|
||||
const updateWidgetScreenshot = (screenshot: File | null) => {
|
||||
setWidgetScreenshot(screenshot);
|
||||
};
|
||||
|
||||
const updateDocumentsList = (documents: Doc[], index: number) => [
|
||||
...documents.slice(0, index),
|
||||
...documents.slice(index + 1),
|
||||
];
|
||||
|
||||
const handleDeleteClick = (index: number, doc: Doc) => {
|
||||
userService
|
||||
.deletePath(doc.id ?? '')
|
||||
.then((response) => {
|
||||
if (response.ok && documents) {
|
||||
const updatedDocuments = [
|
||||
...documents.slice(0, index),
|
||||
...documents.slice(index + 1),
|
||||
];
|
||||
dispatch(setSourceDocs(updatedDocuments));
|
||||
if (paginatedDocuments) {
|
||||
dispatch(
|
||||
setPaginatedDocuments(
|
||||
updateDocumentsList(paginatedDocuments, index),
|
||||
),
|
||||
);
|
||||
}
|
||||
dispatch(setSourceDocs(updateDocumentsList(documents, index)));
|
||||
}
|
||||
})
|
||||
.catch((error) => console.error(error));
|
||||
@@ -70,7 +81,12 @@ export default function Settings() {
|
||||
case t('settings.general.label'):
|
||||
return <General />;
|
||||
case t('settings.documents.label'):
|
||||
return <Documents handleDeleteDocument={handleDeleteClick} />;
|
||||
return (
|
||||
<Documents
|
||||
paginatedDocuments={paginatedDocuments}
|
||||
handleDeleteDocument={handleDeleteClick}
|
||||
/>
|
||||
);
|
||||
case 'Widgets':
|
||||
return (
|
||||
<Widgets
|
||||
|
||||
Reference in New Issue
Block a user