randomize backgrounds

This commit is contained in:
2025-02-09 23:23:04 +02:00
parent 2dfad23a95
commit 4b30e27578

View File

@@ -1,4 +1,4 @@
import { atomWithStorage } from 'jotai/utils';
import { atomWithDefault, atomWithStorage } from 'jotai/utils';
import { Background, BackgroundStorage } from './types';
import { random } from './lib/math';
import { atom } from 'jotai';
@@ -28,13 +28,18 @@ export const backgroundsAtom = atomWithStorage<BackgroundStorage>('vertex-backgr
backgrounds: [],
});
export const backgroundIndexAtom = atomWithDefault((get) =>
random(get(backgroundsAtom).backgrounds.length - 1)
);
export const favoriteBackgroundsAtom = atomWithStorage<Background[]>(
'vertex-favorite-backgrounds',
[]
);
export const backgroundIndexAtom = atom(random(19));
export const favoritedBackgroundIndexAtom = atom(0);
export const favoritedBackgroundIndexAtom = atomWithDefault((get) =>
random(get(favoriteBackgroundsAtom).length - 1)
);
export const currentBackgroundAtom = atom((get) => {
if (get(settingsAtom).useSavedBackgrounds) {