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

Commit

Permalink
refactor(consultation): retain the reactivity of props in controller
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Sep 17, 2022
1 parent b45fff8 commit 688f234
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions components/consultation/chat_window/user_controller.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,23 @@ import type { DeserializedConsultationResource } from "$/types/documents/consult
import calculateMillisecondDifference from "$@/helpers/calculate_millisecond_difference"
const { consultation } = defineProps<{
const props = defineProps<{
consultation: DeserializedConsultationResource<"consultant"|"consultantRole">
}>()
const currentTime = ref<Date>(new Date())
const differenceFromSchedule = computed<number>(() => calculateMillisecondDifference(
consultation.scheduledStartAt,
props.consultation.scheduledStartAt,
currentTime.value
))
const isAfterScheduledStart = computed<boolean>(() => differenceFromSchedule.value < 0)
const hasStarted = computed<boolean>(() => consultation.startedAt !== null)
const hasFinished = computed<boolean>(() => consultation.finishedAt !== null)
const hasDeleted = computed<boolean>(() => consultation.deletedAt !== null)
const isAfterScheduledStart = computed<boolean>(() => differenceFromSchedule.value
< 0)
const hasStarted = computed<boolean>(() => props.consultation.startedAt !== null)
const hasFinished = computed<boolean>(() => props.consultation.finishedAt !== null)
const hasDeleted = computed<boolean>(() => props.consultation.deletedAt !== null)
const willSoonStart = computed<boolean>(() => differenceFromSchedule.value > 0)
const willSoonStart = computed<boolean>(() => differenceFromSchedule.value < 0)
const willStart = computed<boolean>(() => {
const mayStart = differenceFromSchedule.value === 0 || isAfterScheduledStart.value
return mayStart && !hasStarted.value
Expand All @@ -87,9 +88,13 @@ const unusedIsDone = computed<boolean>(() => {
const unusedIsCanceled = computed<boolean>(() => !isAfterScheduledStart.value && hasDeleted.value)
const unusedIsAutoTerminated = computed<boolean>(() => {
const hasTerminated = isAfterScheduledStart.value && hasDeleted.value
return hasTerminated && consultation.actionTaken === null
return hasTerminated && props.consultation.actionTaken === null
})
setInterval(() => {
currentTime.value = new Date()
}, 1000)
interface CustomEvents {
(eventName: "startConsultation"): void
}
Expand Down

0 comments on commit 688f234

Please sign in to comment.