diff --git a/app/Http/Controllers/UsersController.php b/app/Http/Controllers/UsersController.php index 022b03a43..c78066a80 100644 --- a/app/Http/Controllers/UsersController.php +++ b/app/Http/Controllers/UsersController.php @@ -151,12 +151,10 @@ class UsersController extends Controller public function beatmapsets($id, $type) { - $this->parsePaginationParams(6); + $this->parsePaginationParams(); switch ($type) { case 'most_played': - $this->parsePaginationParams(5); - return $this->mostPlayedBeatmapsets($this->user, $this->perPage, $this->offset); case 'favourite': @@ -169,8 +167,6 @@ class UsersController extends Controller return $this->unrankedBeatmapsets($this->user, $this->perPage, $this->offset); case 'graveyard': - $this->parsePaginationParams(2); - return $this->graveyardBeatmapsets($this->user, $this->perPage, $this->offset); default: @@ -180,7 +176,7 @@ class UsersController extends Controller public function kudosu($id) { - $this->parsePaginationParams(5); + $this->parsePaginationParams(); return $this->recentKudosu($this->user, $this->perPage, $this->offset); } @@ -300,7 +296,7 @@ class UsersController extends Controller return [$friend, $friend->mutual ?? false]; } - private function parsePaginationParams($perPage) + private function parsePaginationParams() { $this->user = User::lookup(Request::route('user'), 'id'); if ($this->user === null || !priv_check('UserShow', $this->user)->can()) { @@ -312,12 +308,13 @@ class UsersController extends Controller abort(404); } - $this->offset = get_int(Request::input('offset')); + $this->offset = get_int(Request::input('offset')) ?? 0; + $perPage = clamp(get_int(request('limit')) ?? 5, 1, 10); if ($this->offset >= $this->maxResults) { $this->perPage = 0; } else { - $this->perPage = min($perPage, $this->maxResults - $this->offset); + $this->perPage = min($perPage, $this->maxResults + 1 - $this->offset); } } diff --git a/resources/assets/coffee/osu_common.coffee b/resources/assets/coffee/osu_common.coffee index 6c9742e74..ea9d8591e 100644 --- a/resources/assets/coffee/osu_common.coffee +++ b/resources/assets/coffee/osu_common.coffee @@ -248,9 +248,10 @@ uuid: -> Turbolinks.uuid() # no point rolling our own - updateQueryString: (key, value, url = window.location.href) -> - urlObj = new URL(url, document.location.origin) - urlObj.searchParams.set(key, value) + updateQueryString: (url, params) -> + urlObj = new URL(url ? window.location.href, document.location.origin) + for own key, value of params + urlObj.searchParams.set(key, value) return urlObj.href diff --git a/resources/assets/coffee/react/profile-page/main.coffee b/resources/assets/coffee/react/profile-page/main.coffee index b7a996082..75686421e 100644 --- a/resources/assets/coffee/react/profile-page/main.coffee +++ b/resources/assets/coffee/react/profile-page/main.coffee @@ -249,12 +249,15 @@ class ProfilePage.Main extends React.PureComponent paginationState[propertyName].loading = true @setState showMorePagination: paginationState, -> - $.get osu.updateQueryString('offset', offset, url), (data) => + $.get osu.updateQueryString(url, offset: offset, limit: perPage + 1), (data) => state = _.cloneDeep(@state[propertyName]).concat(data) + hasMore = data.length > perPage && state.length < maxResults + + state.pop() if hasMore paginationState = _.cloneDeep @state.showMorePagination paginationState[propertyName].loading = false - paginationState[propertyName].hasMore = data.length == perPage && state.length < maxResults + paginationState[propertyName].hasMore = hasMore @setState "#{propertyName}": state