| {document.name} |
{document.date} |
@@ -173,7 +215,7 @@ const Documents: React.FC = ({
{document.type === 'remote' ? 'Pre-loaded' : 'Private'}
|
-
+
{document.type !== 'remote' && (
 = ({
)}
+ {/* Pagination component with props:
+ # Note: Every time the page changes,
+ the refreshDocs function is called with the updated page number and rows per page.
+ and reset cursor paginated query parameter to undefined.
+ */}
+ {
+ setCurrentPage(page);
+ refreshDocs(sortField, page, rowsPerPage);
+ }}
+ onRowsPerPageChange={(rows) => {
+ setRowsPerPage(rows);
+ setCurrentPage(1);
+ refreshDocs(sortField, 1, rows);
+ }}
+ />
);
};
Documents.propTypes = {
- documents: PropTypes.array.isRequired,
+ //documents: PropTypes.array.isRequired,
handleDeleteDocument: PropTypes.func.isRequired,
};
diff --git a/frontend/src/settings/index.tsx b/frontend/src/settings/index.tsx
index ea3d4428..15c7ce08 100644
--- a/frontend/src/settings/index.tsx
+++ b/frontend/src/settings/index.tsx
@@ -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));
@@ -72,7 +83,7 @@ export default function Settings() {
case t('settings.documents.label'):
return (
);
diff --git a/frontend/src/store.ts b/frontend/src/store.ts
index 5843d493..8f426ed6 100644
--- a/frontend/src/store.ts
+++ b/frontend/src/store.ts
@@ -38,6 +38,7 @@ const preloadedState: { preference: Preference } = {
},
],
modalState: 'INACTIVE',
+ paginatedDocuments: null,
},
};
const store = configureStore({
diff --git a/frontend/src/upload/Upload.tsx b/frontend/src/upload/Upload.tsx
index 81ce9f2b..4fee88f6 100644
--- a/frontend/src/upload/Upload.tsx
+++ b/frontend/src/upload/Upload.tsx
@@ -166,7 +166,10 @@ function Upload({
dispatch(setSourceDocs(data));
dispatch(
setSelectedDocs(
- data?.find((d) => d.type?.toLowerCase() === 'local'),
+ Array.isArray(data) &&
+ data?.find(
+ (d: Doc) => d.type?.toLowerCase() === 'local',
+ ),
),
);
});
@@ -182,15 +185,21 @@ function Upload({
getDocs().then((data) => {
dispatch(setSourceDocs(data));
const docIds = new Set(
- sourceDocs?.map((doc: Doc) => (doc.id ? doc.id : null)),
+ (Array.isArray(sourceDocs) &&
+ sourceDocs?.map((doc: Doc) =>
+ doc.id ? doc.id : null,
+ )) ||
+ [],
);
- data?.map((updatedDoc: Doc) => {
- if (updatedDoc.id && !docIds.has(updatedDoc.id)) {
- //select the doc not present in the intersection of current Docs and fetched data
- dispatch(setSelectedDocs(updatedDoc));
- return;
- }
- });
+ if (data && Array.isArray(data)) {
+ data.map((updatedDoc: Doc) => {
+ if (updatedDoc.id && !docIds.has(updatedDoc.id)) {
+ // Select the doc not present in the intersection of current Docs and fetched data
+ dispatch(setSelectedDocs(updatedDoc));
+ return;
+ }
+ });
+ }
});
setProgress(
(progress) =>
@@ -351,32 +360,32 @@ function Upload({
} else {
view = (
-
+
{t('modals.uploadDoc.label')}
{!activeTab && (
-
+
{t('modals.uploadDoc.select')}
|