Skip to content

Commit

Permalink
[Client] Moved Chat History to its own component
Browse files Browse the repository at this point in the history
  • Loading branch information
Senryoku committed Jun 1, 2024
1 parent b0ec444 commit e541be8
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 130 deletions.
1 change: 1 addition & 0 deletions client/src/App.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export default defineComponent({
CardPool,
CardPopup,
CardStats: defineAsyncComponent(() => import("./components/CardStats.vue")),
ChatHistory: defineAsyncComponent(() => import("./components/ChatHistory.vue")),
CollectionComponent: defineAsyncComponent({
loader: () => import("./components/Collection.vue"),
loadingComponent: LoadingComponent,
Expand Down
57 changes: 9 additions & 48 deletions client/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -782,55 +782,16 @@
@click="displayChatHistory = !displayChatHistory"
v-tooltip="'Display chat history.'"
></font-awesome-icon>
<div
class="chat-history"
v-show="displayChatHistory"
<ChatHistory
v-if="displayChatHistory"
@focusout="displayChatHistory = false"
tabindex="0"
>
<template v-if="messagesHistory && messagesHistory.length > 0">
<ol>
<li
v-for="msg in messagesHistory.slice().reverse()"
:title="new Date(msg.timestamp).toLocaleTimeString()"
:key="msg.timestamp"
>
<span class="chat-author">
<template v-if="msg.author !== userID">
<template v-if="!mutedUsers.has(msg.author)">
<font-awesome-icon
class="clickable"
icon="fa-solid fa-comment-slash"
@click="mutedUsers.add(msg.author)"
v-tooltip="`Mute this user.`"
></font-awesome-icon>
</template>
<template v-else>
<font-awesome-icon
class="clickable"
icon="fa-solid fa-comment"
@click="mutedUsers.delete(msg.author)"
v-tooltip="`Unmute this user.`"
></font-awesome-icon>
</template>
</template>
{{
msg.author in userByID
? userByID[msg.author].userName
: msg.author === sessionOwner && sessionOwnerUsername
? sessionOwnerUsername
: "(Left)"
}}
</span>
<span class="chat-message">
<template v-if="!mutedUsers.has(msg.author)">{{ msg.text }}</template>
<template v-else><em>(Muted)</em></template>
</span>
</li>
</ol>
</template>
<template v-else>No messages in chat history.</template>
</div>
:messagesHistory="messagesHistory"
:userID="userID"
:sessionOwner="sessionOwner"
:sessionOwnerUsername="sessionOwnerUsername"
:userByID="userByID"
:mutedUsers="mutedUsers"
/>
</div>
</div>
<div class="main-content">
Expand Down
148 changes: 148 additions & 0 deletions client/src/components/ChatHistory.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<template>
<div class="chat-history" tabindex="0">
<ol v-if="messagesHistory && messagesHistory.length > 0">
<li
v-for="msg in reversedMessages"
:title="new Date(msg.timestamp).toLocaleTimeString()"
:key="msg.timestamp"
>
<span class="chat-author">
<template v-if="msg.author !== userID">
<template v-if="!mutedUsers.has(msg.author)">
<font-awesome-icon
class="clickable"
icon="fa-solid fa-comment-slash"
@click="mutedUsers.add(msg.author)"
v-tooltip="`Mute this user.`"
></font-awesome-icon>
</template>
<template v-else>
<font-awesome-icon
class="clickable"
icon="fa-solid fa-comment"
@click="mutedUsers.delete(msg.author)"
v-tooltip="`Unmute this user.`"
></font-awesome-icon>
</template>
</template>
{{
msg.author in userByID
? userByID[msg.author].userName
: msg.author === sessionOwner && sessionOwnerUsername
? sessionOwnerUsername
: "(Left)"
}}
</span>
<span class="chat-message">
<template v-if="!mutedUsers.has(msg.author)">{{ msg.text }}</template>
<template v-else><em>(Muted)</em></template>
</span>
</li>
</ol>
<template v-else>No messages in chat history.</template>
</div>
</template>

<script setup lang="ts">
import { computed } from "vue";
import { UserData } from "../../../src/Session/SessionTypes";
const props = defineProps<{
messagesHistory: {
author: string;
text: string;
timestamp: number;
}[];
userID: string;
sessionOwner: string;
sessionOwnerUsername: string;
userByID: Record<string, UserData>;
mutedUsers: Set<string>;
}>();
const reversedMessages = computed(() => props.messagesHistory.slice().reverse());
</script>

<style scoped>
.chat-history {
position: absolute;
top: calc(100% + 0.25em);
right: 0;
background: rgba(255, 255, 255, 0.5);
padding: 0.5em;
border-radius: 0.5em;
color: black;
max-width: 50vw;
width: max-content;
z-index: 1;
}
.chat-history:before {
content: "";
position: absolute;
top: 0;
right: calc(14px + 0.5em);
width: 0;
height: 0;
border: 14px solid transparent;
border-bottom-color: rgba(255, 255, 255, 0.5);
border-top: 0;
border-right: 0;
margin-left: -7px;
margin-top: -14px;
}
.chat-history ol {
display: flex;
flex-direction: column;
min-width: 20vw;
max-height: 60vh;
margin: 0;
padding: 0;
list-style: none;
overflow-y: scroll;
white-space: initial;
}
@media (orientation: landscape) {
.chat-history ol {
max-width: 60vw;
}
}
@media (orientation: portrait) {
.chat-history ol {
max-width: 90vw;
}
}
.chat-history li {
display: inline-flex;
align-items: stretch;
background: white;
border-radius: 0.25em;
margin: 0.2em;
}
.chat-history li span {
padding: 0.25em;
}
.chat-history li .chat-author {
border-radius: 0.25em 0 0 0.25em;
background: #444;
color: #ddd;
font-weight: bold;
white-space: nowrap;
min-width: 18ch;
max-width: 18ch;
overflow: hidden;
text-overflow: ellipsis;
}
.chat-history li .chat-message {
border-radius: 0 0.25em 0.25em 0;
background: white;
flex-grow: 2;
word-wrap: anywhere;
}
</style>
82 changes: 0 additions & 82 deletions client/src/css/chat.css
Original file line number Diff line number Diff line change
Expand Up @@ -84,85 +84,3 @@
margin-left: -7px;
margin-top: -14px;
}

.chat-history {
position: absolute;
top: calc(100% + 0.25em);
right: 0;
background: rgba(255, 255, 255, 0.5);
padding: 0.5em;
border-radius: 0.5em;
color: black;
max-width: 50vw;
width: max-content;
z-index: 1;
}

.chat-history:before {
content: "";
position: absolute;
top: 0;
right: calc(14px + 0.5em);
width: 0;
height: 0;
border: 14px solid transparent;
border-bottom-color: rgba(255, 255, 255, 0.5);
border-top: 0;
border-right: 0;
margin-left: -7px;
margin-top: -14px;
}

.chat-history ol {
display: flex;
flex-direction: column;
min-width: 20vw;
max-height: 60vh;
margin: 0;
padding: 0;
list-style: none;
overflow-y: scroll;
white-space: initial;
}

@media (orientation: landscape) {
.chat-history ol {
max-width: 60vw;
}
}

@media (orientation: portrait) {
.chat-history ol {
max-width: 90vw;
}
}
.chat-history li {
display: inline-flex;
align-items: stretch;
background: white;
border-radius: 0.25em;
margin: 0.2em;
}

.chat-history li span {
padding: 0.25em;
}

.chat-history li .chat-author {
border-radius: 0.25em 0 0 0.25em;
background: #444;
color: #ddd;
font-weight: bold;
white-space: nowrap;
min-width: 18ch;
max-width: 18ch;
overflow: hidden;
text-overflow: ellipsis;
}

.chat-history li .chat-message {
border-radius: 0 0.25em 0.25em 0;
background: white;
flex-grow: 2;
word-wrap: anywhere;
}

0 comments on commit e541be8

Please sign in to comment.