fix auto scroll in chat history

This commit is contained in:
Sam Hoffman
2026-01-13 00:33:53 -05:00
parent afe555f51e
commit f86b48f43e

View File

@@ -1,5 +1,5 @@
<script setup> <script setup>
import { computed } from "vue"; import { computed, watch, useTemplateRef } from "vue";
import { useIRCStore } from "@/stores/irc"; import { useIRCStore } from "@/stores/irc";
const props = defineProps(["messages", "me"]); const props = defineProps(["messages", "me"]);
@@ -15,14 +15,26 @@ const timeFormatter = new Intl.DateTimeFormat("en-US", {
minute: "2-digit", minute: "2-digit",
hour12: true, hour12: true,
}); });
function formatTime(ts) { function formatTime(ts) {
const date = new Date(ts); const date = new Date(ts);
return timeFormatter.format(date); return timeFormatter.format(date);
} }
const chatHistory = useTemplateRef("chat-scrollback");
watch(
() => props.messages,
() =>
nextTick(() => {
chatHistory.value.scrollTop = chatHistory.value.scrollHeight;
}),
{ deep: true },
);
</script> </script>
<template> <template>
<v-sheet class="message-list d-flex"> <v-sheet ref="chat-history" class="message-list d-flex">
<div ref="chat-scrollback">
<v-list> <v-list>
<v-list-item <v-list-item
v-for="msg in messagesReverse" v-for="msg in messagesReverse"
@@ -31,7 +43,7 @@ function formatTime(ts) {
> >
<v-list-item-title> <v-list-item-title>
<span <span
class="message-nick" class="message-nick font-weight-bold"
:class="{ 'text-primary': me === msg.nick }" :class="{ 'text-primary': me === msg.nick }"
> >
{{ msg.nick }} {{ msg.nick }}
@@ -40,11 +52,10 @@ function formatTime(ts) {
formatTime(msg.time) formatTime(msg.time)
}}</span> }}</span>
</v-list-item-title> </v-list-item-title>
<v-list-item-subtitle>
{{ msg.message }} {{ msg.message }}
</v-list-item-subtitle>
</v-list-item> </v-list-item>
</v-list> </v-list>
</div>
</v-sheet> </v-sheet>
</template> </template>