Skip to content

Commit

Permalink
rank pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
arily committed Aug 20, 2023
1 parent 285a45a commit e226a0e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/pages/leaderboard/[[mode]].vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const selected = shallowRef<Required<SwitcherPropType<LeaderboardRankingSystem>>
})
const { data: total, refresh: refreshCount } = await app$.$client.rank.countLeaderboard.useQuery(selected)
const totalPages = computed(() => Math.min(Math.ceil(total.value / perPage), 5))
const {
data: table,
pending,
Expand All @@ -68,9 +70,9 @@ useHead({
})
function boundaryPage() {
const outOfRange = page.value * perPage - perPage > total.value
const outOfRange = page.value > totalPages.value
if (outOfRange) {
page.value = Math.floor(total.value / perPage)
page.value = totalPages.value
}
}
Expand Down Expand Up @@ -190,7 +192,7 @@ zh-CN:
</h2>
</div>
<div class="join mx-auto outline outline-2">
<input v-for="i in 5" :key="`pagination-${i}`" class="join-item btn btn-ghost checked:outline outline-2" type="radio" name="options" :aria-label="i.toString()" @click="reloadPage(i)">
<input v-for="i in totalPages" :key="`pagination-${i}`" class="join-item btn btn-ghost checked:outline outline-2" type="radio" :checked="page === i" name="options" :aria-label="i.toString()" @click="reloadPage(i)">
</div>
</div>
</div>
Expand Down
7 changes: 5 additions & 2 deletions src/server/backend/bancho.py/server/rank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,15 @@ export class DatabaseRankProvider implements Base<Id> {
const start = page * pageSize
const result = await this.db.stat.findMany({
where: {
pp: rankingSystem === Rank.PPv2 ? { gt: 0 } : undefined,
rankedScore: rankingSystem === Rank.RankedScore ? { gt: 0 } : undefined,
totalScore: rankingSystem === Rank.TotalScore ? { gt: 0 } : undefined,
mode: toBanchoPyMode(mode, ruleset),
user: {
priv: {
gt: 2,
},
},
mode: toBanchoPyMode(mode, ruleset),
},
select: {
user: true,
Expand Down Expand Up @@ -118,12 +121,12 @@ export class DatabaseRankProvider implements Base<Id> {
pp: rankingSystem === Rank.PPv2 ? { gt: 0 } : undefined,
rankedScore: rankingSystem === Rank.RankedScore ? { gt: 0 } : undefined,
totalScore: rankingSystem === Rank.TotalScore ? { gt: 0 } : undefined,
mode: toBanchoPyMode(mode, ruleset),
user: {
priv: {
gt: 2,
},
},
mode: toBanchoPyMode(mode, ruleset),
},

})
Expand Down

0 comments on commit e226a0e

Please sign in to comment.