mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
fix grid song play behavior (#1477)
This commit is contained in:
@@ -73,6 +73,29 @@ const createPlayHandler =
|
||||
return;
|
||||
}
|
||||
|
||||
const isSongItem =
|
||||
itemType === LibraryItem.SONG ||
|
||||
itemType === LibraryItem.PLAYLIST_SONG ||
|
||||
(item as { _itemType: LibraryItem })._itemType === LibraryItem.SONG;
|
||||
|
||||
if (isSongItem && controls?.onDoubleClick && internalState) {
|
||||
const rowId = internalState.extractRowId(item);
|
||||
|
||||
if (rowId) {
|
||||
const index = internalState.findItemIndex(rowId);
|
||||
return controls.onDoubleClick({
|
||||
event: null,
|
||||
index,
|
||||
internalState,
|
||||
item,
|
||||
itemType,
|
||||
meta: {
|
||||
playType,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
controls?.onPlay?.({
|
||||
event: e,
|
||||
internalState,
|
||||
|
||||
@@ -191,7 +191,7 @@ export const useDefaultItemListControls = (args?: UseDefaultItemListControlsArgs
|
||||
onColumnResized?.(columnId, width);
|
||||
},
|
||||
|
||||
onDoubleClick: ({ internalState, item, itemType }: DefaultItemControlProps) => {
|
||||
onDoubleClick: ({ internalState, item, itemType, meta }: DefaultItemControlProps) => {
|
||||
if (!item || !internalState) {
|
||||
return;
|
||||
}
|
||||
@@ -212,7 +212,7 @@ export const useDefaultItemListControls = (args?: UseDefaultItemListControlsArgs
|
||||
}
|
||||
}
|
||||
|
||||
if (itemType === LibraryItem.SONG) {
|
||||
if (itemType === LibraryItem.SONG || itemType === LibraryItem.PLAYLIST_SONG) {
|
||||
const data = internalState.getData();
|
||||
const validSongs = data.filter((d): d is Song => {
|
||||
if (!d || typeof d !== 'object') {
|
||||
@@ -235,17 +235,31 @@ export const useDefaultItemListControls = (args?: UseDefaultItemListControlsArgs
|
||||
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);
|
||||
const playType = (meta?.playType as Play) || Play.NOW;
|
||||
|
||||
// For NEXT, LAST, NEXT_SHUFFLE, and LAST_SHUFFLE, only add the clicked song
|
||||
// For NOW and SHUFFLE, add a range of songs around the clicked song
|
||||
let songsToAdd: Song[];
|
||||
if (
|
||||
playType === Play.NEXT ||
|
||||
playType === Play.LAST ||
|
||||
playType === Play.NEXT_SHUFFLE ||
|
||||
playType === Play.LAST_SHUFFLE
|
||||
) {
|
||||
songsToAdd = [item as Song];
|
||||
} else {
|
||||
const songsBefore = 50;
|
||||
const songsAfter = 50;
|
||||
const startIndex = Math.max(0, clickedIndex - songsBefore);
|
||||
const endIndex = Math.min(validSongs.length, clickedIndex + songsAfter + 1);
|
||||
songsToAdd = validSongs.slice(startIndex, endIndex);
|
||||
}
|
||||
|
||||
if (songsToAdd.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
player.addToQueueByData(songsToAdd, Play.NOW, item.id);
|
||||
player.addToQueueByData(songsToAdd, playType, item.id);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user