Some more cleaning + fixes
[vchess.git] / client / src / components / Chat.vue
CommitLineData
cf2343ce 1<template lang="pug">
a1c48034 2div
910d631b
BA
3 input#inputChat(
4 type="text"
5 :placeholder="st.tr['Chat here']"
6 @keyup.enter="sendChat()"
7 )
9a3049f3
BA
8 button(@click="sendChat()") {{ st.tr["Send"] }}
9 p(v-for="chat in chats.concat(pastChats)")
10 span.name {{ chat.name }} :&nbsp;
910d631b
BA
11 span(
12 :class="classObject(chat)"
13 v-html="chat.msg"
14 )
cf2343ce
BA
15</template>
16
17<script>
5c8e044f 18import { store } from "@/store";
cf2343ce
BA
19export default {
20 name: "my-chat",
3837d4f7 21 // Prop 'pastChats' for corr games where chats are on server
6808d7a1 22 props: ["players", "pastChats", "newChat"],
cf2343ce
BA
23 data: function() {
24 return {
5c8e044f 25 st: store.state,
6808d7a1 26 chats: [] //chat messages after human game
cf2343ce
BA
27 };
28 },
ac8f441c
BA
29 watch: {
30 newChat: function(chat) {
31 if (chat.msg != "")
6808d7a1
BA
32 this.chats.unshift({ msg: chat.msg, name: chat.name || "@nonymous" });
33 }
cf2343ce 34 },
5c8e044f
BA
35 methods: {
36 classObject: function(chat) {
37 return {
dcd68c41 38 "my-chatmsg": chat.name == this.st.user.name,
6808d7a1
BA
39 "opp-chatmsg":
40 !!this.players &&
41 this.players.some(
42 p => p.name == chat.name && p.name != this.st.user.name
43 )
5c8e044f
BA
44 };
45 },
46 sendChat: function() {
47 let chatInput = document.getElementById("inputChat");
b1ea2149 48 const chatTxt = chatInput.value.trim();
6808d7a1 49 if (chatTxt == "") return; //nothing to send
5c8e044f 50 chatInput.value = "";
6808d7a1 51 const chat = { msg: chatTxt, name: this.st.user.name || "@nonymous" };
ac8f441c 52 this.$emit("mychat", chat);
9ca1e26b 53 this.chats.unshift(chat);
6808d7a1
BA
54 }
55 }
5c8e044f
BA
56};
57</script>
58
4f887105 59<style lang="sass" scoped>
9a3049f3
BA
60.name
61 color: #abb2b9
910d631b 62
5c8e044f 63.my-chatmsg
9a3049f3 64 color: #7d3c98
5c8e044f 65.opp-chatmsg
9a3049f3 66 color: #2471a3
5c8e044f 67</style>