client: refresh templates when mount

This commit is contained in:
fantasticit 2022-05-31 22:23:31 +08:00
parent 663096dc17
commit 68c2f8ecc5
2 changed files with 9 additions and 4 deletions

View File

@ -2,7 +2,7 @@ import { List, Pagination } from '@douyinfe/semi-ui';
import { DataRender } from 'components/data-render'; import { DataRender } from 'components/data-render';
import { Empty } from 'components/empty'; import { Empty } from 'components/empty';
import { IProps as ITemplateCardProps, TemplateCard, TemplateCardPlaceholder } from 'components/template/card'; import { IProps as ITemplateCardProps, TemplateCard, TemplateCardPlaceholder } from 'components/template/card';
import React, { useMemo, useState } from 'react'; import React, { useEffect, useMemo, useState } from 'react';
const grid = { const grid = {
gutter: 16, gutter: 16,
@ -29,8 +29,7 @@ export const TemplateList: React.FC<IProps> = ({
onClosePreview, onClosePreview,
pageSize = 5, pageSize = 5,
}) => { }) => {
const { data, loading, error } = hook(); const { data, loading, error, refresh } = hook();
const [page, onPageChange] = useState(1); const [page, onPageChange] = useState(1);
const arr = useMemo(() => { const arr = useMemo(() => {
@ -40,6 +39,10 @@ export const TemplateList: React.FC<IProps> = ({
return arr.slice(start, end); return arr.slice(start, end);
}, [data, page, pageSize]); }, [data, page, pageSize]);
useEffect(() => {
refresh();
}, [refresh]);
return ( return (
<DataRender <DataRender
loading={loading} loading={loading}

View File

@ -22,7 +22,7 @@ export const getPublicTemplates = (
export const usePublicTemplates = () => { export const usePublicTemplates = () => {
const [page, setPage] = useState(1); const [page, setPage] = useState(1);
const { data, error, isLoading } = useQuery([TemplateApiDefinition.public.client(), page], () => const { data, error, isLoading, refetch } = useQuery([TemplateApiDefinition.public.client(), page], () =>
getPublicTemplates(page) getPublicTemplates(page)
); );
@ -31,6 +31,7 @@ export const usePublicTemplates = () => {
loading: isLoading, loading: isLoading,
error, error,
setPage, setPage,
refresh: refetch,
}; };
}; };
@ -79,6 +80,7 @@ export const useOwnTemplates = () => {
error, error,
setPage, setPage,
addTemplate, addTemplate,
refresh: mutate,
}; };
}; };