diff --git a/frontend/src/Navigation.tsx b/frontend/src/Navigation.tsx index 3591469b..72c0d57a 100644 --- a/frontend/src/Navigation.tsx +++ b/frontend/src/Navigation.tsx @@ -145,7 +145,10 @@ export default function Navigation({ navOpen, setNavOpen }: NavigationProps) { dispatch(setSourceDocs(updatedDocs)); dispatch( setSelectedDocs( - updatedDocs?.find((doc) => doc.name.toLowerCase() === 'default'), + Array.isArray(updatedDocs) && + updatedDocs?.find( + (doc: Doc) => doc.name.toLowerCase() === 'default', + ), ), ); }) diff --git a/frontend/src/hooks/useDefaultDocument.ts b/frontend/src/hooks/useDefaultDocument.ts index 37374ce0..7f4b9812 100644 --- a/frontend/src/hooks/useDefaultDocument.ts +++ b/frontend/src/hooks/useDefaultDocument.ts @@ -17,11 +17,12 @@ export default function useDefaultDocument() { getDocs().then((data) => { dispatch(setSourceDocs(data)); if (!selectedDoc) - data?.forEach((doc: Doc) => { - if (doc.model && doc.name === 'default') { - dispatch(setSelectedDocs(doc)); - } - }); + Array.isArray(data) && + data?.forEach((doc: Doc) => { + if (doc.model && doc.name === 'default') { + dispatch(setSelectedDocs(doc)); + } + }); }); }; diff --git a/frontend/src/models/misc.ts b/frontend/src/models/misc.ts index 5478722c..3d5d908c 100644 --- a/frontend/src/models/misc.ts +++ b/frontend/src/models/misc.ts @@ -28,7 +28,6 @@ export type PromptProps = { }; export type DocumentsProps = { - documents: Doc[] | null; handleDeleteDocument: (index: number, document: Doc) => void; }; diff --git a/frontend/src/settings/Documents.tsx b/frontend/src/settings/Documents.tsx index fc21a8f1..ed7f2d89 100644 --- a/frontend/src/settings/Documents.tsx +++ b/frontend/src/settings/Documents.tsx @@ -33,13 +33,9 @@ const formatTokens = (tokens: number): string => { } }; -const Documents: React.FC = ({ - documents, - handleDeleteDocument, -}) => { +const Documents: React.FC = ({ handleDeleteDocument }) => { const { t } = useTranslation(); const dispatch = useDispatch(); - // State for search input const [searchTerm, setSearchTerm] = useState(''); // State for modal: active/inactive @@ -73,7 +69,6 @@ const Documents: React.FC = ({ pageNumber?: number, rows?: number, ) => { - console.log(`field: ${field}, pageNumber: ${pageNumber}, rows: ${rows}`); const page = pageNumber ?? currentPage; const rowsPerPg = rows ?? rowsPerPage; if (field !== undefined) { @@ -88,7 +83,6 @@ const Documents: React.FC = ({ } getDocs(sortField, sortOrder, page, rowsPerPg, true) .then((data) => { - console.log(data); dispatch(setSourceDocs(data ? data.docs : [])); setFetchedDocuments(data ? data.docs : []); setTotalPages(data ? data.totalPages : 0); @@ -114,9 +108,11 @@ const Documents: React.FC = ({ setLoading(false); }); }; + useEffect(() => { refreshDocs(sortField, currentPage, rowsPerPage); }, []); + return (
@@ -267,7 +263,7 @@ const Documents: React.FC = ({ }; 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..24ea2681 100644 --- a/frontend/src/settings/index.tsx +++ b/frontend/src/settings/index.tsx @@ -70,12 +70,7 @@ export default function Settings() { case t('settings.general.label'): return ; case t('settings.documents.label'): - return ( - - ); + return ; case 'Widgets': return ( 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.docs)) { + data.docs.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) =>