aboutsummaryrefslogtreecommitdiff
path: root/launcher/ui/pages
diff options
context:
space:
mode:
authorflow <flowlnlnln@gmail.com>2022-05-15 20:45:27 -0300
committerflow <flowlnlnln@gmail.com>2022-05-15 20:45:27 -0300
commit66ce5a4a2d38803bf667d7326f2ffb1bc06bff99 (patch)
tree6f869df6597db837fbc7ce7efc18e236a5084060 /launcher/ui/pages
parent7194bb1b8114a2ec96d3cb30a4fe3338f3962d4c (diff)
downloadPrismLauncher-66ce5a4a2d38803bf667d7326f2ffb1bc06bff99.tar.gz
PrismLauncher-66ce5a4a2d38803bf667d7326f2ffb1bc06bff99.tar.bz2
PrismLauncher-66ce5a4a2d38803bf667d7326f2ffb1bc06bff99.zip
fix: pack sorting and other search parameters
Diffstat (limited to 'launcher/ui/pages')
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthModel.cpp24
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthModel.h2
-rw-r--r--launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp9
3 files changed, 23 insertions, 12 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"),
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h
index e61eae7c..bffea54d 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthModel.h
@@ -104,7 +104,7 @@ class ModpackListModel : public QAbstractListModel {
QStringList m_loadingLogos;
QString currentSearchTerm;
- int currentSort = 0;
+ QString currentSort;
int nextSearchOffset = 0;
enum SearchState { None, CanPossiblyFetchMore, ResetRequested, Finished } searchState = None;
diff --git a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
index a2e18d19..ceddcfb5 100644
--- a/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
+++ b/launcher/ui/pages/modplatform/modrinth/ModrinthPage.cpp
@@ -61,12 +61,11 @@ ModrinthPage::ModrinthPage(NewInstanceDialog* dialog, QWidget* parent) : QWidget
ui->versionSelectionBox->view()->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->versionSelectionBox->view()->parentWidget()->setMaximumHeight(300);
- ui->sortByBox->addItem(tr("Sort by Featured"));
- ui->sortByBox->addItem(tr("Sort by Popularity"));
- ui->sortByBox->addItem(tr("Sort by Last Updated"));
- ui->sortByBox->addItem(tr("Sort by Name"));
- ui->sortByBox->addItem(tr("Sort by Author"));
+ ui->sortByBox->addItem(tr("Sort by Relevance"));
ui->sortByBox->addItem(tr("Sort by Total Downloads"));
+ ui->sortByBox->addItem(tr("Sort by Follows"));
+ ui->sortByBox->addItem(tr("Sort by Newest"));
+ ui->sortByBox->addItem(tr("Sort by Last Updated"));
connect(ui->sortByBox, SIGNAL(currentIndexChanged(int)), this, SLOT(triggerSearch()));
connect(ui->packView->selectionModel(), &QItemSelectionModel::currentChanged, this, &ModrinthPage::onSelectionChanged);