refactor: remove sync storage (#2269)

This commit is contained in:
Himself65
2023-05-09 06:21:42 +08:00
committed by GitHub
parent 3a6be4510b
commit 95bc5cac49
9 changed files with 22 additions and 102 deletions

View File

@@ -1,5 +1,4 @@
import { DebugLogger } from '@affine/debug';
import { atomWithSyncStorage } from '@affine/jotai';
import type { RootWorkspaceMetadata } from '@affine/workspace/atom';
import {
rootCurrentEditorAtom,
@@ -10,6 +9,7 @@ import {
import { WorkspaceFlavour } from '@affine/workspace/type';
import type { Page } from '@blocksuite/store';
import { atom } from 'jotai';
import { atomWithStorage } from 'jotai/utils';
import { WorkspacePlugins } from '../plugins';
@@ -87,12 +87,16 @@ type View = { id: string; mode: 'page' | 'edgeless' };
export type WorkspaceRecentViews = Record<string, View[]>;
export const workspaceRecentViewsAtom =
atomWithSyncStorage<WorkspaceRecentViews>('recentViews', {});
export const workspaceRecentViewsAtom = atomWithStorage<WorkspaceRecentViews>(
'recentViews',
{}
);
export type PreferredModeRecord = Record<Page['id'], 'page' | 'edgeless'>;
export const workspacePreferredModeAtom =
atomWithSyncStorage<PreferredModeRecord>('preferredMode', {});
export const workspacePreferredModeAtom = atomWithStorage<PreferredModeRecord>(
'preferredMode',
{}
);
export const workspaceRecentViresWriteAtom = atom<null, [string, View], View[]>(
null,

View File

@@ -1,5 +1,5 @@
import { atomWithSyncStorage } from '@affine/jotai';
import { useAtom, useAtomValue, useSetAtom } from 'jotai';
import { atomWithStorage } from 'jotai/utils';
import { useCallback } from 'react';
import { currentPageIdAtom, currentWorkspaceIdAtom } from '../../atoms';
@@ -11,7 +11,7 @@ import type { AllWorkspace } from '../../shared';
*/
export const currentWorkspaceAtom = rootCurrentWorkspaceAtom;
export const lastWorkspaceIdAtom = atomWithSyncStorage<string | null>(
export const lastWorkspaceIdAtom = atomWithStorage<string | null>(
'last_workspace_id',
null
);

View File

@@ -1,5 +1,4 @@
import { useAFFiNEI18N } from '@affine/i18n/hooks';
import { atomWithSyncStorage } from '@affine/jotai';
import { rootWorkspacesMetadataAtom } from '@affine/workspace/atom';
import type { SettingPanel } from '@affine/workspace/type';
import {
@@ -10,6 +9,7 @@ import {
import { SettingsIcon } from '@blocksuite/icons';
import { assertExists } from '@blocksuite/store';
import { useAtom, useAtomValue } from 'jotai';
import { atomWithStorage } from 'jotai/utils';
import Head from 'next/head';
import { useRouter } from 'next/router';
import React, { useCallback, useEffect } from 'react';
@@ -26,7 +26,7 @@ import { WorkspacePlugins } from '../../../plugins';
import type { NextPageWithLayout } from '../../../shared';
import { toast } from '../../../utils';
const settingPanelAtom = atomWithSyncStorage<SettingPanel>(
const settingPanelAtom = atomWithStorage<SettingPanel>(
'workspaceId',
settingPanel.General
);