fix: remove pageMode from pageMeta (#1647)

This commit is contained in:
Himself65
2023-03-21 19:45:54 -05:00
committed by GitHub
parent e7d6bda7a5
commit 45260543e1
7 changed files with 40 additions and 27 deletions

View File

@@ -19,9 +19,11 @@ import {
useTheme as useMuiTheme,
useTheme,
} from '@mui/material';
import { useAtomValue } from 'jotai';
import type React from 'react';
import { useMemo } from 'react';
import { workspacePreferredModeAtom } from '../../../../atoms';
import {
usePageMeta,
usePageMetaHelper,
@@ -102,6 +104,7 @@ export const PageList: React.FC<PageListProps> = ({
const theme = useMuiTheme();
const matches = useMediaQuery(theme.breakpoints.up('sm'));
const isTrash = listType === 'trash';
const record = useAtomValue(workspacePreferredModeAtom);
const list = useMemo(
() => pageList.filter(filter[listType ?? 'all']),
[pageList, listType]
@@ -141,7 +144,7 @@ export const PageList: React.FC<PageListProps> = ({
>
<StyledTitleWrapper>
<StyledTitleLink>
{pageMeta.mode === 'edgeless' ? (
{record[pageMeta.id] === 'edgeless' ? (
<EdgelessIcon />
) : (
<PageIcon />

View File

@@ -1,11 +1,10 @@
import { toast } from '@affine/component';
import { assertExists } from '@blocksuite/store';
import { useAtomValue, useSetAtom } from 'jotai';
import type { CSSProperties } from 'react';
import {
usePageMeta,
usePageMetaHelper,
} from '../../../../hooks/use-page-meta';
import { workspacePreferredModeAtom } from '../../../../atoms';
import { usePageMeta } from '../../../../hooks/use-page-meta';
import type { BlockSuiteWorkspace } from '../../../../shared';
import { StyledEditorModeSwitch } from './style';
import { EdgelessSwitchItem, PageSwitchItem } from './switch-items';
@@ -22,34 +21,36 @@ export const EditorModeSwitch = ({
blockSuiteWorkspace,
pageId,
}: EditorModeSwitchProps) => {
const { setPageMeta } = usePageMetaHelper(blockSuiteWorkspace);
const currentMode =
useAtomValue(workspacePreferredModeAtom)[pageId] ?? 'page';
const setMode = useSetAtom(workspacePreferredModeAtom);
const pageMeta = usePageMeta(blockSuiteWorkspace).find(
meta => meta.id === pageId
);
assertExists(pageMeta);
const { trash, mode = 'page' } = pageMeta;
const { trash } = pageMeta;
return (
<StyledEditorModeSwitch
style={style}
switchLeft={mode === 'page'}
switchLeft={currentMode === 'page'}
showAlone={trash}
>
<PageSwitchItem
data-testid="switch-page-mode-button"
active={mode === 'page'}
hide={trash && mode !== 'page'}
active={currentMode === 'page'}
hide={trash && currentMode !== 'page'}
onClick={() => {
setPageMeta(pageId, { mode: 'page' });
setMode(mode => ({ ...mode, [pageMeta.id]: 'page' }));
toast('Page mode');
}}
/>
<EdgelessSwitchItem
data-testid="switch-edgeless-mode-button"
active={mode === 'edgeless'}
hide={trash && mode !== 'edgeless'}
active={currentMode === 'edgeless'}
hide={trash && currentMode !== 'edgeless'}
onClick={() => {
setPageMeta(pageId, { mode: 'edgeless' });
setMode(mode => ({ ...mode, [pageMeta.id]: 'edgeless' }));
toast('Edgeless mode');
}}
/>