add volume storage in zustand

This commit is contained in:
mrjvs 2023-10-14 22:22:01 +02:00
parent b9f79b97c0
commit e7de27e33b

View File

@ -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<VolumeStore>((set) => ({
volume: 1,
setVolume(v: number) {
set((s) => {
s.volume = v;
});
},
})),
{
name: "__MW::volume",
}
)
);