Skip to content

Commit

Permalink
New artist loading for followed artists
Browse files Browse the repository at this point in the history
  • Loading branch information
kraxarn committed Mar 23, 2024
1 parent 078c7a1 commit 4b15cf4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/include/lib/spotify/api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace lib

//region Follow

void followed_artists(lib::callback<std::vector<lib::spt::artist>> &callback);
void followed_artists(const paged_callback<spt::artist> &callback) const;

void follow(lib::follow_type type, const std::vector<std::string> &ids,
lib::callback<std::string> &callback);
Expand Down
5 changes: 3 additions & 2 deletions lib/src/spotifyapi/follow.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#include "lib/spotify/api.hpp"

void lib::spt::api::followed_artists(lib::callback<std::vector<lib::spt::artist>> &callback)
void lib::spt::api::followed_artists(const paged_callback<spt::artist> &callback) const
{
get_items("me/following?type=artist&limit=50", "artists", callback);
const std::string url("me/following?type=artist&limit=50");
request.get_page<spt::artist>(url, "artists", callback);
}

void lib::spt::api::follow(lib::follow_type type, const std::vector<std::string> &ids,
Expand Down
20 changes: 16 additions & 4 deletions src/list/library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,27 @@ void List::Library::onExpanded(QTreeWidgetItem *item)
}
else if (item->text(0) == followedArtists)
{
spotify.followed_artists([item](const std::vector<lib::spt::artist> &artists)
spotify.followed_artists([item](const lib::result<lib::spt::page<lib::spt::artist>> &result)
{
if (!result.success())
{
StatusMessage::error(QString("Failed to get artists: %1")
.arg(QString::fromStdString(result.message())));

return false;
}

const auto &page = result.value();
std::vector<ListItem::Library> results;
results.reserve(artists.size());
for (const auto &artist: artists)
results.reserve(page.items.size());

for (const auto &artist: page.items)
{
results.emplace_back(artist);
}
List::Library::itemsLoaded(results, item);

itemsLoaded(results, item);
return page.has_next();
});
}
else if (item->text(0) == newReleases)
Expand Down

0 comments on commit 4b15cf4

Please sign in to comment.