projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Some fixes
[vchess.git]
/
client
/
src
/
components
/
Chat.vue
diff --git
a/client/src/components/Chat.vue
b/client/src/components/Chat.vue
index
cd3c3c8
..
65e0dcb
100644
(file)
--- a/
client/src/components/Chat.vue
+++ b/
client/src/components/Chat.vue
@@
-1,9
+1,12
@@
<template lang="pug">
<template lang="pug">
-.card
+div
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 chats" :class="classObject(chat)" v-html="chat.msg")
+ p(v-for="chat in chats" :class="classObject(chat)"
+ v-html="chat.name + ': ' + chat.msg")
+ p(v-for="chat in pastChats" :class="classObject(chat)"
+ v-html="chat.name + ': ' + chat.msg")
</template>
<script>
</template>
<script>
@@
-11,7
+14,8
@@
import { store } from "@/store";
export default {
name: "my-chat",
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,
data: function() {
return {
st: store.state,
@@
-25,8
+29,8
@@
export default {
const data = JSON.parse(msg.data);
if (data.code == "newchat") //only event at this level
{
const data = JSON.parse(msg.data);
if (data.code == "newchat") //only event at this level
{
- this.chats.unshift({msg:data.msg,
- name:data.name || "@nonymous", sid:data.from});
+ this.chats.unshift({msg:data.msg,
name:data.name || "@nonymous"});
+ this.$emit("newchat-received"); //data not required here
}
};
const socketCloseListener = () => {
}
};
const socketCloseListener = () => {
@@
-40,18
+44,19
@@
export default {
methods: {
classObject: function(chat) {
return {
methods: {
classObject: function(chat) {
return {
- "my-chatmsg": chat.
sid == this.st.user.sid
,
+ "my-chatmsg": chat.
name == this.st.user.name
,
"opp-chatmsg": this.players.some(
"opp-chatmsg": this.players.some(
- p => p.
sid == chat.sid && p.sid != this.st.user.sid
)
+ p => p.
name == chat.name && p.name != this.st.user.name
)
};
},
sendChat: function() {
let chatInput = document.getElementById("inputChat");
};
},
sendChat: function() {
let chatInput = document.getElementById("inputChat");
- const chatTxt = chatInput.value;
+ const chatTxt = chatInput.value.trim();
+ if (chatTxt == "")
+ return; //nothing to send
chatInput.value = "";
chatInput.value = "";
- const chat = {msg:chatTxt, name: this.st.user.name || "@nonymous",
- sid:this.st.user.sid};
- this.$emit("newchat", chat); //useful for corr games
+ const chat = {msg:chatTxt, name: this.st.user.name || "@nonymous"};
+ 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}));
this.chats.unshift(chat);
this.st.conn.send(JSON.stringify({
code:"newchat", msg:chatTxt, name:chat.name}));
@@
-65,6
+70,4
@@
export default {
color: grey
.opp-chatmsg
color: black
color: grey
.opp-chatmsg
color: black
-#chat
- max-width: 100%
</style>
</style>