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") | |
9ddaf8da | 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 | 13 | import { store } from "@/store"; |
cf2343ce BA |
14 | export default { |
15 | name: "my-chat", | |
3837d4f7 | 16 | // Prop 'pastChats' for corr games where chats are on server |
ac8f441c | 17 | props: ["players","pastChats","newChat"], |
cf2343ce BA |
18 | data: function() { |
19 | return { | |
5c8e044f | 20 | st: store.state, |
cf2343ce BA |
21 | chats: [], //chat messages after human game |
22 | }; | |
23 | }, | |
ac8f441c BA |
24 | watch: { |
25 | newChat: function(chat) { | |
26 | if (chat.msg != "") | |
27 | this.chats.unshift({msg:chat.msg, name:chat.name || "@nonymous"}); | |
28 | }, | |
cf2343ce | 29 | }, |
5c8e044f BA |
30 | methods: { |
31 | classObject: function(chat) { | |
32 | return { | |
dcd68c41 | 33 | "my-chatmsg": chat.name == this.st.user.name, |
ac8f441c | 34 | "opp-chatmsg": !!this.players && this.players.some( |
dcd68c41 | 35 | p => p.name == chat.name && p.name != this.st.user.name) |
5c8e044f BA |
36 | }; |
37 | }, | |
38 | sendChat: function() { | |
39 | let chatInput = document.getElementById("inputChat"); | |
b1ea2149 BA |
40 | const chatTxt = chatInput.value.trim(); |
41 | if (chatTxt == "") | |
42 | return; //nothing to send | |
5c8e044f | 43 | chatInput.value = ""; |
dcd68c41 | 44 | const chat = {msg:chatTxt, name: this.st.user.name || "@nonymous"}; |
ac8f441c | 45 | this.$emit("mychat", chat); |
9ca1e26b | 46 | this.chats.unshift(chat); |
5c8e044f BA |
47 | }, |
48 | }, | |
49 | }; | |
50 | </script> | |
51 | ||
4f887105 | 52 | <style lang="sass" scoped> |
5c8e044f BA |
53 | .my-chatmsg |
54 | color: grey | |
55 | .opp-chatmsg | |
56 | color: black | |
57 | </style> |