add double click play handler to song lists

This commit is contained in:
jeffvli
2025-12-02 00:50:48 -08:00
parent 65f24c2c03
commit 6d8947fe74
@@ -6,7 +6,7 @@ import { ItemListStateItemWithRequiredProperties } from '/@/renderer/components/
import { DefaultItemControlProps, ItemControls } from '/@/renderer/components/item-list/types';
import { ContextMenuController } from '/@/renderer/features/context-menu/context-menu-controller';
import { usePlayer } from '/@/renderer/features/player/context/player-context';
import { LibraryItem, QueueSong } from '/@/shared/types/domain-types';
import { LibraryItem, QueueSong, Song } from '/@/shared/types/domain-types';
import { Play, TableColumn } from '/@/shared/types/types';
interface UseDefaultItemListControlsArgs {
@@ -212,6 +212,47 @@ export const useDefaultItemListControls = (args?: UseDefaultItemListControlsArgs
}
}
if (itemType === LibraryItem.SONG) {
const data = internalState.getData();
const validSongs = data.filter((d): d is Song => {
if (!d || typeof d !== 'object') {
return false;
}
if (!('_itemType' in d)) {
return false;
}
return (d as { _itemType: LibraryItem })._itemType === LibraryItem.SONG;
});
if (validSongs.length === 0) {
return;
}
const clickedSongId = item.id;
const clickedIndex = validSongs.findIndex((song) => song.id === clickedSongId);
if (clickedIndex === -1) {
return;
}
const songsBefore = 100;
const songsAfter = 100;
const startIndex = Math.max(0, clickedIndex - songsBefore);
const endIndex = Math.min(validSongs.length, clickedIndex + songsAfter + 1);
const songsToAdd = validSongs.slice(startIndex, endIndex);
if (songsToAdd.length === 0) {
return;
}
player.addToQueueByData(songsToAdd, Play.NOW);
const targetIndex = clickedIndex - startIndex;
player.mediaPlayByIndex(targetIndex);
return;
}
if (itemType === LibraryItem.QUEUE_SONG) {
const queueSong = item as QueueSong;
if (queueSong._uniqueId) {