done
This commit is contained in:
parent
fd235b56c6
commit
1ed1189bec
2 changed files with 20 additions and 18 deletions
|
|
@ -12,10 +12,10 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-4">
|
<div class="col-4">
|
||||||
<Leaderboard :title="'Highscore'" :leaderboard="this.highscoreLeaderboard"></Leaderboard>
|
<Leaderboard type="highscore"></Leaderboard>
|
||||||
</div>
|
</div>
|
||||||
<div class="offset-4 col-4">
|
<div class="offset-4 col-4">
|
||||||
<Leaderboard :title="'Total Playtime'" :leaderboard="this.totalPlaytimeLeaderboard"></Leaderboard>
|
<Leaderboard type="totalplaytime"></Leaderboard>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -55,15 +55,9 @@ export default defineComponent({
|
||||||
async fetchUserScores() {
|
async fetchUserScores() {
|
||||||
return await this.fetchFromApi(`/user/${this.userId}/scores`, "GET");
|
return await this.fetchFromApi(`/user/${this.userId}/scores`, "GET");
|
||||||
},
|
},
|
||||||
async fetchLeaderboard(type: "highscore" | "totalplaytime") {
|
|
||||||
return await this.fetchFromApi(`/leaderboard/${type}`, "GET");
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
async created() {
|
async created() {
|
||||||
this.userScores = await this.fetchUserScores();
|
this.userScores = await this.fetchUserScores();
|
||||||
this.highscoreLeaderboard = await this.fetchLeaderboard("highscore")
|
|
||||||
this.totalPlaytimeLeaderboard = await this.fetchLeaderboard("totalplaytime")
|
|
||||||
console.log(this)
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<h3 class="col-10"><strong>{{ title }}</strong></h3>
|
<h3 class="col-10"><strong>{{ this.title() }}</strong></h3>
|
||||||
<div class="col-1">
|
<div class="col-1">
|
||||||
<Button @click="prevPage" text="<"></Button>
|
<Button @click="prevPage" text="<"></Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -9,7 +9,7 @@
|
||||||
<Button @click="nextPage" text=">"></Button>
|
<Button @click="nextPage" text=">"></Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row" v-for="entry in page" :key="entry.rank" >
|
<div class="row" v-for="entry in this.page" :key="entry.rank" >
|
||||||
<LeaderboardEntry :entry="entry" ></LeaderboardEntry>
|
<LeaderboardEntry :entry="entry" ></LeaderboardEntry>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -29,29 +29,37 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
pageNumber: 0,
|
pageNumber: 0,
|
||||||
entriesPerPage: 3,
|
entriesPerPage: 5,
|
||||||
page: [],
|
page: []
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
props: {
|
props: {
|
||||||
title: String,
|
type: "totalplaytime" | "highscore",
|
||||||
leaderboard: Array,
|
},
|
||||||
|
created() {
|
||||||
|
this.updatePage();
|
||||||
},
|
},
|
||||||
updated() {
|
updated() {
|
||||||
this.updatePage()
|
this.updatePage()
|
||||||
console.log(this.leaderboard)
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
async fetchPage() {
|
||||||
|
let res = await fetch(`http://localhost:3000/leaderboard/${this.type}?pagination=true&entriesPerPage=${this.entriesPerPage}&page=${this.pageNumber}`, {method: "GET"});
|
||||||
|
return await res.json();
|
||||||
|
},
|
||||||
|
title() {
|
||||||
|
return this.type === "totalplaytime" ? "Total Playtime" : "Highscore";
|
||||||
|
},
|
||||||
nextPage() {
|
nextPage() {
|
||||||
if (this.pageNumber < (this.leaderboard.length / this.entriesPerPage) - 1) this.pageNumber++;
|
this.pageNumber++;
|
||||||
this.updatePage();
|
this.updatePage();
|
||||||
},
|
},
|
||||||
prevPage() {
|
prevPage() {
|
||||||
if (this.pageNumber > 0) this.pageNumber--;
|
if (this.pageNumber > 0) this.pageNumber--;
|
||||||
this.updatePage();
|
this.updatePage();
|
||||||
},
|
},
|
||||||
updatePage() {
|
async updatePage() {
|
||||||
let tempPage = this.leaderboard.slice(this.entriesPerPage * this.pageNumber, this.entriesPerPage * (this.pageNumber + 1));
|
let tempPage = await this.fetchPage();
|
||||||
for (let i = 0; i < this.entriesPerPage; i++) {
|
for (let i = 0; i < this.entriesPerPage; i++) {
|
||||||
this.page.pop()
|
this.page.pop()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue