aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/AniList.cpp
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-08-17 14:55:10 +0200
committerdec05eba <dec05eba@protonmail.com>2021-08-17 14:55:10 +0200
commitdf95eccc5e8ef62ad9c83a925adc83926491dfb3 (patch)
tree324ce8c2f204f55a4758c93c1110bb4e395159d8 /src/plugins/AniList.cpp
parent37e0de2d586099fba5736b13dfb945db5f54fe94 (diff)
AniList: separate anime and manga searches to different tabs
Diffstat (limited to 'src/plugins/AniList.cpp')
-rw-r--r--src/plugins/AniList.cpp33
1 files changed, 6 insertions, 27 deletions
diff --git a/src/plugins/AniList.cpp b/src/plugins/AniList.cpp
index fe9a62f..1523129 100644
--- a/src/plugins/AniList.cpp
+++ b/src/plugins/AniList.cpp
@@ -10,7 +10,7 @@ namespace QuickMedia {
static const std::string search_query_graphql = R"END(
query ($page: Int, $perPage: Int, $search: String) {
Page (page: $page, perPage: $perPage) {
- media (search: $search) {
+ media (search: $search, type: %TYPE%) {
id
type
format
@@ -152,11 +152,6 @@ query ($id: Int, $page: Int, $perPage: Int) {
}
)END";
- enum class AniListMediaType {
- ANIME,
- MANGA
- };
-
static const char *month_names[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
static bool in_range(int value, int min, int max) {
return value >= min && value <= max;
@@ -438,8 +433,11 @@ query ($id: Int, $page: Int, $perPage: Int) {
variables_json["perPage"] = 20;
variables_json["search"] = str;
+ std::string query = search_query_graphql;
+ string_replace_all(query, "%TYPE%", media_type == AniListMediaType::ANIME ? "ANIME" : "MANGA");
+
Json::Value request_json(Json::objectValue);
- request_json["query"] = search_query_graphql;
+ request_json["query"] = std::move(query);
request_json["variables"] = std::move(variables_json);
Json::StreamWriterBuilder json_builder;
@@ -484,32 +482,13 @@ query ($id: Int, $page: Int, $perPage: Int) {
if(!media_list_json.isArray())
return SearchResult::ERR;
- BodyItems anime_items;
- BodyItems manga_items;
for(const Json::Value &media_json : media_list_json) {
AniListMediaType media_type;
auto body_item = media_json_to_body_item(media_json, ThumbnailSize::MEDIUM, media_type);
if(!body_item)
continue;
- if(media_type == AniListMediaType::ANIME)
- anime_items.push_back(std::move(body_item));
- else if(media_type == AniListMediaType::MANGA)
- manga_items.push_back(std::move(body_item));
- }
-
- if(!anime_items.empty()) {
- auto anime_title_item = BodyItem::create("");
- anime_title_item->set_author("------------------------ Anime ------------------------");
- result_items.push_back(std::move(anime_title_item));
- result_items.insert(result_items.end(), std::move_iterator(anime_items.begin()), std::move_iterator(anime_items.end()));
- }
-
- if(!manga_items.empty()) {
- auto manga_title_item = BodyItem::create("");
- manga_title_item->set_author("------------------------ Manga ------------------------");
- result_items.push_back(std::move(manga_title_item));
- result_items.insert(result_items.end(), std::move_iterator(manga_items.begin()), std::move_iterator(manga_items.end()));
+ result_items.push_back(std::move(body_item));
}
return SearchResult::OK;