mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-11-22 09:13:18 +03:00
refactor: remove deprecated atoms (#2615)
This commit is contained in:
parent
ee289706ec
commit
06abb702f5
@ -1,11 +1,6 @@
|
||||
import { DebugLogger } from '@affine/debug';
|
||||
import type { RootWorkspaceMetadata } from '@affine/workspace/atom';
|
||||
import {
|
||||
rootCurrentEditorAtom,
|
||||
rootCurrentPageIdAtom,
|
||||
rootCurrentWorkspaceIdAtom,
|
||||
rootWorkspacesMetadataAtom,
|
||||
} from '@affine/workspace/atom';
|
||||
import { rootWorkspacesMetadataAtom } from '@affine/workspace/atom';
|
||||
import { WorkspaceFlavour } from '@affine/workspace/type';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import { atom } from 'jotai';
|
||||
@ -17,11 +12,6 @@ import type { CreateWorkspaceMode } from '../components/affine/create-workspace-
|
||||
const logger = new DebugLogger('web:atoms');
|
||||
|
||||
// workspace necessary atoms
|
||||
/**
|
||||
* @deprecated Use `rootCurrentWorkspaceIdAtom` directly instead.
|
||||
*/
|
||||
export const currentWorkspaceIdAtom = rootCurrentWorkspaceIdAtom;
|
||||
|
||||
// todo(himself65): move this to the workspace package
|
||||
rootWorkspacesMetadataAtom.onMount = setAtom => {
|
||||
function createFirst(): RootWorkspaceMetadata[] {
|
||||
@ -81,15 +71,6 @@ rootWorkspacesMetadataAtom.onMount = setAtom => {
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* @deprecated Use `rootCurrentPageIdAtom` directly instead.
|
||||
*/
|
||||
export const currentPageIdAtom = rootCurrentPageIdAtom;
|
||||
/**
|
||||
* @deprecated Use `rootCurrentEditorAtom` directly instead.
|
||||
*/
|
||||
export const currentEditorAtom = rootCurrentEditorAtom;
|
||||
|
||||
// modal atoms
|
||||
export const openWorkspacesModalAtom = atom(false);
|
||||
export const openCreateWorkspaceModalAtom = atom<CreateWorkspaceMode>(false);
|
||||
|
@ -1,6 +1,7 @@
|
||||
import './page-detail-editor.css';
|
||||
|
||||
import { PageNotFoundError, Unreachable } from '@affine/env/constant';
|
||||
import { rootCurrentEditorAtom } from '@affine/workspace/atom';
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import { assertExists } from '@blocksuite/store';
|
||||
@ -23,7 +24,7 @@ import React, {
|
||||
} from 'react';
|
||||
import type { MosaicNode } from 'react-mosaic-component';
|
||||
|
||||
import { currentEditorAtom, workspacePreferredModeAtom } from '../atoms';
|
||||
import { workspacePreferredModeAtom } from '../atoms';
|
||||
import { contentLayoutAtom } from '../atoms/layout';
|
||||
import type { AffineOfficialWorkspace } from '../shared';
|
||||
import { BlockSuiteEditor as Editor } from './blocksuite/block-suite-editor';
|
||||
@ -59,7 +60,7 @@ const EditorWrapper = memo(function EditorWrapper({
|
||||
);
|
||||
const currentMode =
|
||||
useAtomValue(workspacePreferredModeAtom)[pageId] ?? 'page';
|
||||
const setEditor = useSetAtom(currentEditorAtom);
|
||||
const setEditor = useSetAtom(rootCurrentEditorAtom);
|
||||
assertExists(meta);
|
||||
return (
|
||||
<Editor
|
||||
|
@ -23,11 +23,9 @@ import type React from 'react';
|
||||
import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import { workspacesAtom } from '../../atoms';
|
||||
import { rootCurrentWorkspaceAtom } from '../../atoms/root';
|
||||
import { BlockSuiteWorkspace } from '../../shared';
|
||||
import {
|
||||
currentWorkspaceAtom,
|
||||
useCurrentWorkspace,
|
||||
} from '../current/use-current-workspace';
|
||||
import { useCurrentWorkspace } from '../current/use-current-workspace';
|
||||
import { useAppHelper, useWorkspaces } from '../use-workspaces';
|
||||
|
||||
vi.mock(
|
||||
@ -169,7 +167,7 @@ describe('useWorkspacesHelper', () => {
|
||||
wrapper: ProviderWrapper,
|
||||
});
|
||||
store.set(rootCurrentWorkspaceIdAtom, workspacesHook.result.current[1].id);
|
||||
await store.get(currentWorkspaceAtom);
|
||||
await store.get(rootCurrentWorkspaceAtom);
|
||||
const currentWorkspaceHook = renderHook(() => useCurrentWorkspace(), {
|
||||
wrapper: ProviderWrapper,
|
||||
});
|
||||
|
@ -20,11 +20,9 @@ import { beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
|
||||
|
||||
import { LocalAdapter } from '../../adapters/local';
|
||||
import { workspacesAtom } from '../../atoms';
|
||||
import { rootCurrentWorkspaceAtom } from '../../atoms/root';
|
||||
import { BlockSuiteWorkspace } from '../../shared';
|
||||
import {
|
||||
currentWorkspaceAtom,
|
||||
useCurrentWorkspace,
|
||||
} from '../current/use-current-workspace';
|
||||
import { useCurrentWorkspace } from '../current/use-current-workspace';
|
||||
import {
|
||||
useRecentlyViewed,
|
||||
useSyncRecentViewsWithRouter,
|
||||
@ -98,14 +96,14 @@ describe('useRecentlyViewed', () => {
|
||||
providers: [],
|
||||
} satisfies LocalWorkspace);
|
||||
store.set(rootCurrentWorkspaceIdAtom, blockSuiteWorkspace.id);
|
||||
const workspace = await store.get(currentWorkspaceAtom);
|
||||
const workspace = await store.get(rootCurrentWorkspaceAtom);
|
||||
expect(workspace?.id).toBe(blockSuiteWorkspace.id);
|
||||
const currentHook = renderHook(() => useCurrentWorkspace(), {
|
||||
wrapper: ProviderWrapper,
|
||||
});
|
||||
expect(currentHook.result.current[0]?.id).toEqual(workspaceId);
|
||||
store.set(rootCurrentWorkspaceIdAtom, blockSuiteWorkspace.id);
|
||||
await store.get(currentWorkspaceAtom);
|
||||
await store.get(rootCurrentWorkspaceAtom);
|
||||
const recentlyViewedHook = renderHook(() => useRecentlyViewed(), {
|
||||
wrapper: ProviderWrapper,
|
||||
});
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { rootCurrentPageIdAtom } from '@affine/workspace/atom';
|
||||
import { atom, useAtomValue } from 'jotai';
|
||||
|
||||
import { currentPageIdAtom, workspacePreferredModeAtom } from '../../atoms';
|
||||
import { workspacePreferredModeAtom } from '../../atoms';
|
||||
|
||||
const currentModeAtom = atom<'page' | 'edgeless'>(get => {
|
||||
const pageId = get(currentPageIdAtom);
|
||||
const pageId = get(rootCurrentPageIdAtom);
|
||||
const record = get(workspacePreferredModeAtom);
|
||||
if (pageId) return record[pageId] ?? 'page';
|
||||
else {
|
||||
|
@ -1,22 +1,20 @@
|
||||
import {
|
||||
rootCurrentPageIdAtom,
|
||||
rootCurrentWorkspaceIdAtom,
|
||||
} from '@affine/workspace/atom';
|
||||
import { useAtom, useAtomValue } from 'jotai';
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { currentPageIdAtom, currentWorkspaceIdAtom } from '../../atoms';
|
||||
import { rootCurrentWorkspaceAtom } from '../../atoms/root';
|
||||
import type { AllWorkspace } from '../../shared';
|
||||
|
||||
/**
|
||||
* @deprecated use `rootCurrentWorkspaceAtom` instead
|
||||
*/
|
||||
export const currentWorkspaceAtom = rootCurrentWorkspaceAtom;
|
||||
|
||||
export function useCurrentWorkspace(): [
|
||||
AllWorkspace,
|
||||
(id: string | null) => void
|
||||
] {
|
||||
const currentWorkspace = useAtomValue(rootCurrentWorkspaceAtom);
|
||||
const [, setId] = useAtom(currentWorkspaceIdAtom);
|
||||
const [, setPageId] = useAtom(currentPageIdAtom);
|
||||
const [, setId] = useAtom(rootCurrentWorkspaceIdAtom);
|
||||
const [, setPageId] = useAtom(rootCurrentPageIdAtom);
|
||||
return [
|
||||
currentWorkspace,
|
||||
useCallback(
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { Breadcrumbs, IconButton, ListSkeleton } from '@affine/component';
|
||||
import { StyledTableContainer } from '@affine/component/page-list';
|
||||
import { QueryParamError } from '@affine/env/constant';
|
||||
import { rootCurrentWorkspaceIdAtom } from '@affine/workspace/atom';
|
||||
import { SearchIcon } from '@blocksuite/icons';
|
||||
import { useBlockSuiteWorkspaceAvatarUrl } from '@toeverything/hooks/use-block-suite-workspace-avatar-url';
|
||||
import { useBlockSuiteWorkspaceName } from '@toeverything/hooks/use-block-suite-workspace-name';
|
||||
@ -9,7 +10,7 @@ import { useRouter } from 'next/router';
|
||||
import type React from 'react';
|
||||
import { lazy, Suspense, useCallback, useEffect } from 'react';
|
||||
|
||||
import { currentWorkspaceIdAtom, openQuickSearchModalAtom } from '../../atoms';
|
||||
import { openQuickSearchModalAtom } from '../../atoms';
|
||||
import {
|
||||
publicWorkspaceAtom,
|
||||
publicWorkspaceIdAtom,
|
||||
@ -96,7 +97,7 @@ const ListPage: NextPageWithLayout = () => {
|
||||
const workspaceId = router.query.workspaceId;
|
||||
const setWorkspaceId = useSetAtom(publicWorkspaceIdAtom);
|
||||
// todo: remove this atom usage here
|
||||
const setCurrentWorkspaceId = useSetAtom(currentWorkspaceIdAtom);
|
||||
const setCurrentWorkspaceId = useSetAtom(rootCurrentWorkspaceIdAtom);
|
||||
useEffect(() => {
|
||||
if (!router.isReady) {
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user