There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
refactor: remove deprecated atoms (#2615)
Himself6506abb702f562
diff --git a/apps/web/src/atoms/index.ts b/apps/web/src/atoms/index.tsindex 449e9e7aeb..86b05ced2c 100644--- a/apps/web/src/atoms/index.ts+++ b/apps/web/src/atoms/index.ts@@ -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 packagerootWorkspacesMetadataAtom.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 atomsexport const openWorkspacesModalAtom = atom(false);export const openCreateWorkspaceModalAtom = atom<CreateWorkspaceMode>(false);diff --git a/apps/web/src/components/page-detail-editor.tsx b/apps/web/src/components/page-detail-editor.tsxindex b6ea342056..dbe7fd495e 100644--- a/apps/web/src/components/page-detail-editor.tsx+++ b/apps/web/src/components/page-detail-editor.tsx@@ -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 (<Editordiff --git a/apps/web/src/hooks/__tests__/index.spec.tsx b/apps/web/src/hooks/__tests__/index.spec.tsxindex 78dbee0277..dd80df8e0f 100644--- a/apps/web/src/hooks/__tests__/index.spec.tsx+++ b/apps/web/src/hooks/__tests__/index.spec.tsx@@ -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,});diff --git a/apps/web/src/hooks/__tests__/use-recent-views.spec.tsx b/apps/web/src/hooks/__tests__/use-recent-views.spec.tsxindex 3de4896cc3..2400b86751 100644--- a/apps/web/src/hooks/__tests__/use-recent-views.spec.tsx+++ b/apps/web/src/hooks/__tests__/use-recent-views.spec.tsx@@ -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,});diff --git a/apps/web/src/hooks/current/use-current-mode.ts b/apps/web/src/hooks/current/use-current-mode.tsindex 04e33b4fe8..6508259469 100644--- a/apps/web/src/hooks/current/use-current-mode.ts+++ b/apps/web/src/hooks/current/use-current-mode.ts@@ -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 {diff --git a/apps/web/src/hooks/current/use-current-workspace.ts b/apps/web/src/hooks/current/use-current-workspace.tsindex adc9aee414..18e04e5eb7 100644--- a/apps/web/src/hooks/current/use-current-workspace.ts+++ b/apps/web/src/hooks/current/use-current-workspace.ts@@ -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(diff --git a/apps/web/src/pages/public-workspace/[workspaceId].tsx b/apps/web/src/pages/public-workspace/[workspaceId].tsxindex e48e2459ce..72405954b7 100644--- a/apps/web/src/pages/public-workspace/[workspaceId].tsx+++ b/apps/web/src/pages/public-workspace/[workspaceId].tsx@@ -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;