diff --git a/app/store/player.ts b/app/store/player.ts index d4fe947..369f604 100644 --- a/app/store/player.ts +++ b/app/store/player.ts @@ -3,40 +3,37 @@ import { create } from "zustand"; import { persist } from "zustand/middleware"; interface userPlayerPreferencesState { - voiceover: Record; - player: Record; - getPreferredVoiceover: (id: number) => (string | undefined); - setPreferredVoiceover: (id: number, voiceover: string) => void; - getPreferredPlayer: (id: number) => (string | undefined); - setPreferredPlayer: (id: number, player: string) => void; + voiceover: Record; + player: Record; + getPreferredVoiceover: (id: number) => string | undefined; + setPreferredVoiceover: (id: number, voiceover: string) => void; + getPreferredPlayer: (id: number) => string | undefined; + setPreferredPlayer: (id: number, player: string) => void; } -export const useUserPlayerPreferencesStore = create()( +export const useUserPlayerPreferencesStore = + create()( persist( - (set, get) => ({ - voiceover: {}, - player: {}, - getPreferredVoiceover: (id: number) => get().voiceover[id], - setPreferredVoiceover: (id: number, voiceover: string) => { - let current = get().voiceover - current[id] = voiceover - set({ - voiceover: current, - player: get().player, - }); - }, - getPreferredPlayer: (id: number) => get().player[id], - setPreferredPlayer: (id: number, player: string) => { - let current = get().player - current[id] = player - set({ - voiceover: get().voiceover, - player: current, - }) - } - }), - { - name: "player-preferences", - } + (set, get) => ({ + voiceover: {}, + player: {}, + getPreferredVoiceover: (id: number) => get().voiceover[id], + setPreferredVoiceover: (id: number, voiceover: string) => { + set({ + voiceover: { ...get().voiceover, [id]: voiceover }, + player: get().player, + }); + }, + getPreferredPlayer: (id: number) => get().player[id], + setPreferredPlayer: (id: number, player: string) => { + set({ + player: { ...get().player, [id]: player }, + voiceover: get().voiceover, + }); + }, + }), + { + name: "player-preferences", + } ) -); \ No newline at end of file + );