From e7de27e33bccfd38abe61a477007b8a864d53318 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Sat, 14 Oct 2023 22:22:01 +0200 Subject: [PATCH] add volume storage in zustand --- src/stores/volume/index.ts | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/stores/volume/index.ts diff --git a/src/stores/volume/index.ts b/src/stores/volume/index.ts new file mode 100644 index 00000000..c71b2f75 --- /dev/null +++ b/src/stores/volume/index.ts @@ -0,0 +1,31 @@ +import { StateCreator, create } from "zustand"; +import { persist } from "zustand/middleware"; +import { immer } from "zustand/middleware/immer"; + +export interface VolumeStore { + volume: number; + setVolume(v: number): void; +} + +export type VolumeState = StateCreator< + VolumeStore, + [["zustand/persist", never]], + [] +>; + +// TODO add migration from previous stored volume +export const useVolumeStore: VolumeState = create( + persist( + immer((set) => ({ + volume: 1, + setVolume(v: number) { + set((s) => { + s.volume = v; + }); + }, + })), + { + name: "__MW::volume", + } + ) +);