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