Skip to content

Commit

Permalink
В дискографию добавлен пункт все лайки
Browse files Browse the repository at this point in the history
  • Loading branch information
Chimildic committed Jun 29, 2022
1 parent f36ea12 commit 123f289
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
1 change: 1 addition & 0 deletions page/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ <h2>Список изменений YaMuTools</h2>
<h3>Версия 0.8.4</h3>
<hr />
<ul>
<li>В дискографию добавлен пункт "все лайки".</li>
<li>Исправлена некорректная работа чекбокса "больше не напоминать" в уведомлении оставить отзыв. Также увеличен период, при котором оно приходит.</li>
</ul>
</section>
Expand Down
45 changes: 30 additions & 15 deletions script/tool/collector.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,6 @@ const COLLECTOR_ARTIST_DROPDOWN = {
{
id: 'artistCollectorMain',
items: [
{
title: PERIOD.DEFAULT.title,
handler: () => collectDiscographyOfPeriod(PERIOD.DEFAULT),
},
{
title: PERIOD.ONE_YEAR.title,
handler: () => collectDiscographyOfPeriod(PERIOD.ONE_YEAR),
Expand All @@ -275,6 +271,14 @@ const COLLECTOR_ARTIST_DROPDOWN = {
title: PERIOD.FIVE_YEAR.title,
handler: () => collectDiscographyOfPeriod(PERIOD.FIVE_YEAR),
},
{
title: PERIOD.DEFAULT.title,
handler: () => collectDiscographyOfPeriod(PERIOD.DEFAULT),
},
{
title: 'Все лайки',
handler: () => collectDiscographyLikes(),
},
],
},
],
Expand Down Expand Up @@ -601,20 +605,29 @@ async function collectDiscoveryAlbums(playlist) {
}
}

function collectDiscographyLikes() {
collectDiscography(PERIOD.DEFAULT, 'likes');
}

function collectDiscographyOfPeriod(period) {
selectedPlaylist = PLAYLIST.discography;
selectedPlaylist.period = period;
collectDiscography();
collectDiscography(period, 'all');
}

function collectDiscography() {
function collectDiscography(period, type) {
selectedPlaylist = PLAYLIST.discography;
selectedPlaylist.period = period;
fireCollectorSwal(selectedPlaylist.title);
toggleDropdown('artistCollectorMain');
receiveAlbumsOfArtist((response) => {

receiveAlbumsOfArtist(async (response) => {
selectedPlaylist.albums = response.albums;
filterAlbumsByPeriod(selectedPlaylist.period);
let trackIds = formatAlbumTracksToIds(selectedPlaylist.albums);
if (type == 'likes') {
trackIds = await removeAllExceptLikes(trackIds);
}
selectedPlaylist.title += ' ' + response.artist.name;
selectedPlaylist.trackIds = formatAlbumTracksToIds(selectedPlaylist.albums);
selectedPlaylist.trackIds = trackIds
patchPlaylistWithRedirect(selectedPlaylist);
});
}
Expand Down Expand Up @@ -795,11 +808,13 @@ function removeFav(ids, callback) {
removeDislikeIds(ids, (trackIds) => removeLikeIds(trackIds, callback));
}

function removeAllExceptLikes(trackIds, callback) {
receiveFavoriteTrackIds(FAV_TYPE.LIKE, (likeIds) => {
let filteredTrackIds = trackIds.filter((item) => likeIds.some((likeTrack) => likeTrack.id == item.id));
callback(filteredTrackIds);
});
function removeAllExceptLikes(trackIds) {
return new Promise(resolve => {
receiveFavoriteTrackIds(FAV_TYPE.LIKE, (likeIds) => {
let filteredTrackIds = trackIds.filter((item) => likeIds.some((likeTrack) => likeTrack.id == item.id));
resolve(filteredTrackIds);
});
})
}

function removeFavoriteTrackIds(trackIds, type, callback) {
Expand Down
4 changes: 2 additions & 2 deletions script/tool/playlist/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function onClickControlDislikesTracks(playlist) {
removeFAV: 'Удалить оба типа',
removeAllExceptLikes: 'Оставить только лайки',
},
}).then((action) => {
}).then(async (action) => {
if (!action.isConfirmed) {
return;
}
Expand All @@ -73,7 +73,7 @@ function onClickControlDislikesTracks(playlist) {
} else if (action.value == 'removeFAV') {
removeFav(ids, callback);
} else if (action.value == 'removeAllExceptLikes') {
removeAllExceptLikes(ids, callback);
callback(await removeAllExceptLikes(ids));
}
});

Expand Down

0 comments on commit 123f289

Please sign in to comment.