[bugfix]: do not duplicate tracks when adding to multiple playlists (#300)
This commit is contained in:
parent
5fdf4c06f9
commit
d7b3d5c0bd
1 changed files with 11 additions and 4 deletions
|
@ -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 a new issue