about summary refs log tree commit diff
path: root/components/Ranking/RankingList.vue
blob: 68fdb1649009b892d35ee813a11d93dec1c886c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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>