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