From 5822d8fdb8368aee4cbf65cf39ee2726af09af8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=95=82=F0=9D=95=AA=F0=9D=95=9D=F0=9D=95=9A?= =?UTF-8?q?=F0=9D=95=92=F0=9D=95=9F?= Date: Thu, 17 Oct 2024 23:37:47 +0200 Subject: [PATCH 1/8] correction influence fausse + correction await inutile + changement lorsque influence = 0 --- src/utils/grades/getAverages.ts | 2 +- src/views/account/Grades/Document.tsx | 6 +++--- src/views/account/Grades/Latest/LatestGrades.tsx | 5 +++-- .../account/Grades/Latest/LatestGradesItem.tsx | 4 ++-- src/views/account/Grades/Subject/GradeItem.tsx | 5 +++-- src/views/account/Grades/Subject/SubjectList.tsx | 6 +++--- src/views/account/Home/Elements/GradesElement.tsx | 14 +++++++++++++- 7 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/utils/grades/getAverages.ts b/src/utils/grades/getAverages.ts index a7dfa1661..0a9da21f9 100644 --- a/src/utils/grades/getAverages.ts +++ b/src/utils/grades/getAverages.ts @@ -84,7 +84,7 @@ export const getSubjectAverage = (subject: Grade[], target: Target = "student"): // Fonction pour calculer la différence de moyenne avec et sans certaines notes const getAverageDiffGrade = (grades: Grade[], list: Grade[], target: Target = "student"): AverageDiffGrade => { const baseAverage = getSubjectAverage(list, target); // Calculer la moyenne de base avec toutes les notes - const baseWithoutGradeAverage = getSubjectAverage(list.filter(grade => !grades.includes(grade)), target); // Calculer la moyenne sans certaines notes + const baseWithoutGradeAverage = getSubjectAverage(list.filter(grade =>JSON.stringify(grades[0]) !== JSON.stringify(grade)), target); // Calculer la moyenne sans certaines notes return { difference: baseWithoutGradeAverage - baseAverage, // Calculer la différence entre les deux moyennes diff --git a/src/views/account/Grades/Document.tsx b/src/views/account/Grades/Document.tsx index 3381a6d6b..df0e5420a 100644 --- a/src/views/account/Grades/Document.tsx +++ b/src/views/account/Grades/Document.tsx @@ -105,16 +105,16 @@ const GradeDocument: Screen<"GradeDocument"> = ({ route, navigation }) => { title: "Moyenne générale", description: "Impact de la note sur la moyenne générale", value: gradeDiff.difference === undefined ? "???" : - (gradeDiff.difference > 0 ? "- " : "+ ") + + (gradeDiff.difference > 0 ? "- " : gradeDiff.difference === 0 ? "+/- " : "+ ") + gradeDiff.difference.toFixed(2).replace("-", "") + " pts", - color: gradeDiff.difference === undefined ? void 0 : (gradeDiff.difference < 0 ? "#4CAF50" : "#F44336"), + color: gradeDiff.difference === undefined ? void 0 : (gradeDiff.difference < 0 ? "#4CAF50" : gradeDiff.difference === 0 ? theme.colors.text : "#F44336"), }, !grade.average.disabled && { icon: , title: "Moyenne de la classe", description: "Impact de la note sur la moyenne de la classe", value: classDiff.difference === undefined ? "???" : - (classDiff.difference > 0 ? "- " : "+ ") + + (classDiff.difference > 0 ? "- " : gradeDiff.difference === 0 ? "+/- " : "+ ") + classDiff.difference.toFixed(2).replace("-", "") + " pts", } ] diff --git a/src/views/account/Grades/Latest/LatestGrades.tsx b/src/views/account/Grades/Latest/LatestGrades.tsx index 7881530ce..b5c51b069 100644 --- a/src/views/account/Grades/Latest/LatestGrades.tsx +++ b/src/views/account/Grades/Latest/LatestGrades.tsx @@ -6,6 +6,7 @@ import Reanimated, { LinearTransition } from "react-native-reanimated"; import GradesLatestItem from "./LatestGradesItem"; +import { Grade } from "@/services/shared/Grade"; const GradesLatestList = (props: GradesLatestListProps) => { const { latestGrades, navigation, allGrades } = props; @@ -30,8 +31,8 @@ const GradesLatestList = (props: GradesLatestListProps) => { gap: 10, }} > - {latestGrades.map((grade, index) => ( - + {latestGrades.map((grade: Grade, index: number) => ( + ))} diff --git a/src/views/account/Grades/Latest/LatestGradesItem.tsx b/src/views/account/Grades/Latest/LatestGradesItem.tsx index 261b366f1..787ec8c7d 100644 --- a/src/views/account/Grades/Latest/LatestGradesItem.tsx +++ b/src/views/account/Grades/Latest/LatestGradesItem.tsx @@ -18,8 +18,8 @@ const GradesLatestItem: React.FC = ({ grade, i, navigation const [subjectData, setSubjectData] = useState({ color: "#888888", pretty: "Matière inconnue", emoji: "❓", }); - const fetchSubjectData = async () => { - const data = await getSubjectData(grade.subjectName); + const fetchSubjectData = () => { + const data = getSubjectData(grade.subjectName); setSubjectData(data); }; diff --git a/src/views/account/Grades/Subject/GradeItem.tsx b/src/views/account/Grades/Subject/GradeItem.tsx index 357fa7025..cd7b2da4c 100644 --- a/src/views/account/Grades/Subject/GradeItem.tsx +++ b/src/views/account/Grades/Subject/GradeItem.tsx @@ -12,9 +12,10 @@ interface GradeItemProps { navigation: NativeStackNavigationProp index: number; totalItems: number; + allGrades: Grade[]; } -const GradeItem: React.FC = ({ subject, grade, navigation, index, totalItems }) => { +const GradeItem: React.FC = ({ subject, grade, navigation, index, totalItems, allGrades }) => { const subjectData = useMemo(() => getSubjectData(subject.average.subjectName), [subject.average.subjectName]); const formattedDate = new Date(grade.timestamp).toLocaleDateString("fr-FR", { @@ -31,7 +32,7 @@ const GradeItem: React.FC = ({ subject, grade, navigation, index return ( navigation.navigate("GradeDocument", { grade })} + onPress={() => navigation.navigate("GradeDocument", { grade, allGrades })} chevron={false} animated leading={ diff --git a/src/views/account/Grades/Subject/SubjectList.tsx b/src/views/account/Grades/Subject/SubjectList.tsx index af88a497f..2601765cb 100644 --- a/src/views/account/Grades/Subject/SubjectList.tsx +++ b/src/views/account/Grades/Subject/SubjectList.tsx @@ -5,7 +5,7 @@ import React, { useEffect, useState } from "react"; import { View } from "react-native"; import Reanimated, { FadeInDown, FadeInUp, FadeOutUp } from "react-native-reanimated"; import SubjectTitle from "./SubjectTitle"; -import { GradeInformation, type Grade, type GradesPerSubject } from "@/services/shared/Grade"; +import { type Grade, type GradesPerSubject } from "@/services/shared/Grade"; import type { NativeStackNavigationProp } from "@react-navigation/native-stack"; import type { RouteParameters } from "@/router/helpers/types"; @@ -24,8 +24,8 @@ const SubjectItem: React.FC = ({ color: "#888888", pretty: "Matière inconnue", emoji: "❓", }); - const fetchSubjectData = async () => { - const data = await getSubjectData(subject.average.subjectName); + const fetchSubjectData = () => { + const data = getSubjectData(subject.average.subjectName); setSubjectData(data); }; diff --git a/src/views/account/Home/Elements/GradesElement.tsx b/src/views/account/Home/Elements/GradesElement.tsx index 2c2e508c3..03850395f 100644 --- a/src/views/account/Home/Elements/GradesElement.tsx +++ b/src/views/account/Home/Elements/GradesElement.tsx @@ -10,10 +10,21 @@ import type { Grade } from "@/services/shared/Grade"; import RedirectButton from "@/components/Home/RedirectButton"; const GradesElement: React.FC = () => { - const account = useCurrentAccount((store) => store.account); + const account = useCurrentAccount((store) => store.account!); + const periods = useGradesStore(store => store.periods); const defaultPeriod = useGradesStore(store => store.defaultPeriod); const grades = useGradesStore((store) => store.grades); + const [userSelectedPeriod, setUserSelectedPeriod] = useState(null); + const selectedPeriod = useMemo(() => userSelectedPeriod ?? defaultPeriod, [userSelectedPeriod, defaultPeriod]); + + useEffect(() => { + setTimeout(() => { + if (!periods.map(period => period.name).includes(selectedPeriod)) { + setUserSelectedPeriod(defaultPeriod); + } + }, 0); + }, [account.instance, defaultPeriod]); useEffect(() => { void async function () { @@ -70,6 +81,7 @@ const GradesElement: React.FC = () => { navigation={PapillonNavigation.current} index={index} totalItems={lastThreeGrades.length} + allGrades={grades[selectedPeriod]} /> ))} From 4ceb2b24ecff58da6a3efe217d26f5a6c69da5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=95=82=F0=9D=95=AA=F0=9D=95=9D=F0=9D=95=9A?= =?UTF-8?q?=F0=9D=95=92=F0=9D=95=9F?= Date: Thu, 17 Oct 2024 23:43:38 +0200 Subject: [PATCH 2/8] indentation via Prettier + fix style --- src/utils/grades/getAverages.ts | 70 ++++--- src/views/account/Grades/Document.tsx | 180 +++++++++++------- .../account/Grades/Latest/LatestGrades.tsx | 20 +- .../Grades/Latest/LatestGradesItem.tsx | 51 +++-- .../account/Grades/Subject/GradeItem.tsx | 54 ++++-- .../account/Grades/Subject/SubjectList.tsx | 38 ++-- .../account/Home/Elements/GradesElement.tsx | 66 ++++--- 7 files changed, 311 insertions(+), 168 deletions(-) diff --git a/src/utils/grades/getAverages.ts b/src/utils/grades/getAverages.ts index 0a9da21f9..33ee58447 100644 --- a/src/utils/grades/getAverages.ts +++ b/src/utils/grades/getAverages.ts @@ -4,7 +4,7 @@ import type { Grade } from "@/services/shared/Grade"; // Définition de l'interface `GradeHistory` pour représenter l'historique des notes avec une valeur numérique et une date export interface GradeHistory { value: number; // La valeur de la note - date: string; // La date à laquelle la note a été enregistrée + date: string; // La date à laquelle la note a été enregistrée } // Définition du type `Target` qui indique quel type de moyenne ou note cibler @@ -13,41 +13,60 @@ type Target = "student" | "average" | "min" | "max"; // Définition du type `AverageDiffGrade` pour calculer la différence entre les moyennes avec et sans certaines notes export type AverageDiffGrade = { difference?: number; // La différence de moyenne entre deux ensembles de notes - with: number; // La moyenne avec toutes les notes - without: number; // La moyenne sans certaines notes + with: number; // La moyenne avec toutes les notes + without: number; // La moyenne sans certaines notes }; // Fonction pour calculer la moyenne des notes globales par matière, en fonction de la cible (par défaut, "student") -const getPronoteAverage = (grades: Grade[], target: Target = "student"): number => { +const getPronoteAverage = ( + grades: Grade[], + target: Target = "student" +): number => { // Si aucune note n'est fournie ou que la liste est vide, on retourne -1 if (!grades || grades.length === 0) return -1; // Grouper les notes par matière - const groupedBySubject = grades.reduce((acc: Record, grade) => { - (acc[grade.subjectName] ||= []).push(grade); // Ajouter la note à la liste des notes pour la matière correspondante - return acc; - }, {}); + const groupedBySubject = grades.reduce( + (acc: Record, grade) => { + (acc[grade.subjectName] ||= []).push(grade); // Ajouter la note à la liste des notes pour la matière correspondante + return acc; + }, + {} + ); // Calculer la moyenne totale de toutes les matières - const totalAverage = Object.values(groupedBySubject).reduce((acc, subjectGrades) => { - return acc + getSubjectAverage(subjectGrades, target); // Additionner les moyennes de chaque matière - }, 0); + const totalAverage = Object.values(groupedBySubject).reduce( + (acc, subjectGrades) => { + return acc + getSubjectAverage(subjectGrades, target); // Additionner les moyennes de chaque matière + }, + 0 + ); // Retourner la moyenne globale en divisant par le nombre de matières return totalAverage / Object.keys(groupedBySubject).length; }; // Fonction pour calculer la moyenne d'une matière spécifique, selon la cible choisie -export const getSubjectAverage = (subject: Grade[], target: Target = "student"): number => { +export const getSubjectAverage = ( + subject: Grade[], + target: Target = "student" +): number => { let calcGradesSum = 0; // Somme cumulée des notes pondérées - let calcOutOfSum = 0; // Somme cumulée des coefficients pondérés + let calcOutOfSum = 0; // Somme cumulée des coefficients pondérés // Parcourir chaque note de la matière for (const grade of subject) { const targetGrade = grade[target]; // Sélectionner la note selon la cible choisie // Vérifier si la note est invalide ou si le coefficient est nul, et passer à la suivante si c'est le cas - if (!targetGrade || targetGrade.disabled || targetGrade.value === null || targetGrade.value < 0 || grade.coefficient === 0) continue; + if ( + !targetGrade || + targetGrade.disabled || + targetGrade.value === null || + targetGrade.value < 0 || + grade.coefficient === 0 + ) + continue; const coefficient = grade.coefficient; // Coefficient de la note const outOfValue = grade.outOf.value!; // Valeur maximale possible pour la note @@ -82,9 +101,16 @@ export const getSubjectAverage = (subject: Grade[], target: Target = "student"): }; // Fonction pour calculer la différence de moyenne avec et sans certaines notes -const getAverageDiffGrade = (grades: Grade[], list: Grade[], target: Target = "student"): AverageDiffGrade => { +const getAverageDiffGrade = ( + grades: Grade[], + list: Grade[], + target: Target = "student" +): AverageDiffGrade => { const baseAverage = getSubjectAverage(list, target); // Calculer la moyenne de base avec toutes les notes - const baseWithoutGradeAverage = getSubjectAverage(list.filter(grade =>JSON.stringify(grades[0]) !== JSON.stringify(grade)), target); // Calculer la moyenne sans certaines notes + const baseWithoutGradeAverage = getSubjectAverage( + list.filter((grade) => JSON.stringify(grades[0]) !== JSON.stringify(grade)), + target + ); // Calculer la moyenne sans certaines notes return { difference: baseWithoutGradeAverage - baseAverage, // Calculer la différence entre les deux moyennes @@ -94,7 +120,11 @@ const getAverageDiffGrade = (grades: Grade[], list: Grade[], target: Target = "s }; // Fonction pour générer un historique des moyennes au fil du temps -const getAveragesHistory = (grades: Grade[], target: Target = "student", final?: number): GradeHistory[] => { +const getAveragesHistory = ( + grades: Grade[], + target: Target = "student", + final?: number +): GradeHistory[] => { // Générer l'historique des moyennes jusqu'à la date de chaque note const history = grades.map((grade, index) => ({ value: getPronoteAverage(grades.slice(0, index + 1), target), // Moyenne jusqu'à ce point @@ -114,8 +144,4 @@ const getAveragesHistory = (grades: Grade[], target: Target = "student", final?: }; // Exportation des fonctions pour utilisation externe -export { - getPronoteAverage, - getAverageDiffGrade, - getAveragesHistory, -}; \ No newline at end of file +export { getPronoteAverage, getAverageDiffGrade, getAveragesHistory }; diff --git a/src/views/account/Grades/Document.tsx b/src/views/account/Grades/Document.tsx index df0e5420a..a0905e65a 100644 --- a/src/views/account/Grades/Document.tsx +++ b/src/views/account/Grades/Document.tsx @@ -1,10 +1,23 @@ -import { NativeItem, NativeList, NativeListHeader, NativeText } from "@/components/Global/NativeComponents"; +import { + NativeItem, + NativeList, + NativeListHeader, + NativeText, +} from "@/components/Global/NativeComponents"; import { getSubjectData } from "@/services/shared/Subject"; import { useTheme } from "@react-navigation/native"; import React, { useEffect, useLayoutEffect, useState } from "react"; import { ScrollView, View } from "react-native"; import { GradeTitle } from "./Atoms/GradeTitle"; -import { Asterisk, Calculator, Scale, School, UserMinus, UserPlus, Users } from "lucide-react-native"; +import { + Asterisk, + Calculator, + Scale, + School, + UserMinus, + UserPlus, + Users, +} from "lucide-react-native"; import { getAverageDiffGrade } from "@/utils/grades/getAverages"; import { useSafeAreaInsets } from "react-native-safe-area-context"; import type { Grade } from "@/services/shared/Grade"; @@ -13,15 +26,14 @@ import { Screen } from "@/router/helpers/types"; import InsetsBottomView from "@/components/Global/InsetsBottomView"; const GradeDocument: Screen<"GradeDocument"> = ({ route, navigation }) => { - const { - grade, - allGrades = [] - } = route.params; + const { grade, allGrades = [] } = route.params; const theme = useTheme(); const insets = useSafeAreaInsets(); const [subjectData, setSubjectData] = useState({ - color: "#888888", pretty: "Matière inconnue", emoji: "❓", + color: "#888888", + pretty: "Matière inconnue", + emoji: "❓", }); const fetchSubjectData = () => { @@ -43,8 +55,16 @@ const GradeDocument: Screen<"GradeDocument"> = ({ route, navigation }) => { const [classDiff, setClassDiff] = useState({} as AverageDiffGrade); useEffect(() => { - const gD = getAverageDiffGrade([grade], allGrades, "student") as AverageDiffGrade; - const cD = getAverageDiffGrade([grade], allGrades, "average") as AverageDiffGrade; + const gD = getAverageDiffGrade( + [grade], + allGrades, + "student" + ) as AverageDiffGrade; + const cD = getAverageDiffGrade( + [grade], + allGrades, + "average" + ) as AverageDiffGrade; setGradeDiff(gD); setClassDiff(cD); @@ -60,15 +80,18 @@ const GradeDocument: Screen<"GradeDocument"> = ({ route, navigation }) => { description: "Coefficient de la note", value: "x" + grade.coefficient.toFixed(2), }, - grade.outOf.value !== 20 && !grade.student.disabled && { + grade.outOf.value !== 20 && + !grade.student.disabled && { icon: , title: "Remis sur /20", description: "Valeur recalculée sur 20", - value: (typeof grade.student.value === "number" && typeof grade.outOf.value === "number") - ? (grade.student.value / grade.outOf.value * 20).toFixed(2) - : "??", + value: + typeof grade.student.value === "number" && + typeof grade.outOf.value === "number" + ? ((grade.student.value / grade.outOf.value) * 20).toFixed(2) + : "??", bareme: "/20", - } + }, ], }, { @@ -94,8 +117,8 @@ const GradeDocument: Screen<"GradeDocument"> = ({ route, navigation }) => { description: "Moins bonne note de la classe", value: grade.min.value?.toFixed(2) ?? "??", bareme: "/" + grade.outOf.value, - } - ] + }, + ], }, { title: "Influence", @@ -104,21 +127,42 @@ const GradeDocument: Screen<"GradeDocument"> = ({ route, navigation }) => { icon: , title: "Moyenne générale", description: "Impact de la note sur la moyenne générale", - value: gradeDiff.difference === undefined ? "???" : - (gradeDiff.difference > 0 ? "- " : gradeDiff.difference === 0 ? "+/- " : "+ ") + - gradeDiff.difference.toFixed(2).replace("-", "") + " pts", - color: gradeDiff.difference === undefined ? void 0 : (gradeDiff.difference < 0 ? "#4CAF50" : gradeDiff.difference === 0 ? theme.colors.text : "#F44336"), + value: + gradeDiff.difference === undefined + ? "???" + : (gradeDiff.difference > 0 + ? "- " + : gradeDiff.difference === 0 + ? "+/- " + : "+ ") + + gradeDiff.difference.toFixed(2).replace("-", "") + + " pts", + color: + gradeDiff.difference === undefined + ? void 0 + : gradeDiff.difference < 0 + ? "#4CAF50" + : gradeDiff.difference === 0 + ? theme.colors.text + : "#F44336", }, !grade.average.disabled && { icon: , title: "Moyenne de la classe", description: "Impact de la note sur la moyenne de la classe", - value: classDiff.difference === undefined ? "???" : - (classDiff.difference > 0 ? "- " : gradeDiff.difference === 0 ? "+/- " : "+ ") + - classDiff.difference.toFixed(2).replace("-", "") + " pts", - } - ] - } + value: + classDiff.difference === undefined + ? "???" + : (classDiff.difference > 0 + ? "- " + : gradeDiff.difference === 0 + ? "+/- " + : "+ ") + + classDiff.difference.toFixed(2).replace("-", "") + + " pts", + }, + ], + }, ]; return ( @@ -137,49 +181,51 @@ const GradeDocument: Screen<"GradeDocument"> = ({ route, navigation }) => { - {list.items.map((item, index) => item && ( - + item && ( + + + {item.value} + + + {"bareme" in item && ( + + {item.bareme} + + )} + + } > - - {item.value} - - - {"bareme" in item && + {item.title} + + {item.description && ( - {item.bareme} + {item.description} - } - - } - > - - {item.title} - - - {item.description && - - {item.description} - - } - - ))} + )} + + ) + )} ))} @@ -189,4 +235,4 @@ const GradeDocument: Screen<"GradeDocument"> = ({ route, navigation }) => { ); }; -export default GradeDocument; \ No newline at end of file +export default GradeDocument; diff --git a/src/views/account/Grades/Latest/LatestGrades.tsx b/src/views/account/Grades/Latest/LatestGrades.tsx index b5c51b069..4f596ff79 100644 --- a/src/views/account/Grades/Latest/LatestGrades.tsx +++ b/src/views/account/Grades/Latest/LatestGrades.tsx @@ -1,10 +1,6 @@ - - import { NativeListHeader } from "@/components/Global/NativeComponents"; import { animPapillon } from "@/utils/ui/animations"; -import Reanimated, { - LinearTransition -} from "react-native-reanimated"; +import Reanimated, { LinearTransition } from "react-native-reanimated"; import GradesLatestItem from "./LatestGradesItem"; import { Grade } from "@/services/shared/Grade"; @@ -15,9 +11,7 @@ const GradesLatestList = (props: GradesLatestListProps) => { { }} > {latestGrades.map((grade: Grade, index: number) => ( - + ))} ); }; -export default GradesLatestList; \ No newline at end of file +export default GradesLatestList; diff --git a/src/views/account/Grades/Latest/LatestGradesItem.tsx b/src/views/account/Grades/Latest/LatestGradesItem.tsx index 787ec8c7d..1783a2868 100644 --- a/src/views/account/Grades/Latest/LatestGradesItem.tsx +++ b/src/views/account/Grades/Latest/LatestGradesItem.tsx @@ -14,9 +14,17 @@ type GradeLatestItemProps = { allGrades: Grade[]; }; -const GradesLatestItem: React.FC = ({ grade, i, navigation, allGrades }) => { +const GradesLatestItem: React.FC = ({ + grade, + i, + navigation, + allGrades, +}) => { const [subjectData, setSubjectData] = useState({ - color: "#888888", pretty: "Matière inconnue", emoji: "❓", }); + color: "#888888", + pretty: "Matière inconnue", + emoji: "❓", + }); const fetchSubjectData = () => { const data = getSubjectData(grade.subjectName); @@ -34,7 +42,7 @@ const GradesLatestItem: React.FC = ({ grade, i, navigation = ({ grade, i, navigation {subjectData.pretty} - + {new Date(grade.timestamp).toLocaleDateString("fr-FR", { month: "short", day: "numeric", @@ -90,16 +95,23 @@ const GradesLatestItem: React.FC = ({ grade, i, navigation - {grade.description || `Note renseignée le ${new Date(grade.timestamp).toLocaleDateString("fr-FR", { - weekday: "long", - month: "long", - day: "numeric", - year: "numeric", - })}`} + {grade.description || + `Note renseignée le ${new Date( + grade.timestamp + ).toLocaleDateString("fr-FR", { + weekday: "long", + month: "long", + day: "numeric", + year: "numeric", + })}`} @@ -124,7 +136,9 @@ const GradesLatestItem: React.FC = ({ grade, i, navigation fontFamily: "semibold", }} > - {!grade.student.disabled ? parseFloat(grade.student.value).toFixed(2) : "N.not"} + {!grade.student.disabled + ? parseFloat(grade.student.value).toFixed(2) + : "N.not"} = ({ grade, i, navigation - ); }; -export default GradesLatestItem; \ No newline at end of file +export default GradesLatestItem; diff --git a/src/views/account/Grades/Subject/GradeItem.tsx b/src/views/account/Grades/Subject/GradeItem.tsx index cd7b2da4c..50c5a994d 100644 --- a/src/views/account/Grades/Subject/GradeItem.tsx +++ b/src/views/account/Grades/Subject/GradeItem.tsx @@ -7,16 +7,26 @@ import type { NativeStackNavigationProp } from "@react-navigation/native-stack"; import type { RouteParameters } from "@/router/helpers/types"; interface GradeItemProps { - subject: { average: { subjectName: string }, grades: any[] }; + subject: { average: { subjectName: string }; grades: any[] }; grade: Grade; - navigation: NativeStackNavigationProp + navigation: NativeStackNavigationProp; index: number; totalItems: number; allGrades: Grade[]; } -const GradeItem: React.FC = ({ subject, grade, navigation, index, totalItems, allGrades }) => { - const subjectData = useMemo(() => getSubjectData(subject.average.subjectName), [subject.average.subjectName]); +const GradeItem: React.FC = ({ + subject, + grade, + navigation, + index, + totalItems, + allGrades, +}) => { + const subjectData = useMemo( + () => getSubjectData(subject.average.subjectName), + [subject.average.subjectName] + ); const formattedDate = new Date(grade.timestamp).toLocaleDateString("fr-FR", { weekday: "long", @@ -25,9 +35,10 @@ const GradeItem: React.FC = ({ subject, grade, navigation, index year: "numeric", }); - const gradeValue = typeof grade.student.value === "number" - ? grade.student.value.toFixed(2) - : "N. not"; + const gradeValue = + typeof grade.student.value === "number" + ? grade.student.value.toFixed(2) + : "N. not"; return ( = ({ subject, grade, navigation, index chevron={false} animated leading={ - - + + {subjectData.emoji} @@ -53,9 +83,7 @@ const GradeItem: React.FC = ({ subject, grade, navigation, index - - {gradeValue} - + {gradeValue} /{grade.outOf.value?.toFixed(0) ?? "??"} @@ -91,4 +119,4 @@ const styles = StyleSheet.create({ }, }); -export default GradeItem; \ No newline at end of file +export default GradeItem; diff --git a/src/views/account/Grades/Subject/SubjectList.tsx b/src/views/account/Grades/Subject/SubjectList.tsx index 2601765cb..297b26525 100644 --- a/src/views/account/Grades/Subject/SubjectList.tsx +++ b/src/views/account/Grades/Subject/SubjectList.tsx @@ -1,27 +1,37 @@ -import { NativeItem, NativeList, NativeText } from "@/components/Global/NativeComponents"; +import { + NativeItem, + NativeList, + NativeText, +} from "@/components/Global/NativeComponents"; import { getSubjectData } from "@/services/shared/Subject"; import { animPapillon } from "@/utils/ui/animations"; import React, { useEffect, useState } from "react"; import { View } from "react-native"; -import Reanimated, { FadeInDown, FadeInUp, FadeOutUp } from "react-native-reanimated"; +import Reanimated, { + FadeInDown, + FadeInUp, + FadeOutUp, +} from "react-native-reanimated"; import SubjectTitle from "./SubjectTitle"; import { type Grade, type GradesPerSubject } from "@/services/shared/Grade"; import type { NativeStackNavigationProp } from "@react-navigation/native-stack"; import type { RouteParameters } from "@/router/helpers/types"; interface SubjectItemProps { - subject: GradesPerSubject - allGrades: Grade[] - navigation: NativeStackNavigationProp + subject: GradesPerSubject; + allGrades: Grade[]; + navigation: NativeStackNavigationProp; } const SubjectItem: React.FC = ({ subject, allGrades, - navigation + navigation, }) => { const [subjectData, setSubjectData] = useState({ - color: "#888888", pretty: "Matière inconnue", emoji: "❓", + color: "#888888", + pretty: "Matière inconnue", + emoji: "❓", }); const fetchSubjectData = () => { @@ -39,7 +49,12 @@ const SubjectItem: React.FC = ({ entering={animPapillon(FadeInUp)} exiting={animPapillon(FadeOutUp)} > - + {subject.grades.map((grade: Grade, index: number) => ( = ({ navigation.navigate("GradeDocument", { grade, allGrades })} + onPress={() => + navigation.navigate("GradeDocument", { grade, allGrades }) + } > = ({ > {typeof grade.student.value === "number" ? grade.student.value.toFixed(2) - : "N. not" - } + : "N. not"} { const account = useCurrentAccount((store) => store.account!); - const periods = useGradesStore(store => store.periods); + const periods = useGradesStore((store) => store.periods); - const defaultPeriod = useGradesStore(store => store.defaultPeriod); + const defaultPeriod = useGradesStore((store) => store.defaultPeriod); const grades = useGradesStore((store) => store.grades); - const [userSelectedPeriod, setUserSelectedPeriod] = useState(null); - const selectedPeriod = useMemo(() => userSelectedPeriod ?? defaultPeriod, [userSelectedPeriod, defaultPeriod]); + const [userSelectedPeriod, setUserSelectedPeriod] = useState( + null + ); + const selectedPeriod = useMemo( + () => userSelectedPeriod ?? defaultPeriod, + [userSelectedPeriod, defaultPeriod] + ); useEffect(() => { setTimeout(() => { - if (!periods.map(period => period.name).includes(selectedPeriod)) { + if (!periods.map((period) => period.name).includes(selectedPeriod)) { setUserSelectedPeriod(defaultPeriod); } }, 0); }, [account.instance, defaultPeriod]); useEffect(() => { - void async function () { + void (async function () { if (!account?.instance) return; await updateGradesPeriodsInCache(account); - }(); + })(); }, [account?.instance]); useEffect(() => { - void async function () { + void (async function () { if (!account?.instance || !defaultPeriod) return; await updateGradesAndAveragesInCache(account, defaultPeriod); - }(); + })(); }, [defaultPeriod]); - const [lastThreeGrades, setLastThreeGrades] = useState>([]); + const [lastThreeGrades, setLastThreeGrades] = useState< + Array<{ + subject: { average: { subjectName: string }; grades: any[] }; + grade: Grade; + }> + >([]); useEffect(() => { if (grades && grades[defaultPeriod]) { @@ -52,7 +64,7 @@ const GradesElement: React.FC = () => { .slice(0, 3) .map((grade) => ({ subject: { average: { subjectName: grade.subjectName }, grades: [] }, - grade + grade, })); setLastThreeGrades(lastThree); @@ -65,14 +77,16 @@ const GradesElement: React.FC = () => { return ( <> - - )} + + } /> - + {lastThreeGrades.map((item, index) => ( { ); }; -export default GradesElement; \ No newline at end of file +export default GradesElement; From 5edd03b6b8c531c667cf5c8ecc19897222fe36c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=95=82=F0=9D=95=AA=F0=9D=95=9D=F0=9D=95=9A?= =?UTF-8?q?=F0=9D=95=92=F0=9D=95=9F?= Date: Thu, 17 Oct 2024 23:49:00 +0200 Subject: [PATCH 3/8] =?UTF-8?q?diverses=20corrections=20+=20indentation=20?= =?UTF-8?q?Prettier=20+=20importations=20inutili=C3=A9es=20supprim=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/account/Grades/Grades.tsx | 217 ++++++++++++++++++---------- 1 file changed, 138 insertions(+), 79 deletions(-) diff --git a/src/views/account/Grades/Grades.tsx b/src/views/account/Grades/Grades.tsx index 8f4b1ba8f..aa8e14df1 100644 --- a/src/views/account/Grades/Grades.tsx +++ b/src/views/account/Grades/Grades.tsx @@ -1,11 +1,14 @@ -import AnimatedNumber from "@/components/Global/AnimatedNumber"; import MissingItem from "@/components/Global/MissingItem"; -import { NativeText } from "@/components/Global/NativeComponents"; -import PapillonHeader from "@/components/Global/PapillonHeader"; -import { PapillonHeaderSelector, PapillonModernHeader } from "@/components/Global/PapillonModernHeader"; +import { + PapillonHeaderSelector, + PapillonModernHeader, +} from "@/components/Global/PapillonModernHeader"; import PapillonPicker from "@/components/Global/PapillonPicker"; import type { Screen } from "@/router/helpers/types"; -import { updateGradesAndAveragesInCache, updateGradesPeriodsInCache } from "@/services/grades"; +import { + updateGradesAndAveragesInCache, + updateGradesPeriodsInCache, +} from "@/services/grades"; import type { GradesPerSubject } from "@/services/shared/Grade"; import { useCurrentAccount } from "@/stores/account"; import { useGradesStore } from "@/stores/grades"; @@ -14,8 +17,19 @@ import { useTheme } from "@react-navigation/native"; import { ChevronDown } from "lucide-react-native"; import React from "react"; import { lazy, Suspense, useEffect, useMemo, useRef, useState } from "react"; -import { ActivityIndicator, Platform, RefreshControl, ScrollView, View } from "react-native"; -import Reanimated, { FadeIn, FadeInUp, FadeOut, FadeOutDown, LinearTransition } from "react-native-reanimated"; +import { + ActivityIndicator, + Platform, + RefreshControl, + ScrollView, + View, +} from "react-native"; +import Reanimated, { + FadeInUp, + FadeOut, + FadeOutDown, + LinearTransition, +} from "react-native-reanimated"; import { useSafeAreaInsets } from "react-native-safe-area-context"; const GradesAverageGraph = lazy(() => import("./Graph/GradesAverage")); @@ -28,16 +42,23 @@ const Grades: Screen<"Grades"> = ({ route, navigation }) => { const outsideNav = route.params?.outsideNav; - const account = useCurrentAccount(store => store.account!); - const defaultPeriod = useGradesStore(store => store.defaultPeriod); - const periods = useGradesStore(store => store.periods); - const averages = useGradesStore(store => store.averages); - const grades = useGradesStore(store => store.grades); + const account = useCurrentAccount((store) => store.account!); + const defaultPeriod = useGradesStore((store) => store.defaultPeriod); + const periods = useGradesStore((store) => store.periods); + const averages = useGradesStore((store) => store.averages); + const grades = useGradesStore((store) => store.grades); - const [userSelectedPeriod, setUserSelectedPeriod] = useState(null); - const selectedPeriod = useMemo(() => userSelectedPeriod ?? defaultPeriod, [userSelectedPeriod, defaultPeriod]); + const [userSelectedPeriod, setUserSelectedPeriod] = useState( + null + ); + const selectedPeriod = useMemo( + () => userSelectedPeriod ?? defaultPeriod, + [userSelectedPeriod, defaultPeriod] + ); - const [gradesPerSubject, setGradesPerSubject] = useState([]); + const [gradesPerSubject, setGradesPerSubject] = useState( + [] + ); const latestGradesRef = useRef([]); const [isRefreshing, setIsRefreshing] = useState(false); @@ -45,7 +66,7 @@ const Grades: Screen<"Grades"> = ({ route, navigation }) => { useEffect(() => { setTimeout(() => { - if (!periods.map(period => period.name).includes(selectedPeriod)) { + if (!periods.map((period) => period.name).includes(selectedPeriod)) { setUserSelectedPeriod(defaultPeriod); } }, 0); @@ -63,10 +84,10 @@ const Grades: Screen<"Grades"> = ({ route, navigation }) => { if (selectedPeriod === "") return; if (!account.instance) return; - void (() => { + void (async () => { setIsLoading(true); - setTimeout(async () => { - await updateData(); + await updateData(); + setTimeout(() => { setIsRefreshing(false); setIsLoading(false); }, 100); @@ -79,8 +100,11 @@ const Grades: Screen<"Grades"> = ({ route, navigation }) => { const gradesPerSubject: GradesPerSubject[] = []; - for (const average of (averages[selectedPeriod] || { subjects: [] }).subjects) { - const newGrades = (grades[selectedPeriod] || []).filter(grade => grade.subjectName === average.subjectName).sort((a, b) => b.timestamp - a.timestamp); + for (const average of (averages[selectedPeriod] || { subjects: [] }) + .subjects) { + const newGrades = (grades[selectedPeriod] || []) + .filter((grade) => grade.subjectName === average.subjectName) + .sort((a, b) => b.timestamp - a.timestamp); gradesPerSubject.push({ average: average, @@ -88,7 +112,9 @@ const Grades: Screen<"Grades"> = ({ route, navigation }) => { }); } - gradesPerSubject.sort((a, b) => a.average.subjectName.localeCompare(b.average.subjectName)); + gradesPerSubject.sort((a, b) => + a.average.subjectName.localeCompare(b.average.subjectName) + ); setGradesPerSubject(gradesPerSubject); }, 1); }, [selectedPeriod, averages, grades]); @@ -97,7 +123,10 @@ const Grades: Screen<"Grades"> = ({ route, navigation }) => { setTimeout(() => { if (selectedPeriod === "") return; - const latestGrades = (grades[selectedPeriod] || []).slice().sort((a, b) => b.timestamp - a.timestamp).slice(0, 10); + const latestGrades = (grades[selectedPeriod] || []) + .slice() + .sort((a, b) => b.timestamp - a.timestamp) + .slice(0, 10); latestGradesRef.current = latestGrades; }, 1); @@ -106,19 +135,23 @@ const Grades: Screen<"Grades"> = ({ route, navigation }) => { return ( <> - period.name)} + data={periods.map((period) => period.name)} selected={userSelectedPeriod ?? selectedPeriod} onSelectionChange={setUserSelectedPeriod} > - - + + = ({ route, navigation }) => { {userSelectedPeriod ?? selectedPeriod} - + - - setIsRefreshing(true)} - colors={Platform.OS === "android" ? [theme.colors.primary] : void 0} - progressViewOffset={outsideNav ? 72 : insets.top + 56} - /> - } - contentContainerStyle={{ - paddingTop: outsideNav ? 64 : insets.top + 42, - }} - scrollIndicatorInsets={{ top: outsideNav ? 64 : insets.top + 16 }} - > - }> - - {(!grades[selectedPeriod] || grades[selectedPeriod].length === 0) && !isLoading && !isRefreshing && ( - - )} + {!isLoading && ( + setIsRefreshing(true)} + colors={Platform.OS === "android" ? [theme.colors.primary] : void 0} + progressViewOffset={outsideNav ? 72 : insets.top + 56} + /> + } + contentContainerStyle={{ + paddingTop: outsideNav ? 64 : insets.top + 42, + }} + scrollIndicatorInsets={{ top: outsideNav ? 64 : insets.top + 16 }} + > + }> + + {(!grades[selectedPeriod] || grades[selectedPeriod].length === 0) && + !isLoading && + !isRefreshing && ( + + )} + + {!isLoading && + grades[selectedPeriod] && + grades[selectedPeriod].length > 1 && ( + + + + )} + + {latestGradesRef.current.length > 2 && ( + + )} - {grades[selectedPeriod] && grades[selectedPeriod].length > 1 && ( - - 0 && ( + - - )} - - {latestGradesRef.current.length > 2 && ( - - )} - - {gradesPerSubject.length > 0 && ( - - )} - - - + )} + + + + )} ); }; From e2dc05239b03201621e10caf309e60e6200cf541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=95=82=F0=9D=95=AA=F0=9D=95=9D=F0=9D=95=9A?= =?UTF-8?q?=F0=9D=95=92=F0=9D=95=9F?= Date: Thu, 17 Oct 2024 23:58:02 +0200 Subject: [PATCH 4/8] fix -1 en pire note --- src/views/account/Grades/Document.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/views/account/Grades/Document.tsx b/src/views/account/Grades/Document.tsx index a0905e65a..34aa6c45e 100644 --- a/src/views/account/Grades/Document.tsx +++ b/src/views/account/Grades/Document.tsx @@ -19,8 +19,6 @@ import { Users, } from "lucide-react-native"; import { getAverageDiffGrade } from "@/utils/grades/getAverages"; -import { useSafeAreaInsets } from "react-native-safe-area-context"; -import type { Grade } from "@/services/shared/Grade"; import type { AverageDiffGrade } from "@/utils/grades/getAverages"; import { Screen } from "@/router/helpers/types"; import InsetsBottomView from "@/components/Global/InsetsBottomView"; @@ -28,7 +26,6 @@ import InsetsBottomView from "@/components/Global/InsetsBottomView"; const GradeDocument: Screen<"GradeDocument"> = ({ route, navigation }) => { const { grade, allGrades = [] } = route.params; const theme = useTheme(); - const insets = useSafeAreaInsets(); const [subjectData, setSubjectData] = useState({ color: "#888888", @@ -115,7 +112,11 @@ const GradeDocument: Screen<"GradeDocument"> = ({ route, navigation }) => { icon: , title: "Note minimale", description: "Moins bonne note de la classe", - value: grade.min.value?.toFixed(2) ?? "??", + value: + grade.min.value?.toFixed(2) && + grade.min.value.toFixed(2) !== "-1.00" + ? grade.min.value?.toFixed(2) + : "??", bareme: "/" + grade.outOf.value, }, ], From 758634988992ebe489fac98b3b6501de270756af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=95=82=F0=9D=95=AA=F0=9D=95=9D=F0=9D=95=9A?= =?UTF-8?q?=F0=9D=95=92=F0=9D=95=9F?= Date: Fri, 18 Oct 2024 00:00:24 +0200 Subject: [PATCH 5/8] =?UTF-8?q?fix=20vibration=20pr=C3=A9sente=203=20fois?= =?UTF-8?q?=20au=20lieu=20d'une?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../account/Grades/Graph/GradesAverage.tsx | 145 ++++++++++-------- 1 file changed, 82 insertions(+), 63 deletions(-) diff --git a/src/views/account/Grades/Graph/GradesAverage.tsx b/src/views/account/Grades/Graph/GradesAverage.tsx index ec7c9a4da..181d7dc90 100644 --- a/src/views/account/Grades/Graph/GradesAverage.tsx +++ b/src/views/account/Grades/Graph/GradesAverage.tsx @@ -1,5 +1,13 @@ -import { NativeItem, NativeList, NativeText } from "@/components/Global/NativeComponents"; -import { getAveragesHistory, getPronoteAverage, GradeHistory } from "@/utils/grades/getAverages"; +import { + NativeItem, + NativeList, + NativeText, +} from "@/components/Global/NativeComponents"; +import { + getAveragesHistory, + getPronoteAverage, + GradeHistory, +} from "@/utils/grades/getAverages"; import { useTheme } from "@react-navigation/native"; import React, { useRef, useCallback, useEffect, useState } from "react"; import { View, StyleSheet, Platform } from "react-native"; @@ -16,19 +24,24 @@ import { animPapillon } from "@/utils/ui/animations"; import * as Haptics from "expo-haptics"; import { PressableScale } from "react-native-pressable-scale"; -import ReanimatedGraph, { ReanimatedGraphPublicMethods } from "@birdwingo/react-native-reanimated-graph"; +import ReanimatedGraph, { + ReanimatedGraphPublicMethods, +} from "@birdwingo/react-native-reanimated-graph"; import { useCurrentAccount } from "@/stores/account"; import AnimatedNumber from "@/components/Global/AnimatedNumber"; import type { Grade } from "@/services/shared/Grade"; interface GradesAverageGraphProps { - grades: Grade[] - overall: number | null + grades: Grade[]; + overall: number | null; } -const GradesAverageGraph: React.FC = ({ grades, overall }) => { +const GradesAverageGraph: React.FC = ({ + grades, + overall, +}) => { const theme = useTheme(); - const account = useCurrentAccount(store => store.account!); + const account = useCurrentAccount((store) => store.account!); const [gradesHistory, setGradesHistory] = useState([]); const [hLength, setHLength] = useState(0); @@ -48,12 +61,7 @@ const GradesAverageGraph: React.FC = ({ grades, overall useEffect(() => { if (currentAvg !== originalCurrentAvg) { - // repeat 3 times - for (let i = 0; i < 3; i++) { - setTimeout(() => { - Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); - }, 100 + (i * 80)); - } + Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light); } }, [currentAvg]); @@ -62,7 +70,6 @@ const GradesAverageGraph: React.FC = ({ grades, overall setSelectedDate(null); }, [grades]); - useEffect(() => { let hst = getAveragesHistory(grades, "student", overall ?? void 0); if (hst.length === 0) return; @@ -88,18 +95,21 @@ const GradesAverageGraph: React.FC = ({ grades, overall setMinAvg(minAvg); graphRef.current?.updateData({ - xAxis: hst.map((p, i) => (new Date(p.date).getTime())), - yAxis: hst.map((p) => (p.value)), + xAxis: hst.map((p, i) => new Date(p.date).getTime()), + yAxis: hst.map((p) => p.value), }); }, [grades, account.instance]); - const updateTo = useCallback((index: number) => { - if (index < 0 || index > gradesHistoryRef.current.length - 1) return; - if (!gradesHistoryRef.current[index]?.value) return; + const updateTo = useCallback( + (index: number) => { + if (index < 0 || index > gradesHistoryRef.current.length - 1) return; + if (!gradesHistoryRef.current[index]?.value) return; - setSelectedDate(gradesHistoryRef.current[index].date); - setCurrentAvg(gradesHistoryRef.current[index].value); - }, [gradesHistoryRef]); + setSelectedDate(gradesHistoryRef.current[index].date); + setCurrentAvg(gradesHistoryRef.current[index].value); + }, + [gradesHistoryRef] + ); const resetToOriginal = useCallback(() => { setSelectedDate(null); @@ -133,8 +143,10 @@ const GradesAverageGraph: React.FC = ({ grades, overall }} > (new Date(p.date).getTime()))} - yAxis={gradesHistory.map((p) => (p.value))} + xAxis={gradesHistory.map((p, i) => + new Date(p.date).getTime() + )} + yAxis={gradesHistory.map((p) => p.value)} color={theme.colors.primary} showXAxisLegend={false} showYAxisLegend={false} @@ -155,16 +167,17 @@ const GradesAverageGraph: React.FC = ({ grades, overall resetToOriginal(); }} /> - - ) : } + ) : ( + + )} @@ -175,8 +188,16 @@ const GradesAverageGraph: React.FC = ({ grades, overall entering={animPapillon(FadeInDown)} exiting={animPapillon(FadeOutUp)} > - - au {new Date(selectedDate).toLocaleDateString("fr-FR", { day: "numeric", month: "short", year: "numeric" })} + + au{" "} + {new Date(selectedDate).toLocaleDateString("fr-FR", { + day: "numeric", + month: "short", + year: "numeric", + })} ) : ( @@ -185,9 +206,7 @@ const GradesAverageGraph: React.FC = ({ grades, overall entering={animPapillon(FadeInDown)} exiting={animPapillon(FadeOutUp)} > - - Moyenne gén. - + Moyenne gén. )} @@ -195,21 +214,19 @@ const GradesAverageGraph: React.FC = ({ grades, overall style={[styles.gradeValue]} layout={animPapillon(LinearTransition)} > - + - - - /20 - + + /20 - - Moyenne classe - + Moyenne classe = ({ grades, overall style={styles.gradeNumberClass} /> - - /20 - + /20 @@ -243,41 +258,45 @@ const GradesAverageGraph: React.FC = ({ grades, overall > + {maxAvg.toFixed(2)} - - /20 - + /20 } separator > - - Moyenne max. - - + Moyenne max. + {minAvg.toFixed(2)} - - /20 - + /20 } > - - Moyenne min. - - + Moyenne min. - ) : } + ) : ( + + )} )} @@ -324,4 +343,4 @@ const styles = StyleSheet.create({ }, }); -export default GradesAverageGraph; \ No newline at end of file +export default GradesAverageGraph; From 8456c51bdb54a81a1c6f4c68947a182127a218dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=95=82=F0=9D=95=AA=F0=9D=95=9D=F0=9D=95=9A?= =?UTF-8?q?=F0=9D=95=92=F0=9D=95=9F?= Date: Fri, 18 Oct 2024 13:21:28 +0200 Subject: [PATCH 6/8] =?UTF-8?q?-1=20remplac=C3=A9=20par=20"=3F=3F"=20pour?= =?UTF-8?q?=20la=20pire=20moyennne?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/account/Grades/Modals/Subject.tsx | 52 ++++++++++++++------- 1 file changed, 34 insertions(+), 18 deletions(-) diff --git a/src/views/account/Grades/Modals/Subject.tsx b/src/views/account/Grades/Modals/Subject.tsx index 01a309566..9a9b0d82e 100644 --- a/src/views/account/Grades/Modals/Subject.tsx +++ b/src/views/account/Grades/Modals/Subject.tsx @@ -1,17 +1,25 @@ -import { NativeItem, NativeList, NativeListHeader, NativeText } from "@/components/Global/NativeComponents"; +import { + NativeItem, + NativeList, + NativeListHeader, + NativeText, +} from "@/components/Global/NativeComponents"; import { getSubjectData } from "@/services/shared/Subject"; -import { icones } from "@/utils/data/icones"; import { getCourseSpeciality } from "@/utils/format/format_cours_name"; import { getAverageDiffGrade } from "@/utils/grades/getAverages"; +import { useTheme } from "@react-navigation/native"; import { User, UserMinus, UserPlus, Users } from "lucide-react-native"; import React, { useEffect, useLayoutEffect, useState } from "react"; -import { View, Text, StyleSheet, ScrollView } from "react-native"; +import { View, ScrollView } from "react-native"; -const GradeSubjectScreen = ({ route, navigation }) => { +const GradeSubjectScreen = ({ route }) => { const { subject, allGrades } = route.params; + const theme = useTheme(); const [subjectData, setSubjectData] = useState({ - color: "#888888", pretty: "Matière inconnue", emoji: "❓", + color: "#888888", + pretty: "Matière inconnue", + emoji: "❓", }); const fetchSubjectData = async () => { @@ -42,7 +50,11 @@ const GradeSubjectScreen = ({ route, navigation }) => { { icon: , label: "Moy. la plus basse", - value: parseFloat(subject.average.min.value || -1).toFixed(2), + value: + subject.average.min.value.toFixed(2) && + subject.average.min.value.toFixed(2) !== "-1.00" + ? subject.average.min.value?.toFixed(2) + : "??", }, ]; @@ -102,9 +114,7 @@ const GradeSubjectScreen = ({ route, navigation }) => { flex: 1, }} > - - {subjectData.pretty} - + {subjectData.pretty} {getCourseSpeciality(subject.average.subjectName) && ( @@ -157,9 +167,7 @@ const GradeSubjectScreen = ({ route, navigation }) => { } > - - {average.label} - + {average.label} ); })} @@ -175,18 +183,26 @@ const GradeSubjectScreen = ({ route, navigation }) => { fontSize: 16, lineHeight: 18, fontFamily: "semibold", - color: averageDiff.difference < 0 ? "#4CAF50" : "#F44336", + color: + averageDiff.difference < 0 + ? "#4CAF50" + : averageDiff.difference === 0 + ? theme.colors.text + : "#F44336", marginLeft: 12, marginRight: 6, }} > - {averageDiff.difference > 0 ? "- " : "+ "}{averageDiff.difference.toFixed(2).replace("-", "")} pts + {averageDiff.difference > 0 + ? "- " + : averageDiff.difference === 0 + ? "+/- " + : "+ "} + {averageDiff.difference.toFixed(2).replace("-", "")} pts } > - - Impact sur la moyenne - + Impact sur la moyenne Indique le poids de {subjectData.pretty} sur votre moyenne générale @@ -196,4 +212,4 @@ const GradeSubjectScreen = ({ route, navigation }) => { ); }; -export default GradeSubjectScreen; \ No newline at end of file +export default GradeSubjectScreen; From 9fa9b1a379be3664afad34ee104ffe3349864e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=95=82=F0=9D=95=AA=F0=9D=95=9D=F0=9D=95=9A?= =?UTF-8?q?=F0=9D=95=92=F0=9D=95=9F?= Date: Fri, 18 Oct 2024 13:30:41 +0200 Subject: [PATCH 7/8] =?UTF-8?q?fix=20affichage=20non=20correct=20de=20la?= =?UTF-8?q?=20moyenne=20g=C3=A9narale=20sur=20le=20widget?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/widgets/Components/GeneralAverage.tsx | 243 +++++++++++----------- 1 file changed, 125 insertions(+), 118 deletions(-) diff --git a/src/widgets/Components/GeneralAverage.tsx b/src/widgets/Components/GeneralAverage.tsx index be0a1e7b1..6ccdbaa5b 100644 --- a/src/widgets/Components/GeneralAverage.tsx +++ b/src/widgets/Components/GeneralAverage.tsx @@ -1,146 +1,153 @@ import { useTheme } from "@react-navigation/native"; import { PieChart } from "lucide-react-native"; -import React, { forwardRef, useEffect, useImperativeHandle, useMemo } from "react"; +import React, { + forwardRef, + useEffect, + useImperativeHandle, + useMemo, +} from "react"; import { Text, View } from "react-native"; -import Reanimated, { - LinearTransition -} from "react-native-reanimated"; +import Reanimated, { LinearTransition } from "react-native-reanimated"; import AnimatedNumber from "@/components/Global/AnimatedNumber"; import { WidgetProps } from "@/components/Home/Widget"; -import { updateGradesAndAveragesInCache, updateGradesPeriodsInCache } from "@/services/grades"; +import { + updateGradesAndAveragesInCache, + updateGradesPeriodsInCache, +} from "@/services/grades"; import { useCurrentAccount } from "@/stores/account"; import { useGradesStore } from "@/stores/grades"; import { getPronoteAverage } from "@/utils/grades/getAverages"; -const GeneralAverageWidget = forwardRef(({ - setLoading, - setHidden, - loading, -}: WidgetProps, ref) => { - const theme = useTheme(); - const { colors } = theme; - - const account = useCurrentAccount((store) => store.account); - - const grades = useGradesStore((store) => store.grades); - const averages = useGradesStore((store) => store.averages); - const defaultPeriod = useGradesStore((store) => store.defaultPeriod); - - useImperativeHandle(ref, () => ({ - handlePress: () => "Grades" - })); - - const average = useMemo(() => { - return !averages[defaultPeriod]?.overall.disabled - ? averages[defaultPeriod]?.overall.value - : getPronoteAverage(grades[defaultPeriod]); - }, [averages, grades, defaultPeriod]); - - useEffect(() => { - void async function () { - if (!account?.instance) return; - setLoading(true); - - await updateGradesPeriodsInCache(account); - setLoading(false); - }(); - }, [account?.instance]); - - useEffect(() => { - void async function () { - if (!account?.instance || !defaultPeriod) return; - setLoading(true); - - await updateGradesAndAveragesInCache(account, defaultPeriod); - setLoading(false); - }(); - }, [defaultPeriod]); - - useEffect(() => { - setHidden(typeof average !== "number" || average < 0 || average + "" === "NaN"); - }, [average]); - - if (isNaN(average ?? 0)) { - setHidden(true); - } - - return ( - <> - - - { + const theme = useTheme(); + const { colors } = theme; + + const account = useCurrentAccount((store) => store.account); + + const grades = useGradesStore((store) => store.grades); + const averages = useGradesStore((store) => store.averages); + const defaultPeriod = useGradesStore((store) => store.defaultPeriod); + + useImperativeHandle(ref, () => ({ + handlePress: () => "Grades", + })); + + const average = useMemo(() => { + return !averages[defaultPeriod]?.overall.disabled + ? averages[defaultPeriod]?.overall.value + : getPronoteAverage(grades[defaultPeriod]); + }, [averages, grades, defaultPeriod]); + + useEffect(() => { + void (async function () { + if (!account?.instance) return; + setLoading(true); + + await updateGradesPeriodsInCache(account); + setLoading(false); + })(); + }, [account?.instance]); + + useEffect(() => { + void (async function () { + if (!account?.instance || !defaultPeriod) return; + setLoading(true); + + await updateGradesAndAveragesInCache(account, defaultPeriod); + setLoading(false); + })(); + }, [defaultPeriod]); + + useEffect(() => { + setHidden( + typeof average !== "number" || average < 0 || average + "" === "NaN" + ); + }, [average]); + + if (isNaN(average ?? 0)) { + setHidden(true); + } + + return ( + <> + - Notes - - - - - - Moyenne générale - + + + Notes + + - - - /20 - + Moyenne générale + + + + + + /20 + + - - - ); -}); + + ); + } +); export default GeneralAverageWidget; From d505b4401de6c81868cc075b804edc2d98b70bce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9D=95=82=F0=9D=95=AA=F0=9D=95=9D=F0=9D=95=9A?= =?UTF-8?q?=F0=9D=95=92=F0=9D=95=9F?= Date: Sat, 26 Oct 2024 22:13:11 +0200 Subject: [PATCH 8/8] correction lint --- src/views/account/Grades/Modals/Subject.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/views/account/Grades/Modals/Subject.tsx b/src/views/account/Grades/Modals/Subject.tsx index 74e3e2989..cad74491b 100644 --- a/src/views/account/Grades/Modals/Subject.tsx +++ b/src/views/account/Grades/Modals/Subject.tsx @@ -53,8 +53,8 @@ const GradeSubjectScreen: Screen<"GradeSubject"> = ({ route, navigation }) => { icon: , label: "Moy. la plus basse", value: parseFloat((subject.average?.min?.value || -1).toString()).toFixed(2) !== "-1.00" - ? parseFloat((subject.average?.min?.value || -1).toString()).toFixed(2) - : "??", + ? parseFloat((subject.average?.min?.value || -1).toString()).toFixed(2) + : "??", }, ];