3 table(v-if="challenges.length > 0")
6 th {{ st.tr["Variant"] }}
8 th {{ st.tr["Cadence"] }}
9 th {{ st.tr["Options"] }}
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)") {{ c.options.abridged || '' }}
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() {
37 // challenges I sent, challenges I received, other challenges
38 let minAdded = Number.MAX_SAFE_INTEGER;
40 let augmentedChalls = this.challenges.map(c => {
42 if (!!c.to && c.to == this.st.user.name) priority = 1;
44 c.from.sid == this.st.user.sid ||
45 (c.from.id > 0 && c.from.id == this.st.user.id)
49 if (c.added < minAdded) minAdded = c.added;
50 if (c.added > maxAdded) maxAdded = c.added;
51 return Object.assign({ priority: priority }, c);
52 // TODO: remove patch soon
53 if (!c.options) c.options = {}
55 const deltaAdded = maxAdded - minAdded;
56 return augmentedChalls.sort((c1, c2) => {
57 return c2.priority - c1.priority + (c2.added - c1.added) / deltaAdded;
62 withWho: function(c) {
63 if (c.from.sid == this.st.user.sid || c.from.id == this.st.user.id)
64 return c.to || this.st.tr["Any player"];
65 return c.from.name || "@nonymous";
67 // TODO: duplicated from Hall
68 getRandomnessClass: function(c) {
69 const opts = c.options;
70 if (opts.randomness === undefined && opts.random === undefined)
72 if (opts.randomness !== undefined)
73 return { ["random-" + opts.randomness]: true };
74 return { ["random-" + (opts.random ? 2 : 0)]: true };
80 <style lang="sass" scoped>
85 // NOTE: the style applied to <tr> element doesn't work
89 background-color: #fcd785
93 background-color: #FEAF9E
95 background-color: #9EB2FE
97 background-color: #A5FE9E