From a12cffe8d8a67658df93eec8286485247e5d7bff Mon Sep 17 00:00:00 2001
From: Patryk Niedźwiedziński <pniedzwiedzinski19@gmail.com>
Date: Thu, 28 Nov 2019 00:30:22 +0100
Subject: Add ranking list

---
 components/Ranking/RankingList.vue | 56 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)
 create mode 100644 components/Ranking/RankingList.vue

(limited to 'components/Ranking/RankingList.vue')

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>
-- 
cgit 1.4.1

