mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-19 22:51:30 +02:00
Move "FP included" logic to SearchSavesRequest
This commit is contained in:
@@ -83,6 +83,7 @@ namespace http
|
||||
|
||||
SearchSavesRequest::SearchSavesRequest(int start, int count, ByteString query, Period period, Sort sort, Category category) : APIRequest(Url(start, count, query, period, sort, category), authUse, false)
|
||||
{
|
||||
includesFp = category == categoryNone && period == http::allSaves && sort == http::sortByVotes && query == "";
|
||||
}
|
||||
|
||||
std::pair<int, std::vector<std::unique_ptr<SaveInfo>>> SearchSavesRequest::Finish()
|
||||
|
@@ -7,9 +7,16 @@ namespace http
|
||||
{
|
||||
class SearchSavesRequest : public APIRequest
|
||||
{
|
||||
bool includesFp;
|
||||
|
||||
public:
|
||||
SearchSavesRequest(int start, int count, ByteString query, Period period, Sort sort, Category category);
|
||||
|
||||
bool GetIncludesFp() const
|
||||
{
|
||||
return includesFp;
|
||||
}
|
||||
|
||||
std::pair<int, std::vector<std::unique_ptr<SaveInfo>>> Finish();
|
||||
};
|
||||
}
|
||||
|
@@ -15,6 +15,7 @@ SearchModel::SearchModel():
|
||||
currentSort(http::sortByVotes),
|
||||
currentPage(1),
|
||||
resultCount(0),
|
||||
includesFp(false),
|
||||
showOwn(false),
|
||||
showFavourite(false),
|
||||
showTags(true)
|
||||
@@ -37,6 +38,7 @@ void SearchModel::BeginSearchSaves(int start, int count, String query, http::Per
|
||||
resultCount = 0;
|
||||
searchSaves = std::make_unique<http::SearchSavesRequest>(start, count, query.ToUtf8(), period, sort, category);
|
||||
searchSaves->Start();
|
||||
includesFp = searchSaves->GetIncludesFp();
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<SaveInfo>> SearchModel::EndSearchSaves()
|
||||
@@ -96,10 +98,18 @@ bool SearchModel::UpdateSaveList(int pageNumber, String query)
|
||||
//resultCount = 0;
|
||||
currentPage = pageNumber;
|
||||
|
||||
if(pageNumber == 1 && !showOwn && !showFavourite && currentPeriod == http::allSaves && currentSort == http::sortByVotes && query == "")
|
||||
SetShowTags(true);
|
||||
else
|
||||
SetShowTags(false);
|
||||
auto category = http::categoryNone;
|
||||
if (showFavourite)
|
||||
{
|
||||
category = http::categoryFavourites;
|
||||
}
|
||||
if (showOwn && Client::Ref().GetAuthUser().UserID)
|
||||
{
|
||||
category = http::categoryMyOwn;
|
||||
}
|
||||
BeginSearchSaves((currentPage-1)*20, 20, lastQuery, currentPeriod, currentSort, category);
|
||||
|
||||
SetShowTags(includesFp && pageNumber == 1);
|
||||
|
||||
notifySaveListChanged();
|
||||
notifyTagListChanged();
|
||||
@@ -112,16 +122,6 @@ bool SearchModel::UpdateSaveList(int pageNumber, String query)
|
||||
BeginGetTags(0, 24, "");
|
||||
}
|
||||
|
||||
auto category = http::categoryNone;
|
||||
if (showFavourite)
|
||||
{
|
||||
category = http::categoryFavourites;
|
||||
}
|
||||
if (showOwn && Client::Ref().GetAuthUser().UserID)
|
||||
{
|
||||
category = http::categoryMyOwn;
|
||||
}
|
||||
BeginSearchSaves((currentPage-1)*20, 20, lastQuery, currentPeriod, currentSort, category);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -307,8 +307,5 @@ void SearchModel::notifySelectedChanged()
|
||||
|
||||
int SearchModel::GetPageCount()
|
||||
{
|
||||
if (!showOwn && !showFavourite && currentPeriod == http::allSaves && currentSort == http::sortByVotes && lastQuery == "")
|
||||
return std::max(1, (int)(ceil(resultCount/20.0f))+1); //add one for front page (front page saves are repeated twice)
|
||||
else
|
||||
return std::max(1, (int)(ceil(resultCount/20.0f)));
|
||||
return std::max(1, (int)(ceil(resultCount/20.0f)) + (includesFp ? 1 : 0)); //add one for front page (front page saves are repeated twice)
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ private:
|
||||
std::vector<std::pair<ByteString, int> > tagList;
|
||||
int currentPage;
|
||||
int resultCount;
|
||||
bool includesFp;
|
||||
bool showOwn;
|
||||
bool showFavourite;
|
||||
bool showTags;
|
||||
|
Reference in New Issue
Block a user