link savePlayQueue setting to player store persist

This commit is contained in:
jeffvli
2025-11-13 10:41:01 -08:00
parent a566509f5b
commit 7d5be53c4d
+29 -11
View File
@@ -1070,22 +1070,40 @@ export const usePlayerStoreBase = create<PlayerState>()(
}, },
name: 'player-store', name: 'player-store',
partialize: (state) => { partialize: (state) => {
const shouldRestorePlayQueue = useSettingsStore.getState().general.resume;
// Exclude playerNum, seekToTimestamp, status, and timestamp from stored player object // Exclude playerNum, seekToTimestamp, status, and timestamp from stored player object
// These are not needed to be stored since they are ephemeral properties // These are not needed to be stored since they are ephemeral properties
const excludedKeys = ['playerNum', 'seekToTimestamp', 'status', 'timestamp']; const excludedPlayerKeys = ['playerNum', 'seekToTimestamp', 'status', 'timestamp'];
if (state.player) { // If we're not restoring the play queue, we don't need the index property
return { if (!shouldRestorePlayQueue) {
...state, excludedPlayerKeys.push('index');
player: Object.fromEntries(
Object.entries(state.player).filter(
([key]) => !excludedKeys.includes(key),
),
) as typeof state.player,
};
} }
return state; // Filter top-level state entries
const filteredStateEntries = Object.entries(state).filter(([key]) => {
// Exclude queue if shouldRestorePlayQueue is false
if (!shouldRestorePlayQueue && key === 'queue') {
return false;
}
return true;
});
const filteredState = Object.fromEntries(
filteredStateEntries,
) as Partial<PlayerState>;
// Filter player object
if (filteredState.player) {
filteredState.player = Object.fromEntries(
Object.entries(filteredState.player).filter(
([key]) => !excludedPlayerKeys.includes(key),
),
) as typeof filteredState.player;
}
return filteredState;
}, },
storage: createJSONStorage(() => idbStateStorage), storage: createJSONStorage(() => idbStateStorage),
version: 1, version: 1,