mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 07:15:47 +00:00
7a7a9f5e6b
111 of 122 top-level src/utils/ files move into 16 topic folders (audio, cache, cover, share, server, playback, playlist, deviceSync, waveform, mix, format, export, changelog, ui, perf, componentHelpers). True singletons with no cluster stay at the utils/ root. Pure file-move: a path-aware codemod rewrote 539 relative-import specifiers across 275 files; no logic touched. The hot-path coverage gate list (.github/frontend-hot-path-files.txt) is updated to the new paths for the 11 gated utils files — a mechanical consequence of the move, not a CI change. tsc is green.
47 lines
1.7 KiB
TypeScript
47 lines
1.7 KiB
TypeScript
import { useMemo } from 'react';
|
|
import type { SubsonicSong } from '../api/subsonicTypes';
|
|
import type { Track } from '../store/playerStoreTypes';
|
|
import { usePlayerStore } from '../store/playerStore';
|
|
import { songToTrack } from '../utils/playback/songToTrack';
|
|
import { getDisplayedSongs, type PlaylistSortDir, type PlaylistSortKey } from '../utils/playlist/playlistDisplayedSongs';
|
|
|
|
export interface PlaylistDerivedOptions {
|
|
filterText: string;
|
|
sortKey: PlaylistSortKey;
|
|
sortDir: PlaylistSortDir;
|
|
ratings: Record<string, number>;
|
|
starredSongs: Set<string>;
|
|
}
|
|
|
|
export interface PlaylistDerived {
|
|
existingIds: Set<string>;
|
|
tracks: Track[];
|
|
displayedSongs: SubsonicSong[];
|
|
displayedTracks: Track[];
|
|
isFiltered: boolean;
|
|
}
|
|
|
|
export function usePlaylistDerived(songs: SubsonicSong[], opts: PlaylistDerivedOptions): PlaylistDerived {
|
|
const userRatingOverrides = usePlayerStore(s => s.userRatingOverrides);
|
|
const starredOverrides = usePlayerStore(s => s.starredOverrides);
|
|
const { filterText, sortKey, sortDir, ratings, starredSongs } = opts;
|
|
|
|
const existingIds = useMemo(() => new Set(songs.map(s => s.id)), [songs]);
|
|
const tracks = useMemo(() => songs.map(songToTrack), [songs]);
|
|
|
|
const displayedSongs = useMemo(
|
|
() => getDisplayedSongs(songs, {
|
|
filterText, sortKey, sortDir,
|
|
ratings, userRatingOverrides, starredOverrides, starredSongs,
|
|
}),
|
|
[songs, filterText, sortKey, sortDir, ratings, userRatingOverrides, starredOverrides, starredSongs],
|
|
);
|
|
const displayedTracks = useMemo(
|
|
() => displayedSongs === songs ? tracks : displayedSongs.map(songToTrack),
|
|
[displayedSongs, songs, tracks],
|
|
);
|
|
const isFiltered = displayedSongs !== songs;
|
|
|
|
return { existingIds, tracks, displayedSongs, displayedTracks, isFiltered };
|
|
}
|