mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-06 00:04:39 +00:00
refactor: player store
https://github.com/Radiquum/AniX/pull/3#discussion_r1871410991
This commit is contained in:
parent
9d921c1ee4
commit
462778c6f9
1 changed files with 30 additions and 33 deletions
|
@ -3,40 +3,37 @@ import { create } from "zustand";
|
||||||
import { persist } from "zustand/middleware";
|
import { persist } from "zustand/middleware";
|
||||||
|
|
||||||
interface userPlayerPreferencesState {
|
interface userPlayerPreferencesState {
|
||||||
voiceover: Record<number, string>;
|
voiceover: Record<number, string>;
|
||||||
player: Record<number, string>;
|
player: Record<number, string>;
|
||||||
getPreferredVoiceover: (id: number) => (string | undefined);
|
getPreferredVoiceover: (id: number) => string | undefined;
|
||||||
setPreferredVoiceover: (id: number, voiceover: string) => void;
|
setPreferredVoiceover: (id: number, voiceover: string) => void;
|
||||||
getPreferredPlayer: (id: number) => (string | undefined);
|
getPreferredPlayer: (id: number) => string | undefined;
|
||||||
setPreferredPlayer: (id: number, player: string) => void;
|
setPreferredPlayer: (id: number, player: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useUserPlayerPreferencesStore = create<userPlayerPreferencesState>()(
|
export const useUserPlayerPreferencesStore =
|
||||||
|
create<userPlayerPreferencesState>()(
|
||||||
persist(
|
persist(
|
||||||
(set, get) => ({
|
(set, get) => ({
|
||||||
voiceover: {},
|
voiceover: {},
|
||||||
player: {},
|
player: {},
|
||||||
getPreferredVoiceover: (id: number) => get().voiceover[id],
|
getPreferredVoiceover: (id: number) => get().voiceover[id],
|
||||||
setPreferredVoiceover: (id: number, voiceover: string) => {
|
setPreferredVoiceover: (id: number, voiceover: string) => {
|
||||||
let current = get().voiceover
|
set({
|
||||||
current[id] = voiceover
|
voiceover: { ...get().voiceover, [id]: voiceover },
|
||||||
set({
|
player: get().player,
|
||||||
voiceover: current,
|
});
|
||||||
player: get().player,
|
},
|
||||||
});
|
getPreferredPlayer: (id: number) => get().player[id],
|
||||||
},
|
setPreferredPlayer: (id: number, player: string) => {
|
||||||
getPreferredPlayer: (id: number) => get().player[id],
|
set({
|
||||||
setPreferredPlayer: (id: number, player: string) => {
|
player: { ...get().player, [id]: player },
|
||||||
let current = get().player
|
voiceover: get().voiceover,
|
||||||
current[id] = player
|
});
|
||||||
set({
|
},
|
||||||
voiceover: get().voiceover,
|
}),
|
||||||
player: current,
|
{
|
||||||
})
|
name: "player-preferences",
|
||||||
}
|
}
|
||||||
}),
|
|
||||||
{
|
|
||||||
name: "player-preferences",
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue