From 1fb88b60ffe01f1a1a84e65d8e33a8d64ef0fbe8 Mon Sep 17 00:00:00 2001 From: Yanice Date: Mon, 11 Nov 2024 15:34:56 +0100 Subject: [PATCH] fix: include unjustified delays in missed class --- .../Home/Elements/AttendanceElement.tsx | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/views/account/Home/Elements/AttendanceElement.tsx b/src/views/account/Home/Elements/AttendanceElement.tsx index 918cb0ff1..559d1cdad 100644 --- a/src/views/account/Home/Elements/AttendanceElement.tsx +++ b/src/views/account/Home/Elements/AttendanceElement.tsx @@ -1,4 +1,5 @@ -import React, { useEffect } from "react"; +import React from "react"; +import { useEffect } from "react"; import { NativeListHeader } from "@/components/Global/NativeComponents"; import { updateGradesPeriodsInCache } from "@/services/grades"; import { useCurrentAccount } from "@/stores/account"; @@ -8,13 +9,8 @@ import { PressableScale } from "react-native-pressable-scale"; import RedirectButton from "@/components/Home/RedirectButton"; import { PapillonNavigation } from "@/router/refs"; import { log } from "@/utils/logger/logger"; +import type { Attendance } from "@/services/shared/Attendance"; -interface Attendance { - absences: { - hours: string; - justified: boolean; - }[]; -} interface AttendanceElementProps { onImportance: (value: number) => unknown @@ -27,7 +23,7 @@ const AttendanceElement: React.FC = ({ onImportance }) = const ImportanceHandler = () => { if (attendances && defaultPeriod) { - let totalMissed = formatTotalMissed(attendances[defaultPeriod]); + const totalMissed = formatTotalMissed(attendances[defaultPeriod]); if (totalMissed.total.hours > 0 || totalMissed.total.minutes > 0) { onImportance(3); } else { @@ -39,13 +35,13 @@ const AttendanceElement: React.FC = ({ onImportance }) = }; useEffect(() => { - void async function () { + void (async () => { log("update grades periods in cache", "attendance:updateGradesPeriodsInCache"); if (account?.instance) { await updateGradesPeriodsInCache(account); } ImportanceHandler(); - }(); + })(); }, [account?.instance]); const totalMissed = attendances && defaultPeriod ? attendances[defaultPeriod] : null; @@ -61,7 +57,10 @@ const AttendanceElement: React.FC = ({ onImportance }) = const totalHours = data.absences.reduce((sum, absence) => { const [hours, minutes] = absence.hours.split("h").map(Number); return sum + hours + (minutes || 0) / 60; - }, 0); + }, 0) + data.delays.reduce((sum, delay) => { + const [hours, minutes] = [Math.floor(delay.duration / 60), delay.duration % 60]; + return sum + hours + (minutes || 0) / 60; + }, 0);; const unJustifiedHours = data.absences.reduce((sum, absence) => { if (!absence.justified) { @@ -69,6 +68,12 @@ const AttendanceElement: React.FC = ({ onImportance }) = return sum + hours + (minutes || 0) / 60; } return sum; + }, 0) + data.delays.reduce((sum, delay) => { + if (!delay.justified) { + const [hours, minutes] = [Math.floor(delay.duration / 60), delay.duration % 60]; + return sum + hours + (minutes || 0) / 60; + } + return sum; }, 0); return {