mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 16:43:16 +00:00
fixing type error
This commit is contained in:
@@ -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',
|
||||
),
|
||||
),
|
||||
);
|
||||
})
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -28,7 +28,6 @@ export type PromptProps = {
|
||||
};
|
||||
|
||||
export type DocumentsProps = {
|
||||
documents: Doc[] | null;
|
||||
handleDeleteDocument: (index: number, document: Doc) => void;
|
||||
};
|
||||
|
||||
|
||||
@@ -33,13 +33,9 @@ const formatTokens = (tokens: number): string => {
|
||||
}
|
||||
};
|
||||
|
||||
const Documents: React.FC<DocumentsProps> = ({
|
||||
documents,
|
||||
handleDeleteDocument,
|
||||
}) => {
|
||||
const Documents: React.FC<DocumentsProps> = ({ 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<DocumentsProps> = ({
|
||||
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<DocumentsProps> = ({
|
||||
}
|
||||
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<DocumentsProps> = ({
|
||||
setLoading(false);
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
refreshDocs(sortField, currentPage, rowsPerPage);
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="mt-8">
|
||||
<div className="flex flex-col relative">
|
||||
@@ -267,7 +263,7 @@ const Documents: React.FC<DocumentsProps> = ({
|
||||
};
|
||||
|
||||
Documents.propTypes = {
|
||||
documents: PropTypes.array.isRequired,
|
||||
//documents: PropTypes.array.isRequired,
|
||||
handleDeleteDocument: PropTypes.func.isRequired,
|
||||
};
|
||||
|
||||
|
||||
@@ -70,12 +70,7 @@ export default function Settings() {
|
||||
case t('settings.general.label'):
|
||||
return <General />;
|
||||
case t('settings.documents.label'):
|
||||
return (
|
||||
<Documents
|
||||
documents={documents}
|
||||
handleDeleteDocument={handleDeleteClick}
|
||||
/>
|
||||
);
|
||||
return <Documents handleDeleteDocument={handleDeleteClick} />;
|
||||
case 'Widgets':
|
||||
return (
|
||||
<Widgets
|
||||
|
||||
@@ -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.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) =>
|
||||
|
||||
Reference in New Issue
Block a user