mirror of https://github.com/fantasticit/think.git
feat: improve data fetch
This commit is contained in:
parent
0c37cdf403
commit
fc335fbc1f
|
@ -142,7 +142,7 @@ export const toggleCollectDocument = (documentId, cookie = null): Promise<boolea
|
|||
* @returns
|
||||
*/
|
||||
export const useDocumentCollectToggle = (documentId) => {
|
||||
const { data, error, refetch } = useQuery(`${CollectorApiDefinition.check.client()}?documentId=${documentId}`, () =>
|
||||
const { data, error, refetch } = useQuery([CollectorApiDefinition.check.client(), documentId], () =>
|
||||
getDocumentIsCollected(documentId)
|
||||
);
|
||||
|
||||
|
|
|
@ -61,7 +61,7 @@ export const useUnreadMessages = () => {
|
|||
const { data, error, isLoading, refetch } = useQuery(
|
||||
[MessageApiDefinition.getUnread.client(), page],
|
||||
() => getMessagesApi('getUnread')(page),
|
||||
{ keepPreviousData: true, refetchInterval: 2000 }
|
||||
{ keepPreviousData: true, refetchInterval: 4000 }
|
||||
);
|
||||
|
||||
const readMessage = useCallback(
|
||||
|
|
|
@ -22,7 +22,7 @@ export const getPublicTemplates = (
|
|||
|
||||
export const usePublicTemplates = () => {
|
||||
const [page, setPage] = useState(1);
|
||||
const { data, error, isLoading } = useQuery(`${TemplateApiDefinition.public.client()}?page=${page}`, () =>
|
||||
const { data, error, isLoading } = useQuery([TemplateApiDefinition.public.client(), page], () =>
|
||||
getPublicTemplates(page)
|
||||
);
|
||||
|
||||
|
@ -62,7 +62,7 @@ export const useOwnTemplates = () => {
|
|||
error,
|
||||
isLoading,
|
||||
refetch: mutate,
|
||||
} = useQuery(`${TemplateApiDefinition.own.client()}?page=${page}`, () => getOwnTemplates(page));
|
||||
} = useQuery([TemplateApiDefinition.own.client(), page], () => getOwnTemplates(page));
|
||||
|
||||
const addTemplate = useCallback(
|
||||
async (data): Promise<ITemplate> => {
|
||||
|
|
|
@ -143,7 +143,7 @@ export const getAllPublicWikis = (
|
|||
*/
|
||||
export const useAllPublicWikis = () => {
|
||||
const [page, setPage] = useState(1);
|
||||
const { data, error, isLoading } = useQuery(`${WikiApiDefinition.getPublicWikis.client()}?page=${page}`, () =>
|
||||
const { data, error, isLoading } = useQuery([WikiApiDefinition.getPublicWikis.client(), page], () =>
|
||||
getAllPublicWikis(page)
|
||||
);
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ const Page: NextPage = () => {
|
|||
|
||||
Page.getInitialProps = async (ctx) => {
|
||||
const props = await serverPrefetcher(ctx, [
|
||||
{ url: `${WikiApiDefinition.getAllWikis.client()}?page=1`, action: (cookie) => getAllPublicWikis(1, cookie) },
|
||||
{ url: [WikiApiDefinition.getAllWikis.client(), 1], action: (cookie) => getAllPublicWikis(1, cookie) },
|
||||
]);
|
||||
return props;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue