Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: include unjustified delays in missed class #348

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/views/account/Home/Elements/AttendanceElement.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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
Expand All @@ -27,7 +23,7 @@ const AttendanceElement: React.FC<AttendanceElementProps> = ({ 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 {
Expand All @@ -39,13 +35,13 @@ const AttendanceElement: React.FC<AttendanceElementProps> = ({ 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;
Expand All @@ -61,14 +57,23 @@ const AttendanceElement: React.FC<AttendanceElementProps> = ({ 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) {
const [hours, minutes] = absence.hours.split("h").map(Number);
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 {
Expand Down
Loading