refactor: mode atom (#3221)

This commit is contained in:
Alex Yang 2023-07-13 23:11:00 +08:00 committed by GitHub
parent d18df12951
commit 492852ba0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 22 deletions

View File

@ -0,0 +1,12 @@
import { currentPageIdAtom } from '@toeverything/plugin-infra/manager';
import { atom } from 'jotai/vanilla';
import { pageSettingFamily } from './index';
export const currentModeAtom = atom<'page' | 'edgeless'>(get => {
const pageId = get(currentPageIdAtom);
if (!pageId) {
return 'page';
}
return get(pageSettingFamily(pageId)).mode;
});

View File

@ -23,7 +23,7 @@ import {
import { guideDownloadClientTipAtom } from '../../../atoms/guide';
import { contentLayoutAtom } from '../../../atoms/layout';
import { useCurrentMode } from '../../../hooks/current/use-current-mode';
import { currentModeAtom } from '../../../atoms/mode';
import type { AffineOfficialWorkspace } from '../../../shared';
import { DownloadClientTip } from './download-tips';
import EditPage from './header-right-items/edit-page';
@ -205,7 +205,7 @@ export const Header = forwardRef<
const open = useAtomValue(appSidebarOpenAtom);
const appSidebarFloating = useAtomValue(appSidebarFloatingAtom);
const mode = useCurrentMode();
const mode = useAtomValue(currentModeAtom);
return (
<div

View File

@ -1,11 +1,12 @@
import { MuiFade, Tooltip } from '@affine/component';
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { CloseIcon, NewIcon, UserGuideIcon } from '@blocksuite/icons';
import { useSetAtom } from 'jotai';
import { useSetAtom } from 'jotai/react';
import { useAtomValue } from 'jotai/react';
import { useCallback, useState } from 'react';
import { openOnboardingModalAtom, openSettingModalAtom } from '../../../atoms';
import { useCurrentMode } from '../../../hooks/current/use-current-mode';
import { currentModeAtom } from '../../../atoms/mode';
import { ShortcutsModal } from '../shortcuts-modal';
import { ContactIcon, HelpIcon, KeyboardIcon } from './icons';
import {
@ -27,7 +28,7 @@ export const HelpIsland = ({
}: {
showList?: IslandItemNames[];
}) => {
const mode = useCurrentMode();
const mode = useAtomValue(currentModeAtom);
const setOpenOnboarding = useSetAtom(openOnboardingModalAtom);
const setOpenSettingModalAtom = useSetAtom(openSettingModalAtom);
const [spread, setShowSpread] = useState(false);

View File

@ -1,17 +0,0 @@
import { currentPageIdAtom } from '@toeverything/plugin-infra/manager';
import { atom, useAtomValue } from 'jotai';
import { pageSettingFamily } from '../../atoms';
const currentModeAtom = atom<'page' | 'edgeless'>(get => {
const pageId = get(currentPageIdAtom);
// fixme(himself65): pageId should not be null
if (!pageId) {
return 'page';
}
return get(pageSettingFamily(pageId))?.mode ?? 'page';
});
export const useCurrentMode = () => {
return useAtomValue(currentModeAtom);
};