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", + } + ) +);