aboutsummaryrefslogtreecommitdiff
path: root/src
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
parent37e0de2d586099fba5736b13dfb945db5f54fe94 (diff)
AniList: separate anime and manga searches to different tabs
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp3
-rw-r--r--src/plugins/AniList.cpp33
2 files changed, 8 insertions, 28 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 79f6d51..6be7dab 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -1214,7 +1214,8 @@ namespace QuickMedia {
body->set_items(std::move(body_items));
tabs.push_back(Tab{std::move(body), std::make_unique<HotExamplesLanguageSelectPage>(this), create_search_bar("Search...", SEARCH_DELAY_FILTER)});
} else if(strcmp(plugin_name, "anilist") == 0) {
- tabs.push_back(Tab{create_body(), std::make_unique<AniListSearchPage>(this), create_search_bar("Search...", 300)});
+ tabs.push_back(Tab{create_body(), std::make_unique<AniListSearchPage>(this, AniListMediaType::ANIME), create_search_bar("Search...", 300)});
+ tabs.push_back(Tab{create_body(), std::make_unique<AniListSearchPage>(this, AniListMediaType::MANGA), create_search_bar("Search...", 300)});
} else if(strcmp(plugin_name, "file-manager") == 0) {
auto file_manager_page = std::make_unique<FileManagerPage>(this, fm_mime_type, file_selection_handler);
if(!file_manager_page->set_current_directory(file_manager_start_dir))
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;