Skip to content

Commit

Permalink
chore: merge pull request PapillonApp#348 from imyanice/main
Browse files Browse the repository at this point in the history
fix: include unjustified delays in missed class
  • Loading branch information
Vexcited authored Nov 11, 2024
2 parents e490165 + 1fb88b6 commit 223e901
Showing 1 changed file with 16 additions and 11 deletions.
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

0 comments on commit 223e901

Please sign in to comment.