randomize backgrounds
This commit is contained in:
11
src/atoms.ts
11
src/atoms.ts
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user