Handle song detail on playqueue add
This commit is contained in:
parent
c4fb9a2e72
commit
b5fa6f0baa
1 changed files with 19 additions and 6 deletions
|
@ -8,7 +8,7 @@ import { PlayQueueAddOptions, Play, PlaybackType } from '/@/renderer/types';
|
||||||
import { toast } from '/@/renderer/components/toast/index';
|
import { toast } from '/@/renderer/components/toast/index';
|
||||||
import isElectron from 'is-electron';
|
import isElectron from 'is-electron';
|
||||||
import { nanoid } from 'nanoid/non-secure';
|
import { nanoid } from 'nanoid/non-secure';
|
||||||
import { LibraryItem, SongListSort, SortOrder } from '/@/renderer/api/types';
|
import { LibraryItem, SongListSort, SortOrder, Song } from '/@/renderer/api/types';
|
||||||
|
|
||||||
const mpvPlayer = isElectron() ? window.electron.mpvPlayer : null;
|
const mpvPlayer = isElectron() ? window.electron.mpvPlayer : null;
|
||||||
const utils = isElectron() ? window.electron.utils : null;
|
const utils = isElectron() ? window.electron.utils : null;
|
||||||
|
@ -28,7 +28,7 @@ export const useHandlePlayQueueAdd = () => {
|
||||||
// const fetchId = itemCount > 1 ? nanoid() : null;
|
// const fetchId = itemCount > 1 ? nanoid() : null;
|
||||||
|
|
||||||
if (options.byItemType) {
|
if (options.byItemType) {
|
||||||
let songsList;
|
let songsList: any;
|
||||||
let queryFilter: any;
|
let queryFilter: any;
|
||||||
let queryKey: any;
|
let queryKey: any;
|
||||||
|
|
||||||
|
@ -94,8 +94,8 @@ export const useHandlePlayQueueAdd = () => {
|
||||||
|
|
||||||
queryKey = queryKeys.songs.list(server?.id, queryFilter);
|
queryKey = queryKeys.songs.list(server?.id, queryFilter);
|
||||||
} else if (options.byItemType.type === LibraryItem.SONG) {
|
} else if (options.byItemType.type === LibraryItem.SONG) {
|
||||||
queryFilter = options.byItemType.id;
|
queryFilter = { id: options.byItemType.id };
|
||||||
queryKey = queryKeys.songs.list(server?.id, queryFilter);
|
queryKey = queryKeys.songs.detail(server?.id, queryFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -115,6 +115,20 @@ export const useHandlePlayQueueAdd = () => {
|
||||||
staleTime: 1000 * 60,
|
staleTime: 1000 * 60,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
} else if (options.byItemType?.type === LibraryItem.SONG) {
|
||||||
|
const song = (await queryClient.fetchQuery(queryKey, async ({ signal }) =>
|
||||||
|
api.controller.getSongDetail({
|
||||||
|
apiClientProps: {
|
||||||
|
server,
|
||||||
|
signal,
|
||||||
|
},
|
||||||
|
query: queryFilter,
|
||||||
|
}),
|
||||||
|
)) as Song;
|
||||||
|
|
||||||
|
if (song) {
|
||||||
|
songsList = { items: [song], startIndex: 0, totalRecordCount: 1 };
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
songsList = await queryClient.fetchQuery(
|
songsList = await queryClient.fetchQuery(
|
||||||
queryKey,
|
queryKey,
|
||||||
|
@ -140,8 +154,7 @@ export const useHandlePlayQueueAdd = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!songsList) return toast.warn({ message: 'No songs found' });
|
if (!songsList) return toast.warn({ message: 'No songs found' });
|
||||||
|
songs = songsList.items?.map((song: Song) => ({ ...song, uniqueId: nanoid() }));
|
||||||
songs = songsList.items?.map((song) => ({ ...song, uniqueId: nanoid() }));
|
|
||||||
} else if (options.byData) {
|
} else if (options.byData) {
|
||||||
songs = options.byData.map((song) => ({ ...song, uniqueId: nanoid() }));
|
songs = options.byData.map((song) => ({ ...song, uniqueId: nanoid() }));
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue