mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
fix: first workspace create logic (#1773)
This commit is contained in:
@@ -1,28 +1,19 @@
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
import { atomWithSyncStorage } from '@affine/jotai';
|
||||
|
||||
export type Visibility = Record<string, boolean>;
|
||||
|
||||
const DEFAULT_VALUE = '0.0.0';
|
||||
//atomWithStorage always uses initial value when first render
|
||||
//https://github.com/pmndrs/jotai/discussions/1737
|
||||
|
||||
function getInitialValue() {
|
||||
if (typeof window !== 'undefined') {
|
||||
const storedValue = window.localStorage.getItem('lastVersion');
|
||||
if (storedValue) {
|
||||
return JSON.parse(storedValue);
|
||||
}
|
||||
}
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
export const lastVersionAtom = atomWithStorage(
|
||||
export const lastVersionAtom = atomWithSyncStorage(
|
||||
'lastVersion',
|
||||
getInitialValue()
|
||||
DEFAULT_VALUE
|
||||
);
|
||||
export const guideHiddenAtom = atomWithSyncStorage<Visibility>(
|
||||
'guideHidden',
|
||||
{}
|
||||
);
|
||||
export const guideHiddenAtom = atomWithStorage<Visibility>('guideHidden', {});
|
||||
|
||||
export const guideHiddenUntilNextUpdateAtom = atomWithStorage<Visibility>(
|
||||
export const guideHiddenUntilNextUpdateAtom = atomWithSyncStorage<Visibility>(
|
||||
'guideHiddenUntilNextUpdate',
|
||||
{}
|
||||
);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { atomWithSyncStorage } from '@affine/jotai';
|
||||
import { jotaiStore, jotaiWorkspacesAtom } from '@affine/workspace/atom';
|
||||
import type { EditorContainer } from '@blocksuite/editor';
|
||||
import type { Page } from '@blocksuite/store';
|
||||
import { assertExists } from '@blocksuite/store';
|
||||
import { atom } from 'jotai';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
import { unstable_batchedUpdates } from 'react-dom';
|
||||
|
||||
import { WorkspacePlugins } from '../plugins';
|
||||
@@ -57,16 +57,12 @@ type View = { id: string; mode: 'page' | 'edgeless' };
|
||||
|
||||
export type WorkspaceRecentViews = Record<string, View[]>;
|
||||
|
||||
export const workspaceRecentViewsAtom = atomWithStorage<WorkspaceRecentViews>(
|
||||
'recentViews',
|
||||
{}
|
||||
);
|
||||
export const workspaceRecentViewsAtom =
|
||||
atomWithSyncStorage<WorkspaceRecentViews>('recentViews', {});
|
||||
|
||||
export type PreferredModeRecord = Record<Page['id'], 'page' | 'edgeless'>;
|
||||
export const workspacePreferredModeAtom = atomWithStorage<PreferredModeRecord>(
|
||||
'preferredMode',
|
||||
{}
|
||||
);
|
||||
export const workspacePreferredModeAtom =
|
||||
atomWithSyncStorage<PreferredModeRecord>('preferredMode', {});
|
||||
|
||||
export const workspaceRecentViresWriteAtom = atom<null, [string, View], View[]>(
|
||||
null,
|
||||
|
||||
Reference in New Issue
Block a user