X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fviews%2FHall.vue;h=287788a17f781d404de53fb1591960c1f9110295;hb=11667c79617c057357f2a176c798bfee3b190771;hp=a8dfa987ae4253a2d76c9e958912b025e958854d;hpb=92a523d1a74cbabcfd7d6ade45f25fa622815f0b;p=vchess.git
diff --git a/client/src/views/Hall.vue b/client/src/views/Hall.vue
index a8dfa987..287788a1 100644
--- a/client/src/views/Hall.vue
+++ b/client/src/views/Hall.vue
@@ -110,7 +110,7 @@ export default {
});
this.games.forEach(g => {
if (g.vname == "")
- g.vname = this.getVname(g.vid)
+ g.vname = this.getVname(g.vid);
});
},
},
@@ -224,10 +224,10 @@ export default {
}
this.$router.push(url);
},
- // TODO: ...filter(...)[0].name, one-line, just remove this function
getVname: function(vid) {
- const vIdx = this.st.variants.findIndex(v => v.id == vid);
- return vIdx >= 0 ? this.st.variants[vIdx].name : "";
+ const variant = this.st.variants.find(v => v.id == vid);
+ // this.st.variants might be uninitialized (variant == null)
+ return (!!variant ? variant.name : "");
},
getSid: function(pname) {
const pIdx = this.people.findIndex(pl => pl.name == pname);
@@ -381,8 +381,8 @@ export default {
else
{
this.infoMessage = "New game started: " +
- "" +
- "#/game/" + data.gameInfo.gameId + "";
+ "" +
+ "#/game/" + data.gameInfo.id + "";
let modalBox = document.getElementById("modalInfo");
modalBox.checked = true;
setTimeout(() => { modalBox.checked = false; }, 3000);
@@ -452,7 +452,8 @@ export default {
chall.vname = vname;
chall.from = this.people[0]; //avoid sending email
this.challenges.push(chall);
- localStorage.setItem("challenge", JSON.stringify(chall));
+ if (ctype == "live")
+ localStorage.setItem("challenge", JSON.stringify(chall));
document.getElementById("modalNewgame").checked = false;
};
const cIdx = this.challenges.findIndex(
@@ -515,7 +516,6 @@ export default {
}
else //my challenge
{
- localStorage.removeItem("challenge");
if (c.type == "corr")
{
ajax(
@@ -524,6 +524,8 @@ export default {
{id: c.id}
);
}
+ else //live
+ localStorage.removeItem("challenge");
}
// In (almost) all cases, the challenge is consumed:
ArrayFun.remove(this.challenges, ch => ch.id == c.id);
@@ -537,10 +539,11 @@ export default {
// These game informations will be sent to other players
const gameInfo =
{
- gameId: getRandString(),
+ id: getRandString(),
fen: c.fen || V.GenRandInitFen(),
players: shuffle([c.from, c.seat]), //white then black
vid: c.vid,
+ vname: c.vname, //theoretically vid is enough, but much easier with vname
timeControl: c.timeControl,
};
let target = c.from.sid; //may not be defined if corr + offline opp
@@ -569,7 +572,7 @@ export default {
"POST",
{gameInfo: gameInfo, cid: c.id}, //cid useful to delete challenge
response => {
- gameInfo.gameId = response.gameId;
+ gameInfo.id = response.gameId;
tryNotifyOpponent();
this.$router.push("/game/" + response.gameId);
}
@@ -591,7 +594,7 @@ export default {
GameStorage.add(game);
if (this.st.settings.sound >= 1)
new Audio("/sounds/newgame.mp3").play().catch(err => {});
- this.$router.push("/game/" + gameInfo.gameId);
+ this.$router.push("/game/" + gameInfo.id);
},
},
};