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