fix: first workspace create logic (#1773)

This commit is contained in:
Peng Xiao
2023-04-01 01:40:30 +08:00
committed by GitHub
parent fd65dd66a1
commit 7299efe16a
20 changed files with 158 additions and 87 deletions
+8 -17
View File
@@ -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',
{}
);