Files
DocsGPT/frontend/src/hooks/useDefaultDocument.ts
fadingNA 5debb48265 Paginated With MongoDB / Create New Endpoint
change routes /combine name, add route /api/source/paginated
add new endpoint source/paginated
fixing table responsive
create new function to handling api/source/paginated
2024-11-09 02:09:01 -05:00

33 lines
813 B
TypeScript

import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { getDocs } from '../preferences/preferenceApi';
import { Doc } from '../models/misc';
import {
selectSelectedDocs,
setSelectedDocs,
setSourceDocs,
} from '../preferences/preferenceSlice';
export default function useDefaultDocument() {
const dispatch = useDispatch();
const selectedDoc = useSelector(selectSelectedDocs);
const fetchDocs = () => {
getDocs().then((data) => {
dispatch(setSourceDocs(data));
if (!selectedDoc)
Array.isArray(data) &&
data?.forEach((doc: Doc) => {
if (doc.model && doc.name === 'default') {
dispatch(setSelectedDocs(doc));
}
});
});
};
React.useEffect(() => {
fetchDocs();
}, []);
}