Left some TODOs, some bugs
[vchess.git] / client / src / views / Game.vue
index d366bb2..ddd5e59 100644 (file)
@@ -5,13 +5,13 @@ main
     #chat.card
       label.modal-close(for="modalChat")
       #participants
-        span {{ Object.keys(people).length }} st.tr["participant(s):"] 
+        span {{ Object.keys(people).length + " " + st.tr["participant(s):"] }} 
         span(v-for="p in Object.values(people)" v-if="!!p.name")
           | {{ p.name }} 
         span.anonymous(v-if="Object.values(people).some(p => !p.name)")
           | + @nonymous
       Chat(:players="game.players" :pastChats="game.chats"
-        @newchat-sent="finishSendChat" @newchat-received="processChat")
+        :newChat="newChat" @mychat="processChat")
   .row
     #aboveBoard.col-sm-12.col-md-9.col-md-offset-3.col-lg-10.col-lg-offset-2
       span.variant-info
@@ -68,6 +68,7 @@ export default {
       people: {}, //players + observers
       lastate: undefined, //used if opponent send lastate before game is ready
       repeat: {}, //detect position repetition
+      newChat: "",
     };
   },
   watch: {
@@ -246,6 +247,11 @@ export default {
             this.drawOffer = "";
           this.$set(this.game, "moveToPlay", data.move);
           break;
+        case "newchat":
+          this.newChat = data.chat;
+          if (!document.getElementById("modalChat").checked)
+            document.getElementById("chatBtn").style.backgroundColor = "#c5fefe";
+          break;
         case "lastate": //got opponent infos about last move
         {
           this.lastate = data;
@@ -616,15 +622,12 @@ export default {
       // TODO: this is called twice, once on opening an once on closing
       document.getElementById("chatBtn").style.backgroundColor = "#e2e2e2";
     },
-    finishSendChat: function(chat) {
+    processChat: function(chat) {
+      this.st.conn.send(JSON.stringify({code:"newchat", chat:chat}));
       // NOTE: anonymous chats in corr games are not stored on server (TODO?)
       if (this.game.type == "corr" && this.st.user.id > 0)
         GameStorage.update(this.gameRef.id, {chat: chat});
     },
-    processChat: function() {
-      if (!document.getElementById("modalChat").checked)
-        document.getElementById("chatBtn").style.backgroundColor = "#c5fefe";
-    },
     gameOver: function(score, scoreMsg) {
       this.game.score = score;
       this.game.scoreMsg = this.st.tr[(!!scoreMsg
@@ -666,7 +669,6 @@ export default {
   margin-top: 10px
   button
     display: inline-block
-    width: 33%
     margin: 0
 
 @media screen and (max-width: 767px)