fix(favorites): bulk add-to-playlist and play/enqueue selected (#1140)

This commit is contained in:
cucadmuh
2026-06-21 14:29:05 +03:00
committed by GitHub
parent 30ccaf51a8
commit 986550c854
15 changed files with 100 additions and 33 deletions
+10 -9
View File
@@ -7,7 +7,7 @@ export interface FavoritesSelectionResult {
}
export function useFavoritesSelection(
songs: SubsonicSong[],
visibleSongs: SubsonicSong[],
inSelectMode: boolean,
tracklistRef: React.RefObject<HTMLDivElement | null>,
): FavoritesSelectionResult {
@@ -17,15 +17,18 @@ export function useFavoritesSelection(
useEffect(() => {
useSelectionStore.getState().clearAll();
lastSelectedIdxRef.current = null;
}, [songs]);
}, [visibleSongs]);
// Clear selection on click outside tracklist
useEffect(() => {
if (!inSelectMode) return;
const handler = (e: MouseEvent) => {
if (tracklistRef.current && !tracklistRef.current.contains(e.target as Node)) {
useSelectionStore.getState().clearAll();
}
const target = e.target as HTMLElement;
if (!tracklistRef.current || tracklistRef.current.contains(target)) return;
// Toolbar (play/enqueue, filters, bulk actions) sits outside the tracklist
// DOM but belongs to the selection — don't clear before its click runs.
if (target.closest('.favorites-songs-toolbar, .bulk-pl-picker-wrap, .context-submenu')) return;
useSelectionStore.getState().clearAll();
};
document.addEventListener('mousedown', handler);
return () => document.removeEventListener('mousedown', handler);
@@ -37,10 +40,8 @@ export function useFavoritesSelection(
if (shift && lastSelectedIdxRef.current !== null) {
const from = Math.min(lastSelectedIdxRef.current, idx);
const to = Math.max(lastSelectedIdxRef.current, idx);
// we need visibleSongs here — read from latest closure via ref trick
// Instead, just toggle range based on idx into songs array
for (let j = from; j <= to; j++) {
const sid = songs[j]?.id;
const sid = visibleSongs[j]?.id;
if (sid) next.add(sid);
}
} else {
@@ -49,7 +50,7 @@ export function useFavoritesSelection(
}
return next;
});
}, [songs]);
}, [visibleSongs]);
return { toggleSelect };
}