Add 'byData' as playqueue add option

This commit is contained in:
jeffvli 2022-12-28 15:31:04 -08:00
parent 0edba7e222
commit 8ebe882236
2 changed files with 27 additions and 3 deletions

View File

@ -10,6 +10,7 @@ import { usePlayerType } from '/@/renderer/store/settings.store';
import { PlayQueueAddOptions, LibraryItem, Play, PlaybackType } from '/@/renderer/types';
import { toast } from '/@/renderer/components/toast';
import isElectron from 'is-electron';
import { nanoid } from 'nanoid/non-secure';
const mpvPlayer = isElectron() ? window.electron.mpvPlayer : null;
@ -74,6 +75,29 @@ export const useHandlePlayQueueAdd = () => {
}
}
if (options.byData) {
const songsWithNewUniqueId = options.byData.map((song) => ({ ...song, uniqueId: nanoid() }));
const playerData = usePlayerStore
.getState()
.actions.addToQueue(songsWithNewUniqueId, options.play);
if (options.play === Play.NEXT || options.play === Play.LAST) {
if (playerType === PlaybackType.LOCAL) {
mpvPlayer.setQueueNext(playerData);
}
}
if (options.play === Play.NOW) {
if (playerType === PlaybackType.LOCAL) {
mpvPlayer.setQueue(playerData);
mpvPlayer.play();
}
usePlayerStore.getState().actions.play();
}
}
return null;
};

View File

@ -1,4 +1,4 @@
import { Album, AlbumArtist, Artist } from '/@/renderer/api/types';
import { Album, AlbumArtist, Artist, QueueSong } from '/@/renderer/api/types';
import { AppRoute } from '/@/renderer/router/routes';
export type TablePagination = {
@ -157,8 +157,8 @@ export enum TableColumn {
}
export type PlayQueueAddOptions = {
// byData?: any[];
byItemType: {
byData?: QueueSong[];
byItemType?: {
id: string;
type: LibraryItem;
};