Feat/personal highscore #44

Merged
KevinMidboe merged 19 commits from feat/personal-highscore into master 2020-10-11 16:19:52 +00:00
Showing only changes of commit 8ef1a2dd88 - Show all commits

View File

@@ -3,9 +3,9 @@
<h1>Vinlottis highscore</h1> <h1>Vinlottis highscore</h1>
<div class="backdrop"> <div class="backdrop">
<router-link to="/highscore"> <a @click="navigateBack" @keydown.enter="navigateBack">
<h3 class="vin-link go-back">Tilbake til topplisten</h3> <span class="vin-link navigate-back">Tilbake til {{ previousRoute.name }}</span>
</router-link> </a>
<section v-if="winner"> <section v-if="winner">
<h2 class="name">{{ winner.name }}</h2> <h2 class="name">{{ winner.name }}</h2>
@@ -53,19 +53,23 @@ import { getWinnerByName } from "@/api";
import { humanReadableDate, daysAgo } from "@/utils"; import { humanReadableDate, daysAgo } from "@/utils";
export default { export default {
props: {
winnerObject: {
type: Object,
required: false,
default: undefined
}
},
data() { data() {
return { return {
winner: undefined, winner: undefined,
error: undefined error: undefined,
previousRoute: {
default: true,
name: "topplisten",
path: "/highscore"
}
} }
}, },
beforeRouteEnter(to, from, next) {
next(vm => {
if (from.name !== null)
vm.previousRoute = from
})
},
computed: { computed: {
numberOfWins() { numberOfWins() {
return this.winner.highscore.length return this.winner.highscore.length
@@ -79,7 +83,11 @@ export default {
}, },
methods: { methods: {
setWinner(winner) { setWinner(winner) {
this.winner = winner this.winner = {
name: winner.name,
highscore: [],
...winner
}
this.winningColors = this.findWinningColors() this.winningColors = this.findWinningColors()
}, },
smallerWineImage(image) { smallerWineImage(image) {
@@ -103,6 +111,13 @@ export default {
const timestamp = new Date(date).getTime(); const timestamp = new Date(date).getTime();
return `/history/${timestamp}` return `/history/${timestamp}`
}, },
navigateBack() {
if (this.previousRoute.default) {
this.$router.push({ path: this.previousRoute.path });
} else {
this.$router.go(-1);
}
},
humanReadableDate: humanReadableDate, humanReadableDate: humanReadableDate,
daysAgo: daysAgo daysAgo: daysAgo
} }