diff options
author | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-11-28 00:30:22 +0100 |
---|---|---|
committer | Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com> | 2019-11-28 00:30:22 +0100 |
commit | a12cffe8d8a67658df93eec8286485247e5d7bff (patch) | |
tree | 3757440cfa77eb1c5e0e67b27b0862f761e79093 /components/Ranking/RankingList.vue | |
parent | 72549ed7b81fc01445fecdb7889bab4cf2a1590f (diff) | |
download | puszcza-a12cffe8d8a67658df93eec8286485247e5d7bff.tar.gz puszcza-a12cffe8d8a67658df93eec8286485247e5d7bff.zip |
Add ranking list
Diffstat (limited to 'components/Ranking/RankingList.vue')
-rw-r--r-- | components/Ranking/RankingList.vue | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/components/Ranking/RankingList.vue b/components/Ranking/RankingList.vue new file mode 100644 index 0000000..68fdb16 --- /dev/null +++ b/components/Ranking/RankingList.vue @@ -0,0 +1,56 @@ +<template> + <ol class="ranking-list"> + <ranking-first-entry + :troop="sortedScores[0].troop" + :points="sortedScores[0].points" + /> + <ranking-entry + v-for="score in sortedScores.slice(1)" + :key="score.troop" + :troop="score.troop" + :points="score.points" + /> + </ol> +</template> + +<script> +import RankingFirstEntry from './RankingFirstEntry' +import RankingEntry from './RankingEntry' + +function compare(a, b) { + return b.points - a.points +} + +export default { + name: 'RankingList', + components: { + RankingEntry, + RankingFirstEntry + }, + props: { + scores: { + type: Array, //i.e. [{troop: "Troop 1", points: 12}, {troop: "Troop 2", points: 22}] + required: true + } + }, + computed: { + sortedScores() { + return [...this.scores].sort(compare) + } + } +} +</script> + +<style scoped> +.ranking-list { + display: flex; + flex-direction: column; + align-items: center; + margin: 10px; + padding: 0; + padding-inline-start: 0; + + width: 100%; + max-width: 200px; +} +</style> |