'update'
[vchess.git] / client / src / components / Chat.vue
index 517d2cd..5834cbe 100644 (file)
@@ -1,11 +1,12 @@
 <template lang="pug">
 div
-  .card.smallpad
-    h4 Chat
-    p(v-for="chat in chats" :class="classObject(chat)" v-html="chat.msg")
-    input#inputChat(type="text" :placeholder="st.tr['Type here']"
-      @keyup.enter="sendChat")
-    button#sendChatBtn(@click="sendChat") {{ st.tr["Send"] }}
+  input#inputChat(type="text" :placeholder="st.tr['Type here']"
+    @keyup.enter="sendChat")
+  button#sendChatBtn(@click="sendChat") {{ st.tr["Send"] }}
+  p(v-for="chat in pastChats" :class="classObject(chat)"
+    v-html="chat.name + ': ' + chat.msg")
+  p(v-for="chat in chats" :class="classObject(chat)"
+    v-html="chat.name + ': ' + chat.msg")
 </template>
 
 <script>
@@ -13,7 +14,8 @@ import { store } from "@/store";
 
 export default {
   name: "my-chat",
-  props: ["players"],
+  // Prop 'pastChats' for corr games where chats are on server
+  props: ["players","pastChats"],
   data: function() {
     return {
       st: store.state,
@@ -27,8 +29,9 @@ export default {
       const data = JSON.parse(msg.data);
       if (data.code == "newchat") //only event at this level
       {
-        this.chats.push({msg:data.msg,
+        this.chats.unshift({msg:data.msg,
           name:data.name || "@nonymous", sid:data.from});
+        this.$emit("newchat-received"); //data not required here
       }
     };
     const socketCloseListener = () => {
@@ -53,7 +56,8 @@ export default {
       chatInput.value = "";
       const chat = {msg:chatTxt, name: this.st.user.name || "@nonymous",
         sid:this.st.user.sid};
-      this.chats.push(chat);
+      this.$emit("newchat-sent", chat); //useful for corr games
+      this.chats.unshift(chat);
       this.st.conn.send(JSON.stringify({
         code:"newchat", msg:chatTxt, name:chat.name}));
     },
@@ -61,9 +65,11 @@ export default {
 };
 </script>
 
-<style lang="sass">
+<style lang="sass" scoped>
 .my-chatmsg
   color: grey
 .opp-chatmsg
   color: black
+#chat
+  max-width: 100%
 </style>