3 table(v-if="challenges.length > 0")
6 th {{ st.tr["Variant"] }}
8 th {{ st.tr["Cadence"] }}
9 th {{ st.tr["Random?"] }}
12 v-for="c in sortedChallenges"
13 :class="{toyou:c.priority==1,fromyou:c.priority==2}"
14 @click="$emit('click-challenge',c)"
19 td(:class="getRandomnessClass(c)")
21 | {{ st.tr["No challenges found :( Click on 'New game'!"] }}
25 import { store } from "@/store";
27 name: "my-challenge-list",
28 props: ["challenges"],
35 sortedChallenges: function() {
36 // Show in order: challenges I sent, challenges I received, other challenges
37 let minAdded = Number.MAX_SAFE_INTEGER;
39 let augmentedChalls = this.challenges.map(c => {
41 if (!!c.to && c.to == this.st.user.name) priority = 1;
43 c.from.sid == this.st.user.sid ||
44 (c.from.id > 0 && c.from.id == this.st.user.id)
48 if (c.added < minAdded) minAdded = c.added;
49 if (c.added > maxAdded) maxAdded = c.added;
50 return Object.assign({}, c, { priority: priority });
52 const deltaAdded = maxAdded - minAdded;
53 return augmentedChalls.sort((c1, c2) => {
54 return c2.priority - c1.priority + (c2.added - c1.added) / deltaAdded;
59 withWho: function(c) {
60 if (c.from.sid == this.st.user.sid || c.from.id == this.st.user.id)
61 return c.to || this.st.tr["Any player"];
62 return c.from.name || "@nonymous";
64 getRandomnessClass: function(c) {
66 ["random-" + c.randomness]: true
73 <style lang="sass" scoped>
78 // NOTE: the style applied to <tr> element doesn't work
82 background-color: #fcd785
86 background-color: #FF5733
88 background-color: #2B63B4
90 background-color: #33B42B