mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
link savePlayQueue setting to player store persist
This commit is contained in:
@@ -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,
|
||||||
|
|||||||
Reference in New Issue
Block a user