fix(ui): Refresh mod list when changing filtering options

This commit is contained in:
flow 2022-04-02 19:21:02 -03:00
parent c730fd6e5f
commit 5cb0e75093
5 changed files with 32 additions and 9 deletions

View File

@ -61,10 +61,9 @@ class ModAPI {
{
QString s;
for(auto& ver : mcVersions){
s += ver.toString();
if(ver != mcVersions.back())
s += ",";
s += QString("%1,").arg(ver.toString());
}
s.remove(s.length() - 1, 1); //remove last comma
return s;
}
};

View File

@ -22,12 +22,12 @@ class ModrinthAPI : public NetworkModAPI {
"limit=25&"
"query=%2&"
"index=%3&"
"facets=[[\"categories:%4\"],[\"versions:%5\"],[\"project_type:mod\"]]")
"facets=[[\"categories:%4\"],[%5],[\"project_type:mod\"]]")
.arg(args.offset)
.arg(args.search)
.arg(args.sorting)
.arg(getModLoaderString(args.mod_loader))
.arg(getGameVersionsString(args.versions));
.arg(getGameVersionsArray(args.versions));
};
inline auto getVersionsURL(VersionSearchArgs& args) const -> QString override
@ -40,6 +40,16 @@ class ModrinthAPI : public NetworkModAPI {
.arg(getModLoaderString(args.loader));
};
auto getGameVersionsArray(std::list<Version> mcVersions) const -> QString
{
QString s;
for(auto& ver : mcVersions){
s += QString("\"versions:%1\",").arg(ver.toString());
}
s.remove(s.length() - 1, 1); //remove last comma
return s;
}
static auto getModLoaderString(ModLoaderType type) -> const QString
{
if (type == Unspecified)

View File

@ -75,11 +75,8 @@ void ListModel::performPaginatedSearch()
{ nextSearchOffset, currentSearchTerm, getSorts()[currentSort], profile->getModLoader(), getMineVersions() });
}
void ListModel::searchWithTerm(const QString& term, const int sort)
void ListModel::refresh()
{
if (currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull() && currentSort == sort) { return; }
currentSearchTerm = term;
currentSort = sort;
if (jobPtr) {
jobPtr->abort();
searchState = ResetRequested;
@ -94,6 +91,15 @@ void ListModel::searchWithTerm(const QString& term, const int sort)
performPaginatedSearch();
}
void ListModel::searchWithTerm(const QString& term, const int sort)
{
if (currentSearchTerm == term && currentSearchTerm.isNull() == term.isNull() && currentSort == sort) { return; }
currentSearchTerm = term;
currentSort = sort;
refresh();
}
void ListModel::getLogo(const QString& logo, const QString& logoUrl, LogoCallback callback)
{
if (m_logoMap.contains(logo)) {

View File

@ -34,6 +34,7 @@ class ListModel : public QAbstractListModel {
/* Ask the API for more information */
void fetchMore(const QModelIndex& parent) override;
void refresh();
void searchWithTerm(const QString& term, const int sort);
void requestModVersions(const ModPlatform::IndexedPack& current);

View File

@ -62,6 +62,13 @@ void ModPage::filterMods()
filter_dialog.execWithInstance(static_cast<MinecraftInstance*>(m_instance));
m_filter = filter_dialog.getFilter();
listModel->refresh();
if(ui->versionSelectionBox->count() > 0){
ui->versionSelectionBox->clear();
updateModVersions();
}
}
void ModPage::triggerSearch()