client: improve component render time

This commit is contained in:
fantasticit 2022-05-25 10:09:30 +08:00
parent 5e6f283032
commit d1f51707a8
3 changed files with 39 additions and 34 deletions

View File

@ -1,5 +1,5 @@
import { IconArticle, IconChevronLeft } from '@douyinfe/semi-icons'; import { IconChevronLeft } from '@douyinfe/semi-icons';
import { Button, Nav, Popover, Skeleton, Space, Spin, Tooltip, Typography } from '@douyinfe/semi-ui'; import { Button, Nav, Skeleton, Space, Spin, Tooltip, Typography } from '@douyinfe/semi-ui';
import { DataRender } from 'components/data-render'; import { DataRender } from 'components/data-render';
import { Divider } from 'components/divider'; import { Divider } from 'components/divider';
import { DocumentCollaboration } from 'components/document/collaboration'; import { DocumentCollaboration } from 'components/document/collaboration';
@ -50,7 +50,9 @@ export const DocumentEditor: React.FC<IProps> = ({ documentId }) => {
}); });
}, [document, documentId]); }, [document, documentId]);
const actions = ( const actions = useMemo(
() =>
docAuthLoading ? null : (
<Space> <Space>
{document && authority.readable && ( {document && authority.readable && (
<DocumentCollaboration key="collaboration" wikiId={document.wikiId} documentId={documentId} /> <DocumentCollaboration key="collaboration" wikiId={document.wikiId} documentId={documentId} />
@ -60,6 +62,8 @@ export const DocumentEditor: React.FC<IProps> = ({ documentId }) => {
<DocumentStar key="star" documentId={documentId} /> <DocumentStar key="star" documentId={documentId} />
<DocumentStyle /> <DocumentStyle />
</Space> </Space>
),
[docAuthLoading, documentId, document, authority]
); );
useEffect(() => { useEffect(() => {

View File

@ -76,7 +76,8 @@ export const DocumentReader: React.FC<IProps> = ({ documentId }) => {
}, [document]); }, [document]);
const actions = useMemo( const actions = useMemo(
() => ( () =>
docAuthLoading ? null : (
<Space> <Space>
{document && authority.readable && ( {document && authority.readable && (
<DocumentCollaboration key="collaboration" wikiId={document.wikiId} documentId={documentId} /> <DocumentCollaboration key="collaboration" wikiId={document.wikiId} documentId={documentId} />
@ -96,7 +97,7 @@ export const DocumentReader: React.FC<IProps> = ({ documentId }) => {
<DocumentStyle /> <DocumentStyle />
</Space> </Space>
), ),
[document, documentId, authority, gotoEdit] [docAuthLoading, document, documentId, authority, gotoEdit]
); );
const editBtnStyle = useMemo(() => getEditBtnStyle(isMobile ? 16 : 100), [isMobile]); const editBtnStyle = useMemo(() => getEditBtnStyle(isMobile ? 16 : 100), [isMobile]);

View File

@ -263,7 +263,7 @@ export const useWikiTocs = (wikiId) => {
const { data, error, refetch } = useQuery( const { data, error, refetch } = useQuery(
WikiApiDefinition.getTocsById.client(wikiId), WikiApiDefinition.getTocsById.client(wikiId),
() => (wikiId ? getWikiTocs(wikiId) : null), () => (wikiId ? getWikiTocs(wikiId) : null),
{ staleTime: 3000 } { staleTime: 2000 }
); );
const loading = !data && !error; const loading = !data && !error;