From 502a7c87a5d83207ed3cc2cb6bdecc801289f26b Mon Sep 17 00:00:00 2001 From: lawvs <18554747+lawvs@users.noreply.github.com> Date: Tue, 26 Jul 2022 16:25:51 +0800 Subject: [PATCH] refactor(view): migrate group menu --- .../src/blocks/group/GroupMenu.tsx | 59 +++++-------------- .../src/blocks/group/GroupView.tsx | 18 +++--- 2 files changed, 23 insertions(+), 54 deletions(-) diff --git a/libs/components/editor-blocks/src/blocks/group/GroupMenu.tsx b/libs/components/editor-blocks/src/blocks/group/GroupMenu.tsx index 1d79daba9f..e7745d792f 100644 --- a/libs/components/editor-blocks/src/blocks/group/GroupMenu.tsx +++ b/libs/components/editor-blocks/src/blocks/group/GroupMenu.tsx @@ -3,8 +3,7 @@ import { mergeToPreviousGroup, RecastScene, RecastView, - useRecastBlockScene, - useRecastKanbanGroupBy, + useCurrentView, useRecastView, } from '@toeverything/components/editor-core'; import { @@ -29,7 +28,7 @@ import { GroupPanel } from './components/group-panel/GroupPanel'; import { IconButton } from './components/IconButton'; import { Line } from './components/Line'; import { Sorter } from './components/sorter'; -import { PANEL_CONFIG, SCENE_CONFIG } from './config'; +import { PANEL_CONFIG } from './config'; import type { ActivePanel } from './types'; const VIEW_ICON_MAP: Record = { @@ -39,14 +38,14 @@ const VIEW_ICON_MAP: Record = { }; const ViewsMenu = () => { - const { currentView, recastViews, changeView } = useRecastView(); + const { currentView, recastViews, setCurrentView } = useRecastView(); return ( <> {recastViews.map(view => ( changeView(view)} + onClick={() => setCurrentView(view)} > {VIEW_ICON_MAP[view.type]} {view.name} @@ -67,24 +66,21 @@ const GroupMenuWrapper = ({ }) => { /* feature flag: sprint14 close Filter、Sort feature */ const filterSorterFlag = useFlag('FilterSorter', false); - const { scene, setPage, setKanban, setTable } = useRecastBlockScene(); - const { groupBy } = useRecastKanbanGroupBy(); + const [currentView] = useCurrentView(); const theme = useTheme(); /* state: add active-style */ - const [activePanel, setActivePanel] = useState( + const [activePanel, setActivePanel] = useState( PANEL_CONFIG.GROUP_BY ); /* state: open panel */ - const [openPanel, setOpenPanel] = useState(null); + const [openPanel, setOpenPanel] = useState(null); /** * close panel state/active state */ const closePanel = () => { - if (!groupBy?.id) { - setActivePanel(null); - } + setActivePanel(null); setOpenPanel(null); }; @@ -108,21 +104,6 @@ const GroupMenuWrapper = ({ zIndex={theme.affine.zIndex.header - 1} content={ - - - Text View - - - - Kanban - - // ) - + Table } - + Calendar - + Timeline - + BI @@ -227,9 +196,9 @@ const GroupMenuWrapper = ({ ) } - {scene === RecastScene.Kanban && ( + {currentView.type === RecastScene.Kanban && ( onPanelChange(PANEL_CONFIG.GROUP_BY)} > diff --git a/libs/components/editor-blocks/src/blocks/group/GroupView.tsx b/libs/components/editor-blocks/src/blocks/group/GroupView.tsx index 3385dd0fe3..7955d28ac3 100644 --- a/libs/components/editor-blocks/src/blocks/group/GroupView.tsx +++ b/libs/components/editor-blocks/src/blocks/group/GroupView.tsx @@ -1,17 +1,17 @@ import { addNewGroup, RecastScene, + useCurrentView, useOnSelect, - useRecastBlockScene, } from '@toeverything/components/editor-core'; +import { styled } from '@toeverything/components/ui'; +import type { CreateView } from '@toeverything/framework/virgo'; +import type { ComponentType, FC } from 'react'; +import { useState } from 'react'; +import { GroupMenuWrapper } from './GroupMenu'; import { SceneKanban } from './scene-kanban'; import { ScenePage } from './ScenePage'; import { SceneTable } from './SceneTable'; -import { GroupMenuWrapper } from './GroupMenu'; -import { styled } from '@toeverything/components/ui'; -import { useState } from 'react'; -import type { FC, ComponentType } from 'react'; -import type { CreateView } from '@toeverything/framework/virgo'; const SceneMap: Record> = { page: ScenePage, @@ -78,7 +78,7 @@ const GroupContainer = styled('div')<{ isSelect?: boolean }>( export const GroupView: FC = props => { const { block, editor } = props; - const { scene } = useRecastBlockScene(); + const [currentView] = useCurrentView(); const [groupIsSelect, setGroupIsSelect] = useState(false); useOnSelect(block.id, (groupIsSelect: boolean) => { @@ -89,9 +89,9 @@ export const GroupView: FC = props => { addNewGroup(editor, block, true); }; - const View = SceneMap[scene]; + const View = SceneMap[currentView.type]; if (!View) { - return <>Group scene not found: {scene}!; + return <>Group scene not found: {currentView.type}!; } return (