From eef782f09676046fb031df195309fdf7a5d38fcd Mon Sep 17 00:00:00 2001 From: fantasticit Date: Fri, 27 May 2022 21:41:03 +0800 Subject: [PATCH] client: optimize render actions --- .../src/components/document/actions/index.tsx | 98 ++++++++++++------- .../src/components/document/delete/index.tsx | 65 ++++++------ .../src/components/document/link/index.tsx | 19 ++-- 3 files changed, 115 insertions(+), 67 deletions(-) diff --git a/packages/client/src/components/document/actions/index.tsx b/packages/client/src/components/document/actions/index.tsx index abee6b1b..a7573cde 100644 --- a/packages/client/src/components/document/actions/index.tsx +++ b/packages/client/src/components/document/actions/index.tsx @@ -1,5 +1,5 @@ import { IconMore, IconPlus, IconStar } from '@douyinfe/semi-icons'; -import { Button, Dropdown, Space, Typography } from '@douyinfe/semi-ui'; +import { Button, Dropdown, Popover, Space, Typography } from '@douyinfe/semi-ui'; import { DocumentCreator } from 'components/document/create'; import { DocumentDeletor } from 'components/document/delete'; import { DocumentLinkCopyer } from 'components/document/link'; @@ -29,22 +29,40 @@ export const DocumentActions: React.FC = ({ showCreateDocument, children, }) => { - const [visible, toggleVisible] = useToggle(false); + const [popoverVisible, togglePopoverVisible] = useToggle(false); + const [createVisible, toggleCreateVisible] = useToggle(false); - const prevent = useCallback((e) => { - e.preventDefault(); - e.stopPropagation(); - }, []); + const create = useCallback(() => { + togglePopoverVisible(false); + toggleCreateVisible(true); + }, [togglePopoverVisible, toggleCreateVisible]); + + const wrapedOnDelete = useCallback(() => { + togglePopoverVisible(false); + onDelete && onDelete(); + }, [onDelete, togglePopoverVisible]); + + const wrapOnVisibleChange = useCallback( + (visible) => { + togglePopoverVisible(visible); + onVisibleChange && onVisibleChange(); + }, + [onVisibleChange, togglePopoverVisible] + ); return ( <> - {showCreateDocument && ( - - + + 新建子文档 @@ -52,15 +70,16 @@ export const DocumentActions: React.FC = ({ )} - - ( - { - toggleStar().then(onStar); - }} - > + + ( + { + toggleStar().then(onStar); + }} + > + = ({ {text} - )} - /> - - - - + + )} + /> + + { + return {children}; + }} + /> + - - - + + { + return {children}; + }} + /> } > - {children ||