diff options
author | flow <flowlnlnln@gmail.com> | 2022-05-15 20:45:27 -0300 |
---|---|---|
committer | flow <flowlnlnln@gmail.com> | 2022-05-15 20:45:27 -0300 |
commit | 66ce5a4a2d38803bf667d7326f2ffb1bc06bff99 (patch) | |
tree | 6f869df6597db837fbc7ce7efc18e236a5084060 /launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp | |
parent | 7194bb1b8114a2ec96d3cb30a4fe3338f3962d4c (diff) | |
download | PrismLauncher-66ce5a4a2d38803bf667d7326f2ffb1bc06bff99.tar.gz PrismLauncher-66ce5a4a2d38803bf667d7326f2ffb1bc06bff99.tar.bz2 PrismLauncher-66ce5a4a2d38803bf667d7326f2ffb1bc06bff99.zip |
fix: pack sorting and other search parameters
Diffstat (limited to 'launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp')
-rw-r--r-- | launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp index 50974e13..6786b0da 100644 --- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp +++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp @@ -105,11 +105,16 @@ void ModpackListModel::performPaginatedSearch() { // TODO: Move to standalone API NetJob* netJob = new NetJob("Modrinth::SearchModpack", APPLICATION->network()); - auto searchAllUrl = QString( - "%1/search?" + auto searchAllUrl = QString(BuildConfig.MODRINTH_STAGING_URL + + "/search?" + "offset=%1&" + "limit=20&" "query=%2&" + "index=%3&" "facets=[[\"project_type:modpack\"]]") - .arg(BuildConfig.MODRINTH_STAGING_URL, currentSearchTerm); + .arg(nextSearchOffset) + .arg(currentSearchTerm) + .arg(currentSort); netJob->addNetAction(Net::Download::makeByteArray(QUrl(searchAllUrl), &m_all_response)); @@ -148,14 +153,21 @@ void ModpackListModel::refresh() performPaginatedSearch(); } +static std::array<QString, 5> sorts {"relevance", "downloads", "follows", "newest", "updated"}; + void ModpackListModel::searchWithTerm(const QString& term, const int sort) { - if (currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull() && currentSort == sort) { + if(sort > 5 || sort < 0) + return; + + auto sort_str = sorts.at(sort); + + if (currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull() && currentSort == sort_str) { return; } currentSearchTerm = term; - currentSort = sort; + currentSort = sort_str; refresh(); } @@ -255,7 +267,7 @@ void ModpackListModel::searchRequestFailed(QString reason) { if (!jobPtr->first()->m_reply) { // Network error - QMessageBox::critical(nullptr, tr("Error"), tr("A network error occurred. Could not load mods.")); + QMessageBox::critical(nullptr, tr("Error"), tr("A network error occurred. Could not load modpacks.")); } else if (jobPtr->first()->m_reply && jobPtr->first()->m_reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 409) { // 409 Gone, notify user to update QMessageBox::critical(nullptr, tr("Error"), |