mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-09 20:29:36 +02:00
[bugfix]: do not duplicate tracks when adding to multiple playlists (#300)
This commit is contained in:
@@ -98,7 +98,7 @@ export const AddToPlaylistContextModal = ({
|
|||||||
const handleSubmit = form.onSubmit(async (values) => {
|
const handleSubmit = form.onSubmit(async (values) => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const allSongIds: string[] = [];
|
const allSongIds: string[] = [];
|
||||||
const uniqueSongIds: string[] = [];
|
let totalUniquesAdded = 0;
|
||||||
|
|
||||||
if (albumId && albumId.length > 0) {
|
if (albumId && albumId.length > 0) {
|
||||||
for (const id of albumId) {
|
for (const id of albumId) {
|
||||||
@@ -129,6 +129,8 @@ export const AddToPlaylistContextModal = ({
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (const playlistId of values.playlistId) {
|
for (const playlistId of values.playlistId) {
|
||||||
|
const uniqueSongIds: string[] = [];
|
||||||
|
|
||||||
if (values.skipDuplicates) {
|
if (values.skipDuplicates) {
|
||||||
const query = {
|
const query = {
|
||||||
id: playlistId,
|
id: playlistId,
|
||||||
@@ -155,6 +157,7 @@ export const AddToPlaylistContextModal = ({
|
|||||||
uniqueSongIds.push(songId);
|
uniqueSongIds.push(songId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
totalUniquesAdded += uniqueSongIds.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (values.skipDuplicates ? uniqueSongIds.length > 0 : allSongIds.length > 0) {
|
if (values.skipDuplicates ? uniqueSongIds.length > 0 : allSongIds.length > 0) {
|
||||||
@@ -180,11 +183,15 @@ export const AddToPlaylistContextModal = ({
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const addMessage =
|
||||||
|
values.skipDuplicates &&
|
||||||
|
allSongIds.length * values.playlistId.length !== totalUniquesAdded
|
||||||
|
? `around ${Math.floor(totalUniquesAdded / values.playlistId.length)}`
|
||||||
|
: allSongIds.length;
|
||||||
|
|
||||||
setIsLoading(false);
|
setIsLoading(false);
|
||||||
toast.success({
|
toast.success({
|
||||||
message: `Added ${
|
message: `Added ${addMessage} songs to ${values.playlistId.length} playlist(s)`,
|
||||||
values.skipDuplicates ? uniqueSongIds.length : allSongIds.length
|
|
||||||
} songs to ${values.playlistId.length} playlist(s)`,
|
|
||||||
});
|
});
|
||||||
closeModal(id);
|
closeModal(id);
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
Reference in New Issue
Block a user