mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
76fc3bb9c9
Two small action-factory extractions in one PR, both following the pattern from E.31–E.33. - `createTransportLightActions` — `stop`, `pause`, `resetAudioPause`, `togglePlay`. Everything in the pause/togglePlay cluster except `resume` (~165 LOC, deferred to its own PR). - `createUndoRedoActions` — `undoLastQueueEdit`, `redoLastQueueEdit`. Trivial wrappers around `applyQueueHistorySnapshot` + the queue-undo stack helpers. Pure code-move. playerStore.ts: 1247 → 1167 LOC (−80).
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { applyQueueHistorySnapshot } from './applyQueueHistorySnapshot';
|
|
import type { PlayerState } from './playerStoreTypes';
|
|
import {
|
|
popQueueRedoSnapshot,
|
|
popQueueUndoSnapshot,
|
|
pushQueueRedoSnapshot,
|
|
pushQueueUndoSnapshot,
|
|
queueUndoSnapshotFromState,
|
|
} from './queueUndo';
|
|
|
|
type SetState = (
|
|
partial: Partial<PlayerState> | ((state: PlayerState) => Partial<PlayerState>),
|
|
) => void;
|
|
type GetState = () => PlayerState;
|
|
|
|
/**
|
|
* Undo / redo wrappers for queue edits. Both pop the matching history
|
|
* snapshot, push the *prior* state onto the opposite stack so the next
|
|
* call reverses direction, and delegate the actual state reconciliation
|
|
* to `applyQueueHistorySnapshot`.
|
|
*/
|
|
export function createUndoRedoActions(set: SetState, get: GetState): Pick<
|
|
PlayerState,
|
|
'undoLastQueueEdit' | 'redoLastQueueEdit'
|
|
> {
|
|
return {
|
|
undoLastQueueEdit: () => {
|
|
const prior = get();
|
|
const snap = popQueueUndoSnapshot();
|
|
if (!snap) return false;
|
|
pushQueueRedoSnapshot(queueUndoSnapshotFromState(prior));
|
|
return applyQueueHistorySnapshot(snap, prior, set, get);
|
|
},
|
|
|
|
redoLastQueueEdit: () => {
|
|
const prior = get();
|
|
const snap = popQueueRedoSnapshot();
|
|
if (!snap) return false;
|
|
pushQueueUndoSnapshot(queueUndoSnapshotFromState(prior));
|
|
return applyQueueHistorySnapshot(snap, prior, set, get);
|
|
},
|
|
};
|
|
}
|