Skip to content

Commit

Permalink
fix: check your name on Chat
Browse files Browse the repository at this point in the history
  • Loading branch information
neto112 committed Feb 4, 2024
1 parent 3733d8a commit 949b085
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/views/games/GameView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
/>
</div>
<div>
<Messages :singleElement="true" @send="sendChat" :messages="messages" />
<Messages @send="sendChat" :messages="messages" />
</div>
</div>
</v-container>
Expand Down
22 changes: 12 additions & 10 deletions src/views/lobby/Messages.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
<template v-for="(item, index) in messages">
<div
:key="index"
:class="!singleElement ? 'class-left' : 'class-right'"
:class="!checkYourUser(item) ? 'class-left' : 'class-right'"
>
<div v-if="!singleElement">
<div v-if="!checkYourUser(item)">
<b>{{ breakMessage(item.message).player }}</b>
<div
class="class-message"
Expand All @@ -26,9 +26,7 @@
<b>{{ breakMessage(item.message).player }}</b>
<div
class="class-message"
:class="
theme === 'dark' ? 'dark-enemy black--text' : 'light-enemy'
"
:class="theme === 'dark' ? 'dark-enemy' : 'light-enemy'"
>
<span> {{ breakMessage(item.message).message }}</span>
</div>
Expand All @@ -52,11 +50,12 @@
<v-btn block @click="sendMessage">Send</v-btn>
</div>
</template>

<script>
import { mapState } from "vuex";
export default {
name: "Messages",
props: ["messages", "singleElement"],
props: ["messages"],
data() {
return { message: "" };
},
Expand Down Expand Up @@ -85,6 +84,10 @@ export default {
}),
},
methods: {
checkYourUser(item) {
const checkYourName = this.$store.state.socket.loggedIn;
return checkYourName === this.breakMessage(item.message).player;
},
breakMessage(item) {
const colonIndex = item.indexOf(":");
if (colonIndex !== -1) {
Expand Down Expand Up @@ -117,7 +120,6 @@ export default {
height: 450px;
line-height: 1.6;
width: 100%;
/* border: 4px solid blue; */
word-break: break-all;
padding: 12px;
margin-bottom: 12px;
Expand All @@ -143,8 +145,8 @@ export default {
}
.dark-player {
background: #1c85fe;
color: white;
background: #e0e0e0;
color: black;
}
.light-enemy {
Expand All @@ -153,7 +155,7 @@ export default {
}
.dark-enemy {
background: #e0e0e0;
background: #1c85fe;
}
.class-right {
Expand Down

0 comments on commit 949b085

Please sign in to comment.