mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-15 16:04:19 +02:00
prevent track radio from prepending song in queue
- this behavior relates to when using NEXT or LAST as this will add a duplicate song
This commit is contained in:
@@ -12,10 +12,15 @@ import { Play } from '/@/shared/types/types';
|
|||||||
|
|
||||||
interface PlayTrackRadioActionProps {
|
interface PlayTrackRadioActionProps {
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
skipFirstSong?: boolean;
|
||||||
song: Song;
|
song: Song;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PlayTrackRadioAction = ({ disabled, song }: PlayTrackRadioActionProps) => {
|
export const PlayTrackRadioAction = ({
|
||||||
|
disabled,
|
||||||
|
skipFirstSong,
|
||||||
|
song,
|
||||||
|
}: PlayTrackRadioActionProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const player = usePlayer();
|
const player = usePlayer();
|
||||||
const serverId = useCurrentServerId();
|
const serverId = useCurrentServerId();
|
||||||
@@ -38,13 +43,17 @@ export const PlayTrackRadioAction = ({ disabled, song }: PlayTrackRadioActionPro
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (similarSongs && similarSongs.length > 0) {
|
if (similarSongs && similarSongs.length > 0) {
|
||||||
player.addToQueueByData([song, ...similarSongs], playType);
|
// We need to skip the first song when adding to the queue as NEXT or LAST, otherwise you will have a duplicate song
|
||||||
|
const shouldSkipFirstSong =
|
||||||
|
skipFirstSong && (playType === Play.NEXT || playType === Play.LAST);
|
||||||
|
const queueSongs = shouldSkipFirstSong ? similarSongs : [song, ...similarSongs];
|
||||||
|
player.addToQueueByData(queueSongs, playType);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to load track radio:', error);
|
console.error('Failed to load track radio:', error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[player, queryClient, serverId, song],
|
[player, queryClient, serverId, skipFirstSong, song],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handlePlayTrackRadioNow = useCallback(() => {
|
const handlePlayTrackRadioNow = useCallback(() => {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export const QueueContextMenu = ({ items }: QueueContextMenuProps) => {
|
|||||||
<MoveQueueItemsAction items={items} />
|
<MoveQueueItemsAction items={items} />
|
||||||
<ShuffleItemsAction items={items} />
|
<ShuffleItemsAction items={items} />
|
||||||
<ContextMenu.Divider />
|
<ContextMenu.Divider />
|
||||||
<PlayTrackRadioAction disabled={items.length > 1} song={items[0]} />
|
<PlayTrackRadioAction disabled={items.length > 1} skipFirstSong song={items[0]} />
|
||||||
<ContextMenu.Divider />
|
<ContextMenu.Divider />
|
||||||
<AddToPlaylistAction items={ids} itemType={LibraryItem.SONG} />
|
<AddToPlaylistAction items={ids} itemType={LibraryItem.SONG} />
|
||||||
<ContextMenu.Divider />
|
<ContextMenu.Divider />
|
||||||
|
|||||||
Reference in New Issue
Block a user