From 72edbf338d8f688542ff05bd144ff87f6c892e44 Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Mon, 15 Dec 2025 15:28:38 +0100 Subject: [PATCH] "Refactor MyWashStart.vue: add elapsed wash timer with start/stop logic, integrate `onUnmounted` for cleanup, and enhance UI with completed wash step." --- .../userDashboard/wash/MyWashStart.vue | 44 ++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/src/views/dashboards/userDashboard/wash/MyWashStart.vue b/src/views/dashboards/userDashboard/wash/MyWashStart.vue index 612013b5..e8185360 100644 --- a/src/views/dashboards/userDashboard/wash/MyWashStart.vue +++ b/src/views/dashboards/userDashboard/wash/MyWashStart.vue @@ -8,7 +8,7 @@ import {BButton, BField, BIcon, BInput, BMessage, BRadioButton, BStepItem, BStep import WhiteBoxCard from "@/components/displays/boxes/WhiteBoxCard.vue"; import {getDepartmentsGuest} from "@/components/pagination/departmentTabs.vue"; -import {computed, onMounted, ref, watch} from "vue"; +import {computed, onMounted, onUnmounted, ref, watch} from "vue"; const guestDepartments = ref([]); @@ -89,11 +89,30 @@ const isLaneAvailable = (lane) => { }; const washInProgress = ref(false); -const washLaneId = ref(null); -const washStartTime = ref(null); +const washLaneId = ref(null); +const washStartTime = ref(null); +// Reactive "now" to drive the timer UI +const now = ref(Date.now()); +let timerInterval: ReturnType | null = null; + +const startElapsedTimer = () => { + // ensure only one interval + if (timerInterval) clearInterval(timerInterval); + timerInterval = setInterval(() => { + now.value = Date.now(); + }, 1000); +}; + +const stopElapsedTimer = () => { + if (timerInterval) { + clearInterval(timerInterval); + timerInterval = null; + } +}; + const timeSinceWashStart = computed(() => { if (washInProgress.value && washStartTime.value) { - return Date.now() - washStartTime.value; + return now.value - washStartTime.value; } return 0; }); @@ -127,6 +146,7 @@ const onStartWash = (laneId, licensePlate, customerNumber) => { // Start time tracking washStartTime.value = Date.now(); washInProgress.value = true; + startElapsedTimer(); // Go to the wash in progress step currentStep.value = steps.WASH_IN_PROGRESS; // Optionally, you can redirect the user or reset the form here @@ -159,6 +179,7 @@ const onStopWash = (laneId) => { //alert('Vask stoppet succesfuldt!'); washInProgress.value = false; washLaneId.value = null; + stopElapsedTimer(); } else { alert('Fejl ved stop af vask: ' + (response.data.message || 'Ukendt fejl.')); } @@ -169,6 +190,10 @@ const onStopWash = (laneId) => { }); }; +onUnmounted(() => { + stopElapsedTimer(); +}); + const getWashStatus = (laneId) => { if (!nearestDepartment.value) { alert('Ingen afdeling valgt.'); @@ -405,7 +430,6 @@ watch(() => nearestDepartment.value, (newValue) => {

Vask i gang

- Vasken har været i gang i {{ Math.floor(timeSinceWashStart / 60000) }} minutter og {{ Math.floor((timeSinceWashStart % 60000) / 1000) }} sekunder.

@@ -424,6 +448,16 @@ watch(() => nearestDepartment.value, (newValue) => { >Stop vask + + +

Vask færdig

+

+ Din vask er nu færdig! Tak fordi du brugte vores selvbetjeningsvask. +

+

+ Vi håber, at du er tilfreds med resultatet. Hvis du har brug for yderligere assistance, er du velkommen til at kontakte vores personale. +

+