mirror of
https://github.com/kilyabin/psysonic.git
synced 2026-07-22 14:35:41 +00:00
1a3eeea048
Four-cut cluster pulling action bodies out of PlaylistDetail.tsx. 741
→ 635 LOC (−106). Each handler on the page becomes a thin wrapper
around a parameterized utility; pure code move, no behaviour change.
runPlaylistZipDownload — the buildDownloadUrl → invoke('download_zip')
flow with start/complete/fail dispatches to useZipDownloadStore and
the setZipDownloadId hand-off. Takes playlist + id + downloadFolder
+ requestDownloadFolder + the id-setter as deps. PlaylistDetail
loses the invoke / join / buildDownloadUrl / sanitizeFilename imports
that only this handler used.
playlistBulkPlayActions — three exports (playPlaylistAll,
shufflePlaylistAll, enqueuePlaylistAll) with a shared BulkPlayDeps
shape (songsLength + id + tracks + touchPlaylist + playTrack +
enqueue). Same length-guard, same touchPlaylist call, same
shuffle / play / enqueue branches as before.
startPlaylistRowDrag — the threshold-drag dispatch on row mousedown
(5px deadzone, then bulk-songs / playlist-reorder / single-song
payload depending on selection state + filtered-view flag). Takes
the mouse event + idx + songs + selectedIds + isFiltered + startDrag.
runPlaylistReorderDrop — the psy-drop event handler that lives
inside the tracklist useEffect. Parses the custom-event detail,
computes from→to indexes, and updates songs + savePlaylist + clears
dropTargetIdx. The useEffect itself stays in the page because it
wires up the event listener.
PlaylistDetail's import list also drops `invoke`, `join`,
`buildDownloadUrl`, `sanitizeFilename` — they followed the ZIP
helper to its new file.
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import type { Track } from '../store/playerStoreTypes';
|
|
|
|
export interface BulkPlayDeps {
|
|
songsLength: number;
|
|
id: string | undefined;
|
|
tracks: Track[];
|
|
touchPlaylist: (id: string) => void;
|
|
playTrack: (track: Track, queue: Track[]) => void;
|
|
enqueue: (tracks: Track[]) => void;
|
|
}
|
|
|
|
export function playPlaylistAll(deps: BulkPlayDeps): void {
|
|
const { songsLength, id, tracks, touchPlaylist, playTrack } = deps;
|
|
if (!songsLength || !id) return;
|
|
touchPlaylist(id);
|
|
playTrack(tracks[0], tracks);
|
|
}
|
|
|
|
export function shufflePlaylistAll(deps: BulkPlayDeps): void {
|
|
const { songsLength, id, tracks, touchPlaylist, playTrack } = deps;
|
|
if (!songsLength || !id) return;
|
|
touchPlaylist(id);
|
|
const shuffled = [...tracks];
|
|
for (let i = shuffled.length - 1; i > 0; i--) {
|
|
const j = Math.floor(Math.random() * (i + 1));
|
|
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
}
|
|
playTrack(shuffled[0], shuffled);
|
|
}
|
|
|
|
export function enqueuePlaylistAll(deps: BulkPlayDeps): void {
|
|
const { songsLength, id, tracks, touchPlaylist, enqueue } = deps;
|
|
if (!songsLength || !id) return;
|
|
touchPlaylist(id);
|
|
enqueue(tracks);
|
|
}
|