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

Commit

Permalink
intrn(consultation): update the consultation accordingly
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Sep 17, 2022
1 parent c331204 commit 1ab45de
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions pages/consultation/read.page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
@picked-consultation="visitConsultation"/>
</template>
<template #chat-window>
<ChatWindow :consultation="consultation" :chat-messages="chatMessages"/>
<ChatWindow
:consultation="consultation"
:chat-messages="chatMessages"
@updated-consultation-attributes="updateConsultationAttributes"/>
</template>
</ConsultationShell>
</template>
Expand All @@ -41,6 +44,7 @@ import type {
DeserializedChatMessageActivityListDocument
} from "$/types/documents/chat_message_activity"
import type {
ConsultationAttributes,
DeserializedConsultationResource,
DeserializedConsultationListDocument
} from "$/types/documents/consultation"
Expand Down Expand Up @@ -107,6 +111,14 @@ function visitConsultation(consultationID: string): void {
assignPath(path)
}
function updateConsultationAttributes(updatedAttributes: ConsultationAttributes<"deserialized">)
: void {
consultation.value = {
...consultation.value,
...updatedAttributes
}
}
function mergeDeserializedMessages(messages: DeserializedChatMessageResource<"user">[]): void {
chatMessages.value = {
...chatMessages.value,
Expand All @@ -119,7 +131,7 @@ function mergeDeserializedMessages(messages: DeserializedChatMessageResource<"us
second.createdAt
))
return comparison || Math.sign(Number(first.id) - Number(second.id))
return comparison || first.id.localeCompare(second.id)
})
}
}
Expand All @@ -130,9 +142,9 @@ function createMessage(message: ChatMessageDocument<"read">): void {
}
function updateMessage(message: ChatMessageDocument<"read">): void {
const IDofMessageToRemove = message.data.id
const IDOfMessageToRemove = message.data.id
chatMessages.value.data = chatMessages.value.data.filter(
chatMessage => chatMessage.id !== IDofMessageToRemove
chatMessage => chatMessage.id !== IDOfMessageToRemove
)
createMessage(message)
Expand Down

0 comments on commit 1ab45de

Please sign in to comment.