diff --git a/packages/app/src/components/edgeless-toolbar/index.tsx b/packages/app/src/components/edgeless-toolbar/index.tsx index 0334b5a1f8..61eed107c5 100644 --- a/packages/app/src/components/edgeless-toolbar/index.tsx +++ b/packages/app/src/components/edgeless-toolbar/index.tsx @@ -1,3 +1,4 @@ +import { useState, useEffect } from 'react'; import { StyledEdgelessToolbar, StyledToolbarWrapper, @@ -70,8 +71,50 @@ const toolbarList2 = [ disable: false, }, ]; + +const UndoRedo = () => { + const [canUndo, setCanUndo] = useState(false); + const [canRedo, setCanRedo] = useState(false); + const { editor } = useEditor(); + useEffect(() => { + if (!editor) return; + const { store } = editor; + + store.signals.historyUpdated.on(() => { + setCanUndo(store.canUndo); + setCanRedo(store.canRedo); + }); + }, [editor]); + + return ( + + + { + editor?.store?.undo(); + }} + > + + + + + { + editor?.store?.redo(); + }} + > + + + + + ); +}; + export const EdgelessToolbar = () => { - const { mode, editor } = useEditor(); + const { mode } = useEditor(); + return ( { ); })} - - {toolbarList2.map(({ icon, toolTip, flavor, disable }, index) => { - return ( - - { - switch (flavor) { - case 'undo': - editor?.store?.undo(); - break; - case 'redo': - editor?.store?.redo(); - break; - } - }} - > - {icon} - - - ); - })} - + ); diff --git a/packages/app/src/components/edgeless-toolbar/style.ts b/packages/app/src/components/edgeless-toolbar/style.ts index e57a370beb..2cab9efc6f 100644 --- a/packages/app/src/components/edgeless-toolbar/style.ts +++ b/packages/app/src/components/edgeless-toolbar/style.ts @@ -20,22 +20,22 @@ export const StyledToolbarWrapper = styled.div(({ theme }) => ({ marginBottom: '12px', })); -export const StyledToolbarItem = styled.div<{ disable: boolean }>( - ({ theme, disable }) => ({ +export const StyledToolbarItem = styled.div<{ + disable?: boolean; +}>(({ theme, disable = false }) => ({ + width: '36px', + height: '36px', + ...displayFlex('center', 'center'), + color: disable ? '#C0C0C0' : theme.colors.iconColor, + cursor: 'pointer', + svg: { width: '36px', height: '36px', - ...displayFlex('center', 'center'), - color: disable ? '#C0C0C0' : theme.colors.iconColor, - cursor: 'pointer', - svg: { - width: '36px', - height: '36px', - }, - ':hover': disable - ? {} - : { - color: theme.colors.primaryColor, - background: theme.colors.hoverBackground, - }, - }) -); + }, + ':hover': disable + ? {} + : { + color: theme.colors.primaryColor, + background: theme.colors.hoverBackground, + }, +}));