mirror of
https://github.com/movie-web/movie-web.git
synced 2024-12-28 01:11:51 +01:00
add volume storage in zustand
This commit is contained in:
parent
b9f79b97c0
commit
e7de27e33b
31
src/stores/volume/index.ts
Normal file
31
src/stores/volume/index.ts
Normal 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",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
);
|
Loading…
Reference in New Issue
Block a user