fix: state in lastVersionAtom

This commit is contained in:
himself65 2023-04-28 02:23:05 -05:00
parent ee695bbcb9
commit 51a4bdc5e4
No known key found for this signature in database
GPG Key ID: 35F07049B7A1E625
3 changed files with 8 additions and 6 deletions

View File

@ -1,10 +1,12 @@
import { config } from '@affine/env';
import { atomWithStorage } from 'jotai/utils';
export type Visibility = Record<string, boolean>;
const DEFAULT_VALUE = '0.0.0';
export const lastVersionAtom = atomWithStorage('lastVersion', DEFAULT_VALUE);
export const lastVersionAtom = atomWithStorage(
'lastVersion',
config.gitVersion
);
export const guideHiddenAtom = atomWithStorage<Visibility>('guideHidden', {});

View File

@ -5,6 +5,7 @@ import 'fake-indexeddb/auto';
import assert from 'node:assert';
import { config } from '@affine/env';
import {
rootCurrentWorkspaceIdAtom,
rootWorkspacesMetadataAtom,
@ -282,7 +283,7 @@ describe('useIsFirstLoad', () => {
test('useLastVersion', async () => {
const lastVersion = renderHook(() => useLastVersion());
const setLastVersion = lastVersion.result.current[1];
expect(lastVersion.result.current[0]).toEqual('0.0.0');
expect(lastVersion.result.current[0]).toEqual(config.gitVersion);
setLastVersion('testVersion');
lastVersion.rerender();
expect(lastVersion.result.current[0]).toEqual('testVersion');

View File

@ -45,7 +45,6 @@ export function useTipsDisplayStatus() {
export function useUpdateTipsOnVersionChange() {
const [lastVersion, setLastVersion] = useLastVersion();
const currentVersion = config.gitVersion;
const tipsDisplayStatus = useTipsDisplayStatus();
const setPermanentlyHiddenTips = useSetAtom(guideHiddenAtom);
const setHiddenUntilNextUpdateTips = useSetAtom(
@ -53,6 +52,7 @@ export function useUpdateTipsOnVersionChange() {
);
useEffect(() => {
const currentVersion = config.gitVersion;
if (lastVersion !== currentVersion) {
setLastVersion(currentVersion);
const newHiddenUntilNextUpdateTips = { ...TIPS };
@ -64,7 +64,6 @@ export function useUpdateTipsOnVersionChange() {
setPermanentlyHiddenTips(newPermanentlyHiddenTips);
}
}, [
currentVersion,
lastVersion,
setLastVersion,
setPermanentlyHiddenTips,