'update'
[vchess.git] / client / src / components / ChallengeList.vue
CommitLineData
85e5b5c1 1<template lang="pug">
7aa548e7
BA
2div
3 table
4f887105
BA
4 thead
5 tr
602d6bef
BA
6 th {{ st.tr["Variant"] }}
7 th {{ st.tr["From"] }}
8 th {{ st.tr["To"] }}
f44fd3bf 9 th {{ st.tr["Cadence"] }}
4f887105
BA
10 tbody
11 tr(v-for="c in sortedChallenges" @click="$emit('click-challenge',c)")
12 td(data-label="Variant") {{ c.vname }}
26f3a887 13 td(data-label="From") {{ c.from.name || "@nonymous" }}
4f887105 14 td(data-label="To") {{ c.to }}
71468011 15 td(data-label="Cadence") {{ c.cadence }}
85e5b5c1
BA
16</template>
17
18<script>
0b0dc040 19import { store } from "@/store";
85e5b5c1
BA
20export default {
21 name: "my-challenge-list",
dac39588 22 props: ["challenges"],
0b0dc040
BA
23 data: function() {
24 return {
25 st: store.state,
26 };
27 },
28 computed: {
29 sortedChallenges: function() {
30 // Show in order: challenges I sent, challenges I received, other challenges
31 let augmentedChalls = this.challenges.map(c => {
32 let priority = 0;
33 if (c.to == this.st.user.name)
34 priority = 1;
35 else if (c.from.id == this.st.user.id || c.from.sid == this.st.user.sid)
36 priority = 2;
37 return Object.assign({}, c, {priority: priority});
38 });
39 return augmentedChalls.sort((c1,c2) => { return c2.priority - c1.priority; });
40 },
41 },
85e5b5c1 42};
85e5b5c1 43</script>