diff --git a/src/components/PersonalHighscorePage.vue b/src/components/PersonalHighscorePage.vue index 40fd738..83c241c 100644 --- a/src/components/PersonalHighscorePage.vue +++ b/src/components/PersonalHighscorePage.vue @@ -3,9 +3,9 @@

Vinlottis highscore

- - ⬅ - + + ⬅ Tilbake til {{ previousRoute.name }} +

{{ winner.name }}

@@ -53,19 +53,23 @@ import { getWinnerByName } from "@/api"; import { humanReadableDate, daysAgo } from "@/utils"; export default { - props: { - winnerObject: { - type: Object, - required: false, - default: undefined - } - }, data() { return { 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: { numberOfWins() { return this.winner.highscore.length @@ -79,7 +83,11 @@ export default { }, methods: { setWinner(winner) { - this.winner = winner + this.winner = { + name: winner.name, + highscore: [], + ...winner + } this.winningColors = this.findWinningColors() }, smallerWineImage(image) { @@ -103,6 +111,13 @@ export default { const timestamp = new Date(date).getTime(); return `/history/${timestamp}` }, + navigateBack() { + if (this.previousRoute.default) { + this.$router.push({ path: this.previousRoute.path }); + } else { + this.$router.go(-1); + } + }, humanReadableDate: humanReadableDate, daysAgo: daysAgo }