mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-12 12:28:42 +00:00
revert: lastVersionAtom atom (#2188)
This commit is contained in:
@@ -1,11 +1,24 @@
|
||||
import { config } from '@affine/env';
|
||||
import { atomWithStorage } from 'jotai/utils';
|
||||
|
||||
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(
|
||||
'lastVersion',
|
||||
config.gitVersion
|
||||
getInitialValue()
|
||||
);
|
||||
|
||||
export const guideHiddenAtom = atomWithStorage<Visibility>('guideHidden', {});
|
||||
|
||||
@@ -5,7 +5,6 @@ import 'fake-indexeddb/auto';
|
||||
|
||||
import assert from 'node:assert';
|
||||
|
||||
import { config } from '@affine/env';
|
||||
import {
|
||||
rootCurrentWorkspaceIdAtom,
|
||||
rootWorkspacesMetadataAtom,
|
||||
@@ -283,7 +282,7 @@ describe('useIsFirstLoad', () => {
|
||||
test('useLastVersion', async () => {
|
||||
const lastVersion = renderHook(() => useLastVersion());
|
||||
const setLastVersion = lastVersion.result.current[1];
|
||||
expect(lastVersion.result.current[0]).toEqual(config.gitVersion);
|
||||
expect(lastVersion.result.current[0]).toEqual('0.0.0');
|
||||
setLastVersion('testVersion');
|
||||
lastVersion.rerender();
|
||||
expect(lastVersion.result.current[0]).toEqual('testVersion');
|
||||
|
||||
@@ -45,6 +45,7 @@ export function useTipsDisplayStatus() {
|
||||
|
||||
export function useUpdateTipsOnVersionChange() {
|
||||
const [lastVersion, setLastVersion] = useLastVersion();
|
||||
const currentVersion = config.gitVersion;
|
||||
const tipsDisplayStatus = useTipsDisplayStatus();
|
||||
const setPermanentlyHiddenTips = useSetAtom(guideHiddenAtom);
|
||||
const setHiddenUntilNextUpdateTips = useSetAtom(
|
||||
@@ -52,7 +53,6 @@ export function useUpdateTipsOnVersionChange() {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const currentVersion = config.gitVersion;
|
||||
if (lastVersion !== currentVersion) {
|
||||
setLastVersion(currentVersion);
|
||||
const newHiddenUntilNextUpdateTips = { ...TIPS };
|
||||
@@ -64,6 +64,7 @@ export function useUpdateTipsOnVersionChange() {
|
||||
setPermanentlyHiddenTips(newPermanentlyHiddenTips);
|
||||
}
|
||||
}, [
|
||||
currentVersion,
|
||||
lastVersion,
|
||||
setLastVersion,
|
||||
setPermanentlyHiddenTips,
|
||||
|
||||
Reference in New Issue
Block a user