refactor(web): move current atoms into plugin infra (#3220)

This commit is contained in:
Alex Yang
2023-07-13 20:14:30 +08:00
committed by GitHub
parent 0230cea16e
commit 64cf297399
13 changed files with 91 additions and 98 deletions
@@ -1,10 +1,10 @@
import { rootCurrentPageIdAtom } from '@affine/workspace/atom';
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(rootCurrentPageIdAtom);
const pageId = get(currentPageIdAtom);
// fixme(himself65): pageId should not be null
if (!pageId) {
return 'page';
@@ -1,12 +0,0 @@
import { rootCurrentPageIdAtom } from '@affine/workspace/atom';
import { useAtom } from 'jotai';
/**
* @deprecated Use `rootCurrentPageIdAtom` directly instead.
*/
export function useCurrentPageId(): [
string | null,
(newId: string | null) => void,
] {
return useAtom(rootCurrentPageIdAtom);
}
@@ -1,8 +1,8 @@
import {
rootCurrentPageIdAtom,
rootCurrentWorkspaceIdAtom,
} from '@affine/workspace/atom';
import { assertExists } from '@blocksuite/global/utils';
import {
currentPageIdAtom,
currentWorkspaceIdAtom,
} from '@toeverything/plugin-infra/manager';
import { useAtom, useSetAtom } from 'jotai';
import { useCallback, useEffect } from 'react';
@@ -24,7 +24,7 @@ export function useCurrentWorkspace(): [
AllWorkspace,
(id: string | null) => void,
] {
const [id, setId] = useAtom(rootCurrentWorkspaceIdAtom);
const [id, setId] = useAtom(currentWorkspaceIdAtom);
assertExists(id);
const currentWorkspace = useWorkspace(id);
useEffect(() => {
@@ -35,7 +35,7 @@ export function useCurrentWorkspace(): [
})
);
}, [currentWorkspace]);
const setPageId = useSetAtom(rootCurrentPageIdAtom);
const setPageId = useSetAtom(currentPageIdAtom);
return [
currentWorkspace,
useCallback(
@@ -1,6 +1,6 @@
import type { WorkspaceRegistry } from '@affine/env/workspace';
import type { WorkspaceFlavour } from '@affine/env/workspace';
import { rootCurrentWorkspaceIdAtom } from '@affine/workspace/atom';
import { currentPageIdAtom } from '@toeverything/plugin-infra/manager';
import { useSetAtom } from 'jotai';
import { useCallback } from 'react';
@@ -8,7 +8,7 @@ import { useTransformWorkspace } from '../use-transform-workspace';
export function useOnTransformWorkspace() {
const transformWorkspace = useTransformWorkspace();
const setWorkspaceId = useSetAtom(rootCurrentWorkspaceIdAtom);
const setWorkspaceId = useSetAtom(currentPageIdAtom);
return useCallback(
async <From extends WorkspaceFlavour, To extends WorkspaceFlavour>(
from: From,