Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
feat(chat): scroll automatically
Browse files Browse the repository at this point in the history
Co-authored-by: Kenneth Trecy Tobias <19201.tobias.kennethtrecy.c@gmail.com>
  • Loading branch information
lemredd and KennethTrecy committed Nov 19, 2022
1 parent 2c6e5e0 commit 0942d4a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions components/consultation/chat_window.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
@hide-action-taken-overlay="hideActionTakenOverlay"
@cancel-consultation="cancelConsultation"
@finish-consultation="finishConsultation"/>
<div class="selected-consultation-chats">
<div ref="selectedConsultationChats" class="selected-consultation-chats">
<div
v-if="!isOngoing"
class="selected-consultation-new">
Expand Down Expand Up @@ -113,10 +113,13 @@
</style>

<script setup lang="ts">
import { ref, computed, onMounted } from "vue"
import { ref, computed, onMounted, watch } from "vue"
import type { FullTime } from "$@/types/independent"
import type { DeserializedChatMessageListDocument } from "$/types/documents/chat_message"
import type {
DeserializedChatMessageActivityResource
} from "$/types/documents/chat_message_activity"
import type {
ConsultationAttributes,
DeserializedConsultationResource
Expand Down Expand Up @@ -151,11 +154,13 @@ interface CustomEvents {
const emit = defineEmits<CustomEvents>()
const props = defineProps<{
consultation: DeserializedConsultationResource<"consultant"|"consultantRole">
currentConsultationActivity: DeserializedChatMessageActivityResource[]
chatMessages: DeserializedChatMessageListDocument<"user">
hasLoadedChatMessages: boolean,
isConsultationListShown: boolean
}>()
const selectedConsultationChats = ref<HTMLDivElement|null>(null)
const sortedMessagesByTime = computed(() => {
const { "chatMessages": { "data": rawData } } = props
return [ ...rawData ].sort((left, right) => {
Expand All @@ -165,6 +170,15 @@ const sortedMessagesByTime = computed(() => {
return Math.sign(leftSeconds - rightSeconds)
})
})
const chatMessageActivities = computed(() => props.currentConsultationActivity)
watch(chatMessageActivities, () => {
const height = selectedConsultationChats.value?.clientHeight
selectedConsultationChats.value?.scrollBy(0, height as number)
}, {
"flush": "post"
})
function loadPreviousMessages() {
emit("loadPreviousMessages")
}
Expand Down

0 comments on commit 0942d4a

Please sign in to comment.