mirror of
https://github.com/arc53/DocsGPT.git
synced 2025-11-29 16:43:16 +00:00
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
33 lines
813 B
TypeScript
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();
|
|
}, []);
|
|
}
|