feat: improve data fetch

This commit is contained in:
fantasticit 2022-05-24 19:08:08 +08:00
parent 0c37cdf403
commit fc335fbc1f
5 changed files with 6 additions and 6 deletions

View File

@ -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)
);

View File

@ -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(

View File

@ -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> => {

View File

@ -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)
);

View File

@ -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;
};