Special SVG for berolina pawns
[vchess.git] / client / src / components / ChallengeList.vue
CommitLineData
85e5b5c1 1<template lang="pug">
7aa548e7 2div
1c9826a5 3 table(v-if="challenges.length > 0")
4f887105
BA
4 thead
5 tr
602d6bef 6 th {{ st.tr["Variant"] }}
303ad63c 7 th {{ st.tr["With"] }}
f44fd3bf 8 th {{ st.tr["Cadence"] }}
eb2d61de 9 th {{ st.tr["Options"] }}
4f887105 10 tbody
910d631b
BA
11 tr(
12 v-for="c in sortedChallenges"
13 :class="{toyou:c.priority==1,fromyou:c.priority==2}"
14 @click="$emit('click-challenge',c)"
15 )
bd76b456 16 td {{ c.vname }}
303ad63c 17 td {{ withWho(c) }}
50330595 18 td {{ c.cadence }}
3d9745ae 19 td(:class="getRandomnessClass(c)") {{ c.options.abridged || '' }}
1c9826a5
BA
20 p(v-else)
21 | {{ st.tr["No challenges found :( Click on 'New game'!"] }}
85e5b5c1
BA
22</template>
23
24<script>
0b0dc040 25import { store } from "@/store";
85e5b5c1
BA
26export default {
27 name: "my-challenge-list",
dac39588 28 props: ["challenges"],
0b0dc040
BA
29 data: function() {
30 return {
6808d7a1 31 st: store.state
0b0dc040
BA
32 };
33 },
34 computed: {
35 sortedChallenges: function() {
2c5d7b20
BA
36 // Show in order:
37 // challenges I sent, challenges I received, other challenges
6808d7a1
BA
38 let minAdded = Number.MAX_SAFE_INTEGER;
39 let maxAdded = 0;
0b0dc040
BA
40 let augmentedChalls = this.challenges.map(c => {
41 let priority = 0;
6808d7a1 42 if (!!c.to && c.to == this.st.user.name) priority = 1;
8f4e861c
BA
43 else if (
44 c.from.sid == this.st.user.sid ||
45 (c.from.id > 0 && c.from.id == this.st.user.id)
46 ) {
0b0dc040 47 priority = 2;
8f4e861c 48 }
6808d7a1
BA
49 if (c.added < minAdded) minAdded = c.added;
50 if (c.added > maxAdded) maxAdded = c.added;
81dd1786 51 return Object.assign({ priority: priority }, c);
0b0dc040 52 });
bd76b456 53 const deltaAdded = maxAdded - minAdded;
6808d7a1 54 return augmentedChalls.sort((c1, c2) => {
bd76b456
BA
55 return c2.priority - c1.priority + (c2.added - c1.added) / deltaAdded;
56 });
6808d7a1 57 }
303ad63c
BA
58 },
59 methods: {
60 withWho: function(c) {
61 if (c.from.sid == this.st.user.sid || c.from.id == this.st.user.id)
62 return c.to || this.st.tr["Any player"];
63 return c.from.name || "@nonymous";
7ba4a5bc 64 },
4313762d 65 // TODO: duplicated from Hall
7ba4a5bc 66 getRandomnessClass: function(c) {
4313762d
BA
67 const opts = c.options;
68 if (opts.randomness === undefined && opts.random === undefined)
2eca7311 69 return {};
4313762d
BA
70 if (opts.randomness !== undefined)
71 return { ["random-" + opts.randomness]: true };
72 return { ["random-" + (opts.random ? 2 : 0)]: true };
303ad63c 73 }
6808d7a1 74 }
85e5b5c1 75};
85e5b5c1 76</script>
bd76b456
BA
77
78<style lang="sass" scoped>
1c9826a5
BA
79p
80 text-align: center
81 font-weight: bold
82
910d631b 83// NOTE: the style applied to <tr> element doesn't work
bd76b456
BA
84tr.fromyou > td
85 font-style: italic
86tr.toyou > td
87 background-color: #fcd785
7ba4a5bc
BA
88
89tr > td:last-child
90 &.random-0
eb2d61de 91 background-color: #FEAF9E
7ba4a5bc 92 &.random-1
eb2d61de 93 background-color: #9EB2FE
7ba4a5bc 94 &.random-2
eb2d61de 95 background-color: #A5FE9E
bd76b456 96</style>