6d675a15bb08ddb6879178bf29533c5099f7b816
[vchess.git] / client / src / views / Hall.vue
1 <template lang="pug">
2 main
3 input#modalInfo.modal(type="checkbox")
4 div#infoDiv(
5 role="dialog"
6 data-checkbox="modalInfo"
7 )
8 .card.text-center
9 label.modal-close(for="modalInfo")
10 p(v-html="infoMessage")
11 input#modalAccept.modal(type="checkbox")
12 div#acceptDiv(role="dialog")
13 .card
14 p.text-center
15 span.variantName
16 | {{ curChallToAccept.vname }}
17 | {{ curChallToAccept.options.abridged }}
18 span {{ curChallToAccept.cadence }}
19 span {{ st.tr["with"] + " " + curChallToAccept.from.name }}
20 p.text-center(v-if="!!curChallToAccept.color")
21 | {{ st.tr["Your color:"] + " " + invColor(curChallToAccept.color) }}
22 .diagram(
23 v-if="!!curChallToAccept.fen"
24 v-html="tchallDiag"
25 )
26 .button-group#buttonsTchall(:style="tchallButtonsMargin()")
27 button.acceptBtn(@click="decisionChallenge(true)")
28 span {{ st.tr["Accept challenge?"] }}
29 button.refuseBtn(@click="decisionChallenge(false)")
30 span {{ st.tr["Refuse"] }}
31 input#modalNewgame.modal(
32 type="checkbox"
33 @change="cadenceFocusIfOpened($event)"
34 )
35 div#newgameDiv(
36 role="dialog"
37 data-checkbox="modalNewgame"
38 )
39 .card
40 label#closeNewgame.modal-close(for="modalNewgame")
41 div(@keyup.enter="issueNewChallenge()")
42 fieldset
43 label(for="selectVariant") {{ st.tr["Variant"] }} *
44 select#selectVariant(
45 @change="loadNewchallVariant(trySetNewchallDiag)"
46 v-model="newchallenge.vid"
47 )
48 option(
49 v-for="v in st.variants"
50 :value="v.id"
51 :selected="newchallenge.vid==v.id"
52 )
53 | {{ v.display }}
54 // Variant-specific options (often at least randomness)
55 fieldset(v-if="!!newchallenge.V")
56 div(v-for="select of newchallenge.V.Options.select")
57 label(:for="select.variable + '_opt'") {{ st.tr[select.label] }} *
58 select(:id="select.variable + '_opt'")
59 option(
60 v-for="o of select.options"
61 :value="o.value"
62 :selected="o.value == select.defaut"
63 )
64 | {{ st.tr[o.label] }}
65 div(v-for="check of newchallenge.V.Options.check")
66 label(:for="check.variable + '_opt'") {{ st.tr[check.label] }} *
67 input(
68 :id="check.variable + '_opt'"
69 type="checkbox"
70 :checked="check.defaut")
71 fieldset
72 label(for="cadence") {{ st.tr["Cadence"] }} *
73 div#predefinedCadences
74 button(type="button") 15+5
75 button(type="button") 45+30
76 button(type="button") 3d
77 button(type="button") 7d
78 input#cadence(
79 type="text"
80 v-model="newchallenge.cadence"
81 placeholder="5+0, 1h+30s, 5d ..."
82 )
83 fieldset
84 label(for="memorizeChall") {{ st.tr["Memorize"] }}
85 input#memorizeChall(
86 type="checkbox"
87 v-model="newchallenge.memorize"
88 )
89 fieldset(v-if="st.user.id > 0")
90 label(for="selectPlayers") {{ st.tr["Play with"] }}
91 select#selectPlayersInList(
92 v-model="newchallenge.to"
93 @change="changeChallTarget()"
94 )
95 option(value="")
96 option(
97 v-for="p in Object.values(people)"
98 v-if="!!p.name"
99 :value="p.name"
100 )
101 | {{ p.name }}
102 input#selectPlayers(
103 type="text"
104 v-model="newchallenge.to"
105 )
106 fieldset(v-show="st.user.id > 0 && newchallenge.to.length > 0")
107 label(for="selectColor") {{ st.tr["Color"] }}
108 select#selectColor(v-model="newchallenge.color")
109 option(value='')
110 option(value='w') {{ st.tr["White"] }}
111 option(value='b') {{ st.tr["Black"] }}
112 br
113 input#inputFen(
114 placeholder="FEN"
115 @input="trySetNewchallDiag()"
116 type="text"
117 v-model="newchallenge.fen"
118 )
119 .diagram(v-html="newchallenge.diag")
120 button(@click="issueNewChallenge()") {{ st.tr["Send challenge"] }}
121 input#modalPeople.modal(
122 type="checkbox"
123 @click="toggleSocialColor()"
124 )
125 div#peopleWrap(
126 role="dialog"
127 data-checkbox="modalPeople"
128 )
129 .card
130 label.modal-close(for="modalPeople")
131 #people
132 #players
133 p(
134 v-for="sid in Object.keys(people)"
135 v-if="!!people[sid].name"
136 )
137 UserBio.user-bio(:uid="people[sid].id" :uname="people[sid].name")
138 button.player-action(
139 v-if="isGamer(sid)"
140 @click="watchGame(sid)"
141 )
142 | {{ st.tr["Observe"] }}
143 button.player-action(
144 v-else-if="st.user.sid != sid"
145 :class="{focused: isFocusedOnHall(sid)}"
146 @click="challenge(sid)"
147 )
148 | {{ st.tr["Challenge"] }}
149 p.anonymous @nonymous ({{ anonymousCount() }})
150 #chat
151 Chat(
152 ref="chatcomp"
153 @mychat="processChat"
154 :pastChats="[]"
155 )
156 .clearer
157 .row
158 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
159 .button-group
160 button#peopleBtn(onClick="window.doClick('modalPeople')")
161 | {{ st.tr["Who's there?"] }}
162 button(@click="showNewchallengeForm()")
163 | {{ st.tr["New game"] }}
164 .row(v-if="presetChalls.length > 0")
165 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
166 h4.text-center {{ st.tr["Preset challenges"] }}
167 table
168 thead
169 tr
170 th {{ st.tr["Variant"] }}
171 th {{ st.tr["Cadence"] }}
172 th {{ st.tr["Options"] }}
173 th
174 tbody
175 tr(
176 v-for="pc in presetChalls"
177 @click="newChallFromPreset(pc)"
178 )
179 td {{ pc.vname }}
180 td {{ pc.cadence }}
181 td(:class="getRandomnessClass(pc)") {{ pc.options.abridged }}
182 td.remove-preset(@click="removePresetChall($event, pc)")
183 img(src="/images/icons/delete.svg")
184 .row
185 .col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
186 div#div2
187 .button-group
188 button.tabbtn#btnClive(@click="setDisplay('c','live',$event)")
189 | {{ st.tr["Live challenges"] }}
190 button.tabbtn#btnCcorr(@click="setDisplay('c','corr',$event)")
191 | {{ st.tr["Correspondence challenges"] }}
192 ChallengeList(
193 v-show="cdisplay=='live'"
194 :challenges="filterChallenges('live')"
195 @click-challenge="clickChallenge"
196 )
197 ChallengeList(
198 v-show="cdisplay=='corr'"
199 :challenges="filterChallenges('corr')"
200 @click-challenge="clickChallenge"
201 )
202 div#div3
203 .button-group
204 button.tabbtn#btnGlive(@click="setDisplay('g','live',$event)")
205 | {{ st.tr["Live games"] }}
206 button.tabbtn#btnGcorr(@click="setDisplay('g','corr',$event)")
207 | {{ st.tr["Correspondence games"] }}
208 GameList(
209 v-show="gdisplay=='live'"
210 :games="filterGames('live')"
211 :show-both="true"
212 @show-game="showGame"
213 )
214 div(v-show="gdisplay=='corr'")
215 GameList(
216 :games="filterGames('corr')"
217 :show-both="true"
218 @show-game="showGame"
219 )
220 button#loadMoreBtn(
221 v-if="hasMore"
222 @click="loadMoreCorr()"
223 )
224 | {{ st.tr["Load more"] }}
225 </template>
226
227 <script>
228 import { store } from "@/store";
229 import { checkChallenge } from "@/data/challengeCheck";
230 import { notify } from "@/utils/notifications";
231 import { ArrayFun } from "@/utils/array";
232 import { ajax } from "@/utils/ajax";
233 import params from "@/parameters";
234 import { getRandString, shuffle, randInt } from "@/utils/alea";
235 import { getDiagram } from "@/utils/printDiagram";
236 import Chat from "@/components/Chat.vue";
237 import UserBio from "@/components/UserBio.vue";
238 import GameList from "@/components/GameList.vue";
239 import ChallengeList from "@/components/ChallengeList.vue";
240 import { GameStorage } from "@/utils/gameStorage";
241 import { processModalClick } from "@/utils/modalClick";
242 export default {
243 name: "my-hall",
244 components: {
245 Chat,
246 UserBio,
247 GameList,
248 ChallengeList
249 },
250 data: function() {
251 return {
252 st: store.state,
253 cdisplay: "live", //or corr
254 gdisplay: "live",
255 // timestamp of last showed (oldest) corr game:
256 cursor: Number.MAX_SAFE_INTEGER,
257 // hasMore == TRUE: a priori there could be more games to load
258 hasMore: true,
259 games: [],
260 challenges: [],
261 people: {},
262 infoMessage: "",
263 newchallenge: {
264 fen: "",
265 vid: parseInt(localStorage.getItem("vid"), 10) || 0,
266 to: "", //name of challenged player (if any)
267 color: '',
268 cadence: localStorage.getItem("cadence") || "",
269 options: {},
270 // VariantRules object, stored to not interfere with
271 // diagrams of targeted challenges:
272 V: null,
273 vname: "",
274 diag: "", //visualizing FEN
275 memorize: false //put settings in localStorage
276 },
277 focus: true,
278 tchallDiag: "",
279 curChallToAccept: { from: {}, options: {} },
280 presetChalls: JSON.parse(localStorage.getItem("presetChalls") || "[]"),
281 conn: null,
282 connexionString: "",
283 socketCloseListener: 0,
284 // Related to (killing of) self multi-connects:
285 newConnect: {}
286 };
287 },
288 watch: {
289 // st.variants changes only once, at loading from [] to [...]
290 "st.variants": function() {
291 // Set potential challenges and games variant names:
292 this.challenges.concat(this.games).forEach(o => {
293 if (!o.vname) this.setVname(o);
294 });
295 if (!this.newchallenge.V && this.newchallenge.vid > 0)
296 this.loadNewchallVariant();
297 },
298 $route: function(to, from) {
299 if (to.path != "/") this.cleanBeforeDestroy();
300 }
301 },
302 created: function() {
303 document.addEventListener('visibilitychange', this.visibilityChange);
304 window.addEventListener('focus', this.onFocus);
305 window.addEventListener('blur', this.onBlur);
306 window.addEventListener("beforeunload", this.cleanBeforeDestroy);
307 if (this.st.variants.length > 0 && this.newchallenge.vid > 0)
308 this.loadNewchallVariant();
309 const my = this.st.user;
310 const tmpId = getRandString();
311 this.$set(
312 this.people,
313 my.sid,
314 {
315 id: my.id,
316 name: my.name,
317 tmpIds: {
318 tmpId: { page: "/", focus: true }
319 }
320 }
321 );
322 const connectAndPoll = () => {
323 this.send("connect");
324 this.send("pollclientsandgamers");
325 if (!!this.$route.query["challenge"]) {
326 // Automatic challenge sending, for tournaments
327 this.loadNewchallVariant(
328 () => {
329 Object.assign(
330 this.newchallenge,
331 {
332 fen: "",
333 vid:
334 this.st.variants
335 .find(v => v.name == this.$route.query["variant"])
336 .id,
337 to: this.$route.query["challenge"],
338 color: this.$route.query["color"] || '',
339 cadence: this.$route.query["cadence"],
340 options: {},
341 memorize: false
342 }
343 );
344 window.doClick("modalNewgame");
345 },
346 this.$route.query["variant"]
347 );
348 }
349 };
350 // Initialize connection
351 this.connexionString =
352 params.socketUrl +
353 "/?sid=" + this.st.user.sid +
354 "&id=" + this.st.user.id +
355 "&tmpId=" + tmpId +
356 "&page=" +
357 // Hall: path is "/" (TODO: could be hard-coded as well)
358 encodeURIComponent(this.$route.path);
359 this.conn = new WebSocket(this.connexionString);
360 this.conn.onopen = connectAndPoll;
361 this.conn.addEventListener("message", this.socketMessageListener);
362 this.socketCloseListener = setInterval(
363 () => {
364 if (this.conn.readyState == 3) {
365 this.conn.removeEventListener("message", this.socketMessageListener);
366 this.conn = new WebSocket(this.connexionString);
367 this.conn.addEventListener("message", this.socketMessageListener);
368 }
369 },
370 1000
371 );
372 },
373 mounted: function() {
374 document.getElementById("peopleWrap")
375 .addEventListener("click", (e) => {
376 processModalClick(e, () => {
377 this.toggleSocialColor("close")
378 });
379 });
380 ["infoDiv", "newgameDiv"].forEach(eltName => {
381 document.getElementById(eltName)
382 .addEventListener("click", processModalClick);
383 });
384 document.querySelectorAll("#predefinedCadences > button").forEach(b => {
385 b.addEventListener("click", () => {
386 this.newchallenge.cadence = b.innerHTML;
387 });
388 });
389 const dispCorr = this.$route.query["disp"];
390 const showCtype =
391 dispCorr || localStorage.getItem("type-challenges") || "live";
392 const showGtype =
393 dispCorr || localStorage.getItem("type-games") || "live";
394 this.setDisplay('c', showCtype);
395 this.setDisplay('g', showGtype);
396 // Ask server for current corr games (all but mines)
397 this.loadMoreCorr();
398 // Also ask for corr challenges (open + sent by/to me)
399 // List them all, because they are not supposed to be that many (TODO?)
400 ajax(
401 "/challenges",
402 "GET",
403 {
404 data: { uid: this.st.user.id },
405 success: (response) => {
406 if (
407 response.challenges.length > 0 &&
408 this.challenges.length == 0 &&
409 this.cdisplay == "live"
410 ) {
411 document
412 .getElementById("btnCcorr")
413 .classList.add("somethingnew");
414 }
415 // Gather all senders names, and then retrieve full identity:
416 // (TODO [perf]: some might be online...)
417 let names = {};
418 response.challenges.forEach(c => {
419 if (c.uid != this.st.user.id) names[c.uid] = "";
420 else if (!!c.target && c.target != this.st.user.id)
421 names[c.target] = "";
422 });
423 const addChallenges = () => {
424 names[this.st.user.id] = this.st.user.name; //in case of
425 this.challenges = this.challenges.concat(
426 response.challenges.map(c => {
427 const from = { name: names[c.uid], id: c.uid }; //or just name
428 const type = this.classifyObject(c);
429 this.setVname(c);
430 return Object.assign(
431 {},
432 c,
433 {
434 type: type,
435 from: from,
436 to: c.target ? names[c.target] : "",
437 options: JSON.parse(c.options)
438 }
439 );
440 })
441 );
442 };
443 if (Object.keys(names).length > 0) {
444 ajax(
445 "/users",
446 "GET",
447 {
448 data: { ids: Object.keys(names).join(",") },
449 success: (response2) => {
450 response2.users.forEach(u => {
451 names[u.id] = u.name;
452 });
453 addChallenges();
454 }
455 }
456 );
457 }
458 else addChallenges();
459 }
460 }
461 );
462 },
463 beforeDestroy: function() {
464 this.cleanBeforeDestroy();
465 },
466 methods: {
467 cleanBeforeDestroy: function() {
468 clearInterval(this.socketCloseListener);
469 document.removeEventListener('visibilitychange', this.visibilityChange);
470 window.removeEventListener('focus', this.onFocus);
471 window.removeEventListener('blur', this.onBlur);
472 window.removeEventListener("beforeunload", this.cleanBeforeDestroy);
473 this.conn.removeEventListener("message", this.socketMessageListener);
474 this.send("disconnect");
475 this.conn = null;
476 },
477 getRandomnessClass: function(pc) {
478 if (!pc.options.randomness) return {};
479 return {
480 ["random-" + pc.options.randomness]: true
481 };
482 },
483 anonymousCount: function() {
484 let count = 0;
485 Object.values(this.people).forEach(p => {
486 // Do not cound people who did not send their identity yet:
487 count += (!p.name && p.id === 0) ? 1 : 0;
488 });
489 return count;
490 },
491 visibilityChange: function() {
492 // TODO: Use document.hidden? https://webplatform.news/issues/2019-03-27
493 this.focus = (document.visibilityState == "visible");
494 this.send(this.focus ? "getfocus" : "losefocus");
495 },
496 onFocus: function() {
497 this.focus = true;
498 this.send("getfocus");
499 },
500 onBlur: function() {
501 this.focus = false;
502 this.send("losefocus");
503 },
504 invColor: function(c) {
505 if (c == 'w') return this.st.tr["Black"];
506 return this.tr.tr["White"];
507 },
508 partialResetNewchallenge: function() {
509 // Reset potential target and custom FEN:
510 this.newchallenge.to = "";
511 this.newchallenge.color = '';
512 this.newchallenge.fen = "";
513 this.newchallenge.diag = "";
514 this.newchallenge.memorize = false;
515 },
516 showNewchallengeForm: function() {
517 this.partialResetNewchallenge();
518 window.doClick("modalNewgame");
519 },
520 sameOptions: function(opt1, opt2) {
521 const keys1 = Object.keys(opt1),
522 keys2 = Object.keys(opt2);
523 if (keys1.length != keys2.length) return false;
524 for (const key1 of keys1) {
525 if (!keys2.includes(key1)) return false;
526 if (opt1[key1] != opt2[key1]) return false;
527 }
528 return true;
529 },
530 addPresetChall: function(chall) {
531 // Add only if not already existing:
532 if (this.presetChalls.some(c =>
533 c.vid == chall.vid &&
534 c.cadence == chall.cadence &&
535 this.sameOptions(c.options, chall.options)
536 )) {
537 return;
538 }
539 const L = this.presetChalls.length;
540 this.presetChalls.push({
541 index: L,
542 vid: chall.vid,
543 vname: chall.vname, //redundant, but easier
544 cadence: chall.cadence,
545 options: chall.options
546 });
547 localStorage.setItem("presetChalls", JSON.stringify(this.presetChalls));
548 },
549 removePresetChall: function(e, pchall) {
550 e.stopPropagation();
551 const pchallIdx =
552 this.presetChalls.findIndex(pc => pc.index == pchall.index);
553 this.presetChalls.splice(pchallIdx, 1);
554 localStorage.setItem("presetChalls", JSON.stringify(this.presetChalls));
555 },
556 tchallButtonsMargin: function() {
557 if (!!this.curChallToAccept.fen) return { "margin-top": "10px" };
558 return {};
559 },
560 changeChallTarget: function() {
561 if (!this.newchallenge.to) {
562 // Reset potential FEN + diagram
563 this.newchallenge.fen = "";
564 this.newchallenge.color = '';
565 this.newchallenge.diag = "";
566 }
567 },
568 cadenceFocusIfOpened: function() {
569 if (event.target.checked)
570 document.getElementById("cadence").focus();
571 },
572 send: function(code, obj) {
573 if (!!this.conn && this.conn.readyState == 1) {
574 this.conn.send(JSON.stringify(Object.assign({ code: code }, obj)));
575 }
576 },
577 setVname: function(obj) {
578 const variant = this.st.variants.find(v => v.id == obj.vid);
579 // this.st.variants might be uninitialized (variant == null)
580 if (!!variant) {
581 obj.vname = variant.name;
582 obj.vdisp = variant.display;
583 }
584 // NOTE: Next line is used in loadNewchallVariant
585 return (!variant ? "" : variant.name);
586 },
587 filterChallenges: function(type) {
588 return this.challenges.filter(c => c.type == type);
589 },
590 filterGames: function(type) {
591 return this.games.filter(g => g.type == type);
592 },
593 // o: challenge or game
594 classifyObject: function(o) {
595 // No imported games here
596 return (o.cadence.indexOf("d") >= 0 ? "corr" : "live");
597 },
598 setDisplay: function(letter, type, e) {
599 this[letter + "display"] = type;
600 localStorage.setItem(
601 "type-" + (letter == "c" ? "challenges" : "games"),
602 type
603 );
604 let elt = e
605 ? e.target
606 : document.getElementById("btn" + letter.toUpperCase() + type);
607 elt.classList.add("active");
608 elt.classList.remove("somethingnew"); //in case of
609 if (!!elt.previousElementSibling)
610 elt.previousElementSibling.classList.remove("active");
611 else elt.nextElementSibling.classList.remove("active");
612 },
613 isGamer: function(sid) {
614 return Object.values(this.people[sid].tmpIds)
615 .some(v => v.focus && v.page.indexOf("/game/") >= 0);
616 },
617 isFocusedOnHall: function(sid) {
618 return (
619 // This is meant to challenge people, thus the next 2 conditions:
620 this.st.user.id > 0 &&
621 sid != this.st.user.sid &&
622 Object.values(this.people[sid].tmpIds)
623 .some(v => v.focus && v.page == "/")
624 );
625 },
626 challenge: function(sid) {
627 this.partialResetNewchallenge();
628 // Available, in Hall
629 this.newchallenge.to = this.people[sid].name;
630 // TODO: also store target sid to not re-search for it
631 document.getElementById("modalPeople").checked = false;
632 window.doClick("modalNewgame");
633 },
634 watchGame: function(sid) {
635 // In some game, maybe playing maybe not: show a random one
636 let gids = [];
637 Object.values(this.people[sid].tmpIds).forEach(v => {
638 if (v.focus) {
639 const matchGid = v.page.match(/[a-zA-Z0-9]+$/);
640 if (!!matchGid) gids.push(matchGid[0]);
641 }
642 });
643 const gid = gids[Math.floor(Math.random() * gids.length)];
644 window.open("/#/game/" + gid, "_blank");
645 },
646 showGame: function(g) {
647 // NOTE: we are an observer, since only games I don't play are shown here
648 // ==> Moves sent by connected remote player(s) if live game
649 window.open("/#/game/" + g.id, "_blank");
650 },
651 toggleSocialColor: function(action) {
652 if (!action && document.getElementById("modalPeople").checked)
653 document.getElementById("inputChat").focus();
654 else
655 document.getElementById("peopleBtn").classList.remove("somethingnew");
656 },
657 processChat: function(chat) {
658 this.send("newchat", { data: chat });
659 },
660 getOppsid: function(c) {
661 let oppsid = c.from.sid; //may not be defined if corr + offline opp
662 if (!oppsid) {
663 oppsid = Object.keys(this.people).find(
664 sid => this.people[sid].id == c.from.id
665 );
666 }
667 return oppsid;
668 },
669 // Messaging center:
670 socketMessageListener: function(msg) {
671 if (!this.conn) return;
672 const data = JSON.parse(msg.data);
673 switch (data.code) {
674 case "pollclientsandgamers": {
675 // TODO: shuffling and random filtering on server,
676 // if the room is really crowded.
677 Object.keys(data.sockIds).forEach(sid => {
678 if (sid != this.st.user.sid) {
679 // Pick a target tmpId (+page) at random:
680 const pt = Object.values(data.sockIds[sid]);
681 const randPage = pt[randInt(pt.length)].page;
682 this.send(
683 "askidentity",
684 {
685 target: sid,
686 page: randPage
687 }
688 );
689 }
690 if (!this.people[sid])
691 // Do not set name or id: identity unknown yet
692 this.people[sid] = { tmpIds: data.sockIds[sid] };
693 else
694 Object.assign(this.people[sid].tmpIds, data.sockIds[sid]);
695 if (Object.values(data.sockIds[sid]).some(v => v.page == "/"))
696 // Peer is in Hall
697 this.send("askchallenges", { target: sid });
698 Object.values(data.sockIds[sid]).forEach(v => {
699 if (
700 v.page.indexOf("/game/") >= 0 &&
701 !v.page.match(/\/[0-9]+$/)
702 ) {
703 // Peer is in Game: ask only if live game
704 this.send("askgame", { target: sid, page: v.page });
705 }
706 });
707 });
708 break;
709 }
710 case "connect":
711 case "gconnect": {
712 const page = data.page || "/";
713 if (data.code == "connect") {
714 // Ask challenges only on first connexion:
715 if (!this.people[data.from[0]])
716 this.send("askchallenges", { target: data.from[0] });
717 }
718 // Ask game only if live:
719 else if (!page.match(/\/[0-9]+$/))
720 this.send("askgame", { target: data.from[0], page: page });
721 if (!this.people[data.from[0]]) {
722 this.$set(
723 this.people,
724 data.from[0],
725 {
726 tmpIds: {
727 [data.from[1]]: { page: page, focus: true }
728 }
729 }
730 );
731 // For self multi-connects tests:
732 this.newConnect[data.from[0]] = true;
733 this.send("askidentity", { target: data.from[0], page: page });
734 }
735 else {
736 this.people[data.from[0]].tmpIds[data.from[1]] =
737 { page: page, focus: true };
738 this.$forceUpdate(); //TODO: shouldn't be required
739 }
740 break;
741 }
742 case "disconnect":
743 case "gdisconnect": {
744 // If the user reloads the page twice very quickly
745 // (experienced with Firefox), the first reload won't have time to
746 // connect but will trigger a "close" event anyway.
747 // ==> Next check is required.
748 if (!this.people[data.from[0]]) return;
749 delete this.people[data.from[0]].tmpIds[data.from[1]];
750 if (Object.keys(this.people[data.from[0]].tmpIds).length == 0)
751 this.$delete(this.people, data.from[0]);
752 else this.$forceUpdate(); //TODO: shouldn't be required
753 if (data.code == "disconnect") {
754 // Remove the live challenges sent by this player, if
755 // he isn't connected on another tab:
756 if (
757 !this.people[data.from[0]] ||
758 Object.values(this.people[data.from[0]].tmpIds)
759 .every(v => v.page != "/")
760 ) {
761 ArrayFun.remove(
762 this.challenges,
763 c => c.type == "live" && c.from.sid == data.from[0],
764 "all"
765 );
766 }
767 }
768 else {
769 // Remove the matching live game if now unreachable
770 const gid = data.page.match(/[a-zA-Z0-9]+$/)[0];
771 // Corr games are always reachable:
772 if (!gid.match(/^[0-9]+$/)) {
773 // Live games are reachable if someone is on the game page
774 if (Object.values(this.people).every(p =>
775 Object.values(p.tmpIds).every(v => v.page != data.page))
776 ) {
777 ArrayFun.remove(this.games, g => g.id == gid);
778 }
779 }
780 }
781 break;
782 }
783 case "getfocus": {
784 let player = this.people[data.from[0]];
785 // If user reload a page, focus may arrive earlier than connect
786 if (!!player) {
787 player.tmpIds[data.from[1]].focus = true;
788 this.$forceUpdate(); //TODO: shouldn't be required
789 }
790 break;
791 }
792 case "losefocus": {
793 let player = this.people[data.from[0]];
794 if (!!player) {
795 player.tmpIds[data.from[1]].focus = false;
796 this.$forceUpdate(); //TODO: shouldn't be required
797 }
798 break;
799 }
800 case "askidentity": {
801 // Request for identification
802 const me = {
803 // Decompose to avoid revealing email
804 name: this.st.user.name,
805 sid: this.st.user.sid,
806 id: this.st.user.id
807 };
808 this.send("identity", { data: me, target: data.from });
809 break;
810 }
811 case "identity": {
812 const user = data.data;
813 let player = this.people[user.sid];
814 // player.tmpIds is already set
815 player.id = user.id;
816 player.name = user.name;
817 // TODO: this.$set(people, ...) fails. So forceUpdate.
818 // But this shouldn't be like that!
819 this.$forceUpdate();
820 // If I multi-connect, kill current connexion if no mark (I'm older)
821 if (this.newConnect[user.sid]) {
822 delete this.newConnect[user.sid];
823 if (
824 user.id > 0 &&
825 user.id == this.st.user.id &&
826 user.sid != this.st.user.sid
827 ) {
828 // I logged in elsewhere:
829 this.cleanBeforeDestroy();
830 alert(this.st.tr["New connexion detected: tab now offline"]);
831 }
832 }
833 break;
834 }
835 case "askchallenges": {
836 // Send my current live challenges (if any)
837 const myChallenges = this.challenges
838 .filter(c =>
839 c.from.sid == this.st.user.sid && c.type == "live"
840 )
841 .map(c => {
842 // NOTE: in principle, should only send targeted challenge to the
843 // target. But we may not know yet the identity of the target
844 // (just name), so can't decide if data.from is the target.
845 return {
846 id: c.id,
847 from: this.st.user.sid,
848 to: c.to,
849 options: c.options,
850 fen: c.fen,
851 vid: c.vid,
852 cadence: c.cadence,
853 added: c.added
854 };
855 });
856 if (myChallenges.length > 0)
857 this.send("challenges", { data: myChallenges, target: data.from });
858 break;
859 }
860 case "challenges": //after "askchallenges"
861 data.data.forEach(this.addChallenge);
862 break;
863 case "newchallenge":
864 this.addChallenge(data.data);
865 break;
866 case "refusechallenge": {
867 const cid = data.data;
868 ArrayFun.remove(this.challenges, c => c.id == cid);
869 alert(this.st.tr["Challenge declined"]);
870 break;
871 }
872 case "deletechallenge_s": {
873 // NOTE: the challenge(s) may be already removed
874 const cref = data.data;
875 if (!!cref.cid)
876 ArrayFun.remove(this.challenges, c => c.id == cref.cid);
877 else if (!!cref.sids) {
878 cref.sids.forEach(s => {
879 ArrayFun.remove(
880 this.challenges,
881 c => c.type == "live" && c.from.sid == s,
882 "all"
883 );
884 });
885 }
886 break;
887 }
888 case "game": // Individual request
889 case "newgame": {
890 const game = data.data;
891 // Ignore games where I play (will go in MyGames page),
892 // and also games that I already received.
893 if (
894 this.games.findIndex(g => g.id == game.id) == -1 &&
895 game.players.every(p => {
896 return (
897 p.sid != this.st.user.sid &&
898 (p.id == 0 || p.id != this.st.user.id)
899 );
900 })
901 ) {
902 let newGame = game;
903 newGame.type = this.classifyObject(game);
904 this.setVname(game);
905 if (!game.score)
906 // New game from Hall
907 newGame.score = "*";
908 this.games.push(newGame);
909 if (
910 newGame.score == '*' &&
911 (newGame.type == "live" && this.gdisplay == "corr") ||
912 (newGame.type == "corr" && this.gdisplay == "live")
913 ) {
914 document
915 .getElementById("btnG" + newGame.type)
916 .classList.add("somethingnew");
917 }
918 }
919 break;
920 }
921 case "result": {
922 let g = this.games.find(g => g.id == data.gid);
923 if (!!g) g.score = data.score;
924 break;
925 }
926 case "startgame": {
927 // New game just started, I'm involved
928 const gameInfo = data.data;
929 if (this.classifyObject(gameInfo) == "live")
930 this.startNewGame(gameInfo);
931 else {
932 this.infoMessage =
933 this.st.tr["New correspondence game:"] + " " +
934 "<a href='#/game/" + gameInfo.id + "'>" +
935 "#/game/" + gameInfo.id + "</a>";
936 document.getElementById("modalInfo").checked = true;
937 }
938 break;
939 }
940 case "newchat":
941 this.$refs["chatcomp"].newChat(data.data);
942 if (!document.getElementById("modalPeople").checked)
943 document.getElementById("peopleBtn").classList.add("somethingnew");
944 break;
945 }
946 },
947 loadMoreCorr: function() {
948 ajax(
949 "/observedgames",
950 "GET",
951 {
952 data: {
953 uid: this.st.user.id,
954 cursor: this.cursor
955 },
956 success: (res) => {
957 const L = res.games.length;
958 if (L > 0) {
959 if (
960 this.cursor == Number.MAX_SAFE_INTEGER &&
961 this.games.length == 0 &&
962 this.gdisplay == "live" &&
963 res.games.some(g => g.score == '*')
964 ) {
965 // First loading: show indicators
966 document
967 .getElementById("btnGcorr")
968 .classList.add("somethingnew");
969 }
970 this.cursor = res.games[L - 1].created;
971 let moreGames = res.games.map(g => {
972 this.setVname(g);
973 g.type = "corr";
974 return g;
975 });
976 this.games = this.games.concat(moreGames);
977 }
978 else this.hasMore = false;
979 }
980 }
981 );
982 },
983 // Challenge lifecycle:
984 addChallenge: function(chall) {
985 // NOTE about next condition: see "askchallenges" case.
986 if (
987 !chall.to ||
988 (this.people[chall.from].id > 0 &&
989 (chall.from == this.st.user.sid || chall.to == this.st.user.name))
990 ) {
991 let newChall = Object.assign({}, chall);
992 newChall.type = this.classifyObject(chall);
993 newChall.options = chall.options;
994 newChall.added = Date.now();
995 let fromValues = Object.assign({}, this.people[chall.from]);
996 delete fromValues["pages"]; //irrelevant in this context
997 newChall.from = Object.assign({ sid: chall.from }, fromValues);
998 this.setVname(newChall);
999 this.challenges.push(newChall);
1000 if (
1001 (newChall.type == "live" && this.cdisplay == "corr") ||
1002 (newChall.type == "corr" && this.cdisplay == "live")
1003 ) {
1004 document
1005 .getElementById("btnC" + newChall.type)
1006 .classList.add("somethingnew");
1007 }
1008 if (!!chall.to && chall.to == this.st.user.name) {
1009 notify(
1010 "New challenge",
1011 // fromValues.name should exist since the player is online, but
1012 // let's consider there is some chance that the challenge arrives
1013 // right after we connected and before receiving the poll result:
1014 { body: "from " + (fromValues.name || "@nonymous") }
1015 );
1016 }
1017 }
1018 },
1019 loadNewchallVariant: async function(cb, vname) {
1020 vname = vname || this.setVname(this.newchallenge);
1021 await import("@/variants/" + vname + ".js")
1022 .then((vModule) => {
1023 window.V = vModule[vname + "Rules"];
1024 this.newchallenge.V = window.V;
1025 if (!!cb) cb();
1026 });
1027 },
1028 trySetNewchallDiag: function() {
1029 if (!this.newchallenge.fen) {
1030 this.newchallenge.diag = "";
1031 return;
1032 }
1033 // If vid > 0 then the variant is loaded (function above):
1034 window.V = this.newchallenge.V;
1035 if (
1036 this.newchallenge.vid > 0 &&
1037 !!this.newchallenge.fen &&
1038 V.IsGoodFen(this.newchallenge.fen)
1039 ) {
1040 const parsedFen = V.ParseFen(this.newchallenge.fen);
1041 this.newchallenge.diag = getDiagram({
1042 position: parsedFen.position
1043 //,orientation: parsedFen.turn
1044 });
1045 }
1046 else this.newchallenge.diag = "";
1047 },
1048 newChallFromPreset(pchall) {
1049 this.partialResetNewchallenge();
1050 this.newchallenge.vid = pchall.vid;
1051 this.newchallenge.cadence = pchall.cadence;
1052 this.newchallenge.options = pchall.options;
1053 this.loadNewchallVariant(this.issueNewChallenge);
1054 },
1055 issueNewChallenge: async function() {
1056 if (!!(this.newchallenge.cadence.match(/^[0-9]+$/)))
1057 this.newchallenge.cadence += "+0"; //assume minutes, no increment
1058 const ctype = this.classifyObject(this.newchallenge);
1059 // TODO: cadence still unchecked so ctype could be wrong...
1060 let error = "";
1061 if (!this.newchallenge.vid)
1062 error = this.st.tr["Please select a variant"];
1063 else if (ctype == "corr" && this.st.user.id <= 0)
1064 error = this.st.tr["Please log in to play correspondence games"];
1065 else if (!this.newchallenge.to && !!this.newchallenge.color)
1066 error = this.st.tr["Color option only for targeted challenge"];
1067 else if (!!this.newchallenge.to) {
1068 if (this.newchallenge.to == this.st.user.name)
1069 error = this.st.tr["Self-challenge is forbidden"];
1070 else if (
1071 ctype == "live" &&
1072 Object.values(this.people).every(p => p.name != this.newchallenge.to)
1073 ) {
1074 error = this.newchallenge.to + " " + this.st.tr["is not online"];
1075 }
1076 if (
1077 !!this.newchallenge.color &&
1078 !['w', 'b'].includes(this.newchallenge.color)
1079 ) {
1080 error = this.st.tr["Wrong color"];
1081 }
1082 }
1083 if (!!error) {
1084 alert(error);
1085 return;
1086 }
1087 window.V = this.newchallenge.V;
1088 error = checkChallenge(this.newchallenge);
1089 if (error) {
1090 alert(error);
1091 return;
1092 }
1093 // NOTE: "from" information is not required here
1094 let chall = Object.assign({}, this.newchallenge);
1095 chall.options = {};
1096 // Get/set options variables (if any) / TODO: v-model?!
1097 for (const check of this.newchallenge.V.Options.check) {
1098 const elt = document.getElementById(check.variable + "_opt");
1099 if (elt.checked) chall.options[check.variable] = true;
1100 }
1101 for (const select of this.newchallenge.V.Options.select) {
1102 const elt = document.getElementById(select.variable + "_opt");
1103 chall.options[select.variable] = elt.value;
1104 }
1105 chall.options.abridged = V.AbbreviateOptions(chall.options);
1106 // Add only if not already issued (not counting FEN):
1107 if (this.challenges.some(c =>
1108 (
1109 c.from.sid == this.st.user.sid ||
1110 (c.from.id > 0 && c.from.id == this.st.user.id)
1111 )
1112 &&
1113 (
1114 (!c.to && !chall.to) ||
1115 c.to == chall.to
1116 )
1117 &&
1118 c.vid == chall.vid &&
1119 c.cadence == chall.cadence &&
1120 this.sameOptions(c.options, chall.options)
1121 )) {
1122 alert(this.st.tr["Challenge already exists"]);
1123 return;
1124 }
1125 if (this.newchallenge.memorize) this.addPresetChall(this.newchallenge);
1126 delete chall["V"];
1127 delete chall["diag"];
1128 const finishAddChallenge = cid => {
1129 chall.id = cid || "c" + getRandString();
1130 const MAX_ALLOWED_CHALLS = 3;
1131 // Remove oldest challenge if 3 found: only 3 at a time of a given type
1132 let countMyChalls = 0;
1133 let challToDelIdx = 0;
1134 let oldestAdded = Number.MAX_SAFE_INTEGER;
1135 for (let i=0; i<this.challenges.length; i++) {
1136 const c = this.challenges[i];
1137 if (
1138 c.type == ctype &&
1139 (
1140 c.from.sid == this.st.user.sid ||
1141 (c.from.id > 0 && c.from.id == this.st.user.id)
1142 )
1143 ) {
1144 countMyChalls++;
1145 if (c.added < oldestAdded) {
1146 challToDelIdx = i;
1147 oldestAdded = c.added;
1148 }
1149 }
1150 }
1151 if (countMyChalls >= MAX_ALLOWED_CHALLS) {
1152 this.send(
1153 "deletechallenge_s",
1154 { data: { cid: this.challenges[challToDelIdx].id } }
1155 );
1156 if (ctype == "corr") {
1157 ajax(
1158 "/challenges",
1159 "DELETE",
1160 { data: { id: this.challenges[challToDelIdx].id } }
1161 );
1162 }
1163 this.challenges.splice(challToDelIdx, 1);
1164 }
1165 this.send("newchallenge", {
1166 data: Object.assign(
1167 // Temporarily add sender infos to display challenge on Discord.
1168 { from: this.st.user.sid, sender: this.st.user.name }, chall)
1169 });
1170 // Add new challenge:
1171 chall.from = {
1172 sid: this.st.user.sid,
1173 id: this.st.user.id,
1174 name: this.st.user.name
1175 };
1176 chall.added = Date.now();
1177 // NOTE: vname and type are redundant (deduced from cadence + vid)
1178 chall.type = ctype;
1179 chall.vname = this.newchallenge.vname;
1180 this.challenges.push(chall);
1181 // Remember cadence + vid for quicker further challenges:
1182 localStorage.setItem("cadence", chall.cadence);
1183 localStorage.setItem("vid", chall.vid);
1184 document.getElementById("modalNewgame").checked = false;
1185 // Show the challenge if not on current display
1186 if (
1187 (ctype == "live" && this.cdisplay == "corr") ||
1188 (ctype == "corr" && this.cdisplay == "live")
1189 ) {
1190 this.setDisplay('c', ctype);
1191 }
1192 };
1193 if (ctype == "live") {
1194 // Live challenges have a random ID
1195 finishAddChallenge(null);
1196 }
1197 else {
1198 // Correspondence game: send challenge to server
1199 ajax(
1200 "/challenges",
1201 "POST",
1202 {
1203 data: {
1204 chall: Object.assign(
1205 {},
1206 chall,
1207 { options: JSON.stringify(chall.options) }
1208 )
1209 },
1210 success: (response) => {
1211 finishAddChallenge(response.id);
1212 }
1213 }
1214 );
1215 }
1216 },
1217 // Callback function after a diagram was showed to accept
1218 // or refuse targetted challenge:
1219 decisionChallenge: function(accepted) {
1220 this.curChallToAccept.accepted = accepted;
1221 this.finishProcessingChallenge(this.curChallToAccept);
1222 document.getElementById("modalAccept").checked = false;
1223 },
1224 finishProcessingChallenge: function(c) {
1225 if (c.accepted) {
1226 c.seat = {
1227 sid: this.st.user.sid,
1228 id: this.st.user.id,
1229 name: this.st.user.name
1230 };
1231 this.launchGame(c);
1232 if (c.type == "live") {
1233 // Remove all live challenges of both players
1234 this.send(
1235 "deletechallenge_s",
1236 { data: { sids: [c.from.sid, c.seat.sid] } }
1237 );
1238 }
1239 else
1240 // Corr challenge: just remove the challenge
1241 this.send("deletechallenge_s", { data: { cid: c.id } });
1242 }
1243 else {
1244 const oppsid = this.getOppsid(c);
1245 if (!!oppsid)
1246 this.send("refusechallenge", { data: c.id, target: oppsid });
1247 if (c.type == "corr") {
1248 ajax(
1249 "/challenges",
1250 "DELETE",
1251 { data: { id: c.id } }
1252 );
1253 }
1254 this.send("deletechallenge_s", { data: { cid: c.id } });
1255 }
1256 },
1257 // TODO: if several players click same challenge at the same time: problem
1258 clickChallenge: async function(c) {
1259 const myChallenge =
1260 c.from.sid == this.st.user.sid || //live
1261 (this.st.user.id > 0 && c.from.id == this.st.user.id); //corr
1262 if (!myChallenge) {
1263 if (c.type == "corr" && this.st.user.id <= 0) {
1264 alert(this.st.tr["Please log in to accept corr challenges"]);
1265 return;
1266 }
1267 else {
1268 c.accepted = true;
1269 await import("@/variants/" + c.vname + ".js")
1270 .then((vModule) => {
1271 window.V = vModule[c.vname + "Rules"];
1272 if (!!c.to) {
1273 // c.to == this.st.user.name (connected)
1274 if (!!c.fen) {
1275 const parsedFen = V.ParseFen(c.fen);
1276 this.tchallDiag = getDiagram({
1277 position: parsedFen.position,
1278 orientation: parsedFen.turn
1279 });
1280 }
1281 this.curChallToAccept = c;
1282 document.getElementById("modalAccept").checked = true;
1283 }
1284 else this.finishProcessingChallenge(c);
1285 });
1286 }
1287 }
1288 else {
1289 // My challenge
1290 if (c.type == "corr") {
1291 ajax(
1292 "/challenges",
1293 "DELETE",
1294 { data: { id: c.id } }
1295 );
1296 }
1297 this.send("deletechallenge_s", { data: { cid: c.id } });
1298 }
1299 // In all cases, the challenge is consumed:
1300 ArrayFun.remove(this.challenges, ch => ch.id == c.id);
1301 },
1302 // NOTE: when launching game, the challenge is already being deleted
1303 launchGame: function(c) {
1304 // White player index 0, black player index 1:
1305 let players =
1306 !!c.color
1307 ? (c.color == "w" ? [c.from, c.seat] : [c.seat, c.from])
1308 : shuffle([c.from, c.seat]);
1309 players.forEach(p => {
1310 if (!!p["tmpIds"]) delete p["tmpIds"];
1311 });
1312 // These game informations will be shared
1313 let gameInfo = {
1314 id: getRandString(),
1315 fen: c.fen || V.GenRandInitFen(c.options),
1316 options: c.options, //for rematch
1317 players: players,
1318 vid: c.vid,
1319 cadence: c.cadence
1320 };
1321 const notifyNewgame = () => {
1322 const oppsid = this.getOppsid(c);
1323 if (!!oppsid)
1324 // Opponent is online
1325 this.send("startgame", { data: gameInfo, target: oppsid });
1326 // If new corr game, notify Hall (except opponent and me)
1327 if (c.type == "corr") {
1328 this.send(
1329 "newgame",
1330 {
1331 data: gameInfo,
1332 excluded: [this.st.user.sid, oppsid]
1333 }
1334 );
1335 }
1336 // Notify MyGames page:
1337 this.send(
1338 "notifynewgame",
1339 {
1340 data: gameInfo,
1341 targets: gameInfo.players
1342 }
1343 );
1344 // NOTE: no need to send the game to the room, since I'll connect
1345 // on game just after, the main Hall will be notified.
1346 };
1347 if (c.type == "live") {
1348 // TODO: ask my IP + opp IP, to add to game infos? (potential bans)
1349 notifyNewgame();
1350 this.startNewGame(gameInfo);
1351 // Increment game stats counter in DB
1352 ajax(
1353 "/gamestat",
1354 "POST",
1355 { data: { vid: gameInfo.vid } }
1356 );
1357 }
1358 else {
1359 // corr: game only on server
1360 ajax(
1361 "/games",
1362 "POST",
1363 {
1364 // cid is useful to delete the challenge:
1365 data: {
1366 gameInfo: Object.assign(
1367 {},
1368 gameInfo,
1369 { options: JSON.stringify(gameInfo.options) }
1370 ),
1371 cid: c.id
1372 },
1373 success: (response) => {
1374 gameInfo.id = response.id;
1375 notifyNewgame();
1376 this.$router.push("/game/" + response.id);
1377 }
1378 }
1379 );
1380 }
1381 },
1382 // NOTE: for live games only (corr games start on the server)
1383 startNewGame: function(gameInfo) {
1384 this.setVname(gameInfo);
1385 const game = Object.assign(
1386 {},
1387 gameInfo,
1388 {
1389 // (other) Game infos: constant
1390 fenStart: gameInfo.fen,
1391 created: Date.now(),
1392 // Game state (including FEN): will be updated
1393 moves: [],
1394 clocks: [-1, -1], //-1 = unstarted
1395 chats: [],
1396 score: "*"
1397 }
1398 );
1399 setTimeout(
1400 () => {
1401 const myIdx = (game.players[0].sid == this.st.user.sid ? 0 : 1);
1402 GameStorage.add(game, (err) => {
1403 // If an error occurred, game is not added: the focused tab
1404 // already added the game.
1405 if (!this.focus) {
1406 if (this.st.settings.sound)
1407 // This will be played several times if several hidden tabs
1408 // on Hall... TODO: fix that (how ?!)
1409 new Audio("/sounds/newgame.flac").play().catch(() => {});
1410 notify(
1411 "New live game",
1412 { body: "vs " + (game.players[1-myIdx].name || "@nonymous") }
1413 );
1414 }
1415 this.$router.push("/game/" + gameInfo.id);
1416 });
1417 },
1418 this.focus ? 0 : 500 + 1000 * Math.random()
1419 );
1420 }
1421 }
1422 };
1423 </script>
1424
1425 <style lang="sass" scoped>
1426 .active
1427 color: #388e3c
1428
1429 #infoDiv > .card
1430 padding: 15px 0
1431 max-width: 430px
1432
1433 #newgameDiv > .card, #acceptDiv > .card
1434 max-width: 767px
1435 max-height: 100%
1436
1437 div#peopleWrap > .card
1438 max-height: 100%
1439
1440 @media screen and (min-width: 1281px)
1441 div#peopleWrap > .card
1442 max-width: 66.67%
1443
1444 @media screen and (max-width: 1280px)
1445 div#peopleWrap > .card
1446 max-width: 83.33%
1447
1448 @media screen and (max-width: 767px)
1449 div#peopleWrap > .card
1450 max-width: 100%
1451
1452 #players
1453 width: 50%
1454 position: relative
1455 float: left
1456
1457 #chat
1458 width: 50%
1459 float: left
1460 position: relative
1461
1462 @media screen and (max-width: 767px)
1463 #players, #chats
1464 width: 100%
1465
1466 #chat > .card
1467 max-width: 100%
1468 margin: 0;
1469 border: none;
1470
1471 #players > p
1472 margin-left: 5px
1473
1474 .anonymous
1475 font-style: italic
1476
1477 button.player-action
1478 margin-left: 32px
1479 &.focused
1480 background-color: #E6D271
1481
1482 .somethingnew
1483 background-color: #90C4EC !important
1484
1485 .tabbtn
1486 background-color: #f9faee
1487
1488 button.acceptBtn
1489 background-color: lightgreen
1490 button.refuseBtn
1491 background-color: red
1492
1493 #buttonsTchall
1494 // margin-top set dynamically (depends if diagram showed or not)
1495 & > button > span
1496 width: 100%
1497 text-align: center
1498
1499 .variantName
1500 font-weight: bold
1501
1502 .diagram
1503 margin: 0 auto
1504 max-width: 400px
1505 // width: 100% required for Firefox
1506 width: 100%
1507
1508 #inputFen
1509 width: 100%
1510
1511 #div2, #div3
1512 margin-top: 15px
1513 @media screen and (max-width: 767px)
1514 #div2, #div3
1515 margin-top: 0
1516
1517 .user-bio
1518 display: inline
1519
1520 tr > td
1521 &.random-0
1522 background-color: #FEAF9E
1523 &.random-1
1524 background-color: #9EB2FE
1525 &.random-2
1526 background-color: #A5FE9E
1527
1528 @media screen and (max-width: 767px)
1529 h4
1530 margin: 5px 0
1531
1532 button#loadMoreBtn
1533 display: block
1534 margin: 0 auto
1535
1536 td.remove-preset
1537 background-color: lightgrey
1538 text-align: center
1539 & > img
1540 height: 1em
1541 </style>