From 43c8c99b26f5ce59e08c9a46418f5c6ee7f68aa1 Mon Sep 17 00:00:00 2001 From: Fefedu973 <80718477+Fefedu973@users.noreply.github.com> Date: Mon, 11 Nov 2024 12:46:10 +0100 Subject: [PATCH] lot of fixes before merge --- src/components/app/Account/Account.css | 6 + src/components/app/Account/Account.jsx | 234 ++++++++++-------- src/components/app/Grades/Charts.jsx | 2 +- src/components/app/Grades/Grade.jsx | 17 +- src/components/app/Messaging/Inbox.jsx | 4 +- .../app/Messaging/MessageReader.jsx | 2 - src/components/app/Messaging/Messaging.jsx | 15 +- 7 files changed, 168 insertions(+), 112 deletions(-) diff --git a/src/components/app/Account/Account.css b/src/components/app/Account/Account.css index 729bc67..9b74a3a 100644 --- a/src/components/app/Account/Account.css +++ b/src/components/app/Account/Account.css @@ -233,6 +233,12 @@ body:has(#account) { align-items: center; } +.file-box-loader { + display: grid; + grid-template-columns: 3.5fr .5fr; + gap: 10px; +} + .file-date { margin-left: auto; margin-right: 30px; diff --git a/src/components/app/Account/Account.jsx b/src/components/app/Account/Account.jsx index d9fa47f..88b15f7 100644 --- a/src/components/app/Account/Account.jsx +++ b/src/components/app/Account/Account.jsx @@ -6,19 +6,21 @@ import Button from "../../generic/UserInputs/Button"; import DropDownMenu from "../../generic/UserInputs/DropDownMenu"; import { getProxiedURL } from "../../../utils/requests"; import FileComponent from "../../generic/FileComponent"; +import ContentLoader from "react-content-loader"; import "./Account.css"; +import { is } from "date-fns/locale"; export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrativeDocuments, sortSchoolLife, isLoggedIn, activeAccount }) { - const { accountsListState, useUserData, useUserSettings } = useContext(AppContext) + const { actualDisplayTheme, accountsListState, useUserData, useUserSettings } = useContext(AppContext) const settings = useUserSettings(); const userData = useUserData(); const moduletype = accountsListState[activeAccount].accountType === "E" ? "DOCUMENTS_ELEVE" : "DOCUMENTS"; - const module = accountsListState[activeAccount].modules.find(module => module.code === moduletype); - const availableYearsArray = module.params.AnneeArchive ? module.params.AnneeArchive.split(",") : []; + const module = (accountsListState[activeAccount].modules || []).find(module => module.code === moduletype); + const availableYearsArray = module?.params?.AnneeArchive ? module.params.AnneeArchive.split(",") : []; const lastYear = availableYearsArray.length > 0 ? availableYearsArray[availableYearsArray.length - 1] : `${new Date().getFullYear() - 1}-${new Date().getFullYear()}`; const [startYear, endYear] = lastYear.split('-').map(Number); const nextYear = `${endYear}-${endYear + 1}`; @@ -26,30 +28,7 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati const profilePictureRefs = useRef([]); - //fetch documents on page load - useEffect(() => { - if (isLoggedIn) { - const controller = new AbortController(); - const fetchDocuments = async () => { - try { - await fetchAdministrativeDocuments('', controller); - let data = userData.get("administrativeDocuments"); - if (data) { - setDocuments(data); - } else { - setDocuments({ factures: [], notes: [], viescolaire: [], administratifs: [], entreprises: [] }); - } - console.log("Documents fetched for year:", selectedYear, data); - } catch (error) { - console.error("Error fetching documents:", error); - } - }; - fetchDocuments(); - return () => { - controller.abort(); - }; - } - }, [isLoggedIn]); + const [isLoadingDocuments, setIsLoadingDocuments] = useState(true);; useEffect(() => { document.title = "Compte • Ecole Directe Plus"; @@ -84,7 +63,7 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati } }, [schoolLife, isLoggedIn, activeAccount]); - const [selectedYear, setSelectedYear] = useState(availableYearsArray[availableYearsArray.length - 1]); + const [selectedYear, setSelectedYear] = useState(settings.get("isSchoolYearEnabled") ? settings.get("schoolYear").join("-") : availableYearsArray[availableYearsArray.length - 1]); const [documents, setDocuments] = useState({ factures: [], notes: [], viescolaire: [], administratifs: [], entreprises: [] }); // handle year change of dropdown @@ -95,10 +74,12 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati // fetch documents on page load and year change useEffect(() => { + setIsLoadingDocuments(true); if (isLoggedIn && selectedYear) { const controller = new AbortController(); const fetchDocuments = async () => { try { + setIsLoadingDocuments(true); let selectedYearFetch = selectedYear === availableYearsArray[availableYearsArray.length - 1] ? '' : selectedYear; await fetchAdministrativeDocuments(selectedYearFetch, controller); let data = userData.get("administrativeDocuments"); @@ -110,8 +91,12 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati console.log("Documents fetched for year:", selectedYear, data); } catch (error) { console.error("Error fetching documents:", error); + } finally { + if (!controller.signal.aborted) { + setIsLoadingDocuments(false); + } } - }; + }; fetchDocuments(); return () => { controller.abort(); @@ -153,35 +138,81 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati
- {module.enable ? ( + {module?.enable ? ( <>

Documents

- { availableYearsArray.length > 1 ? ( + {availableYearsArray.length > 1 ? ( year)} - selected={selectedYear} - onChange={handleYearChange} - className="year-selector" + name="year-selector" + options={availableYearsArray} + displayedOptions={availableYearsArray.map(year => year)} + selected={selectedYear} + onChange={handleYearChange} + className="year-selector" /> ) : null }
- {documents?.administratifs?.length === 0 && - documents?.notes?.length === 0 && - documents?.viescolaire?.length === 0 && - documents?.entreprises?.length === 0 && - documents?.factures?.length === 0 - // && documents?.inscriptionsReinscriptions?.length === 0 - ? ( - Aucun document disponible. - // TODO: add content-loader - ) : ( - <> - {/* {module.params.DocumentsInscriptionsReinscriptionsActif === "1" && documents?.inscriptionsReinscriptions?.length > 0 && ( + {isLoadingDocuments ? ( +
+
+ {Array.from({ length: 5 }).map((_, index) => ( +
+

+ + + +

+ {Array.from({ length: Math.floor(Math.random() * 10 + 1) }, (_, index) => ( +
+ + + +

+ +

+
+ ))} +
+ ))} +
+
+ ) : + documents?.administratifs?.length === 0 && + documents?.notes?.length === 0 && + documents?.viescolaire?.length === 0 && + documents?.entreprises?.length === 0 && + documents?.factures?.length === 0 + // && documents?.inscriptionsReinscriptions?.length === 0 + ? ( + Aucun document disponible. + // TODO: add content-loader + ) : ( + <> + {/* {module.params.DocumentsInscriptionsReinscriptionsActif === "1" && documents?.inscriptionsReinscriptions?.length > 0 && (

Inscriptions & Réinscriptions

{documents.inscriptionsReinscriptions.map(file => ( @@ -192,68 +223,69 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati ))}
)} */} - {module?.params?.DocumentsFactureActif === "1" && documents?.factures?.length > 0 && ( -
-

Factures

- {documents.factures.map(file => ( -
- -

{file.specialParams.date}

+ + {module?.params?.DocumentsFactureActif === "1" && documents?.factures?.length > 0 && ( +
+

Factures

+ {documents.factures.map(file => ( +
+ +

{file.specialParams.date}

+
+ ))}
- ))} -
- )} - {module?.params?.DocumentsAdministratifActif === "1" && documents?.administratifs?.length > 0 && ( -
-

Documents Administratifs

- {documents.administratifs.map(file => ( -
- -

{file.specialParams.date}

+ )} + {module?.params?.DocumentsAdministratifActif === "1" && documents?.administratifs?.length > 0 && ( +
+

Documents Administratifs

+ {documents.administratifs.map(file => ( +
+ +

{file.specialParams.date}

+
+ ))}
- ))} -
- )} - {module?.params?.DocumentsNotesActif === "1" && documents?.notes?.length > 0 && ( -
-

Notes

- {documents.notes.map(file => ( -
- -

{file.specialParams.date}

+ )} + {module?.params?.DocumentsNotesActif === "1" && documents?.notes?.length > 0 && ( +
+

Notes

+ {documents.notes.map(file => ( +
+ +

{file.specialParams.date}

+
+ ))}
- ))} -
- )} - {module?.params?.DocumentsVSActif === "1" && documents?.viescolaire?.length > 0 && ( -
-

Vie Scolaire

- {documents.viescolaire.map(file => ( -
- -

{file.specialParams.date}

+ )} + {module?.params?.DocumentsVSActif === "1" && documents?.viescolaire?.length > 0 && ( +
+

Vie Scolaire

+ {documents.viescolaire.map(file => ( +
+ +

{file.specialParams.date}

+
+ ))}
- ))} -
- )} - {module?.params?.DocumentsEntrepriseActif === "1" && documents?.entreprises?.length > 0 && ( -
-

Documents Entreprise

- {documents.entreprises.map(file => ( -
- -

{file.specialParams.date}

+ )} + {module?.params?.DocumentsEntrepriseActif === "1" && documents?.entreprises?.length > 0 && ( +
+

Documents Entreprise

+ {documents.entreprises.map(file => ( +
+ +

{file.specialParams.date}

+
+ ))}
- ))} -
+ )} + )} - - )}
) : (
- Le module de documents n'est pas accessible. + Le module de documents n'est pas accessible.
)}
diff --git a/src/components/app/Grades/Charts.jsx b/src/components/app/Grades/Charts.jsx index c25a118..b47e42a 100644 --- a/src/components/app/Grades/Charts.jsx +++ b/src/components/app/Grades/Charts.jsx @@ -143,7 +143,7 @@ export default function Charts({ selectedPeriod }) { chartData.current = { labels: Array.from({ length: subjectsComparativeInformation[selectedPeriod].length }, (_, i) => subjectsComparativeInformation[selectedPeriod][i].subjectFullname), datasets: [ - ...(minMaxEnabled && false ? [ + ...(minMaxEnabled ? [ { type: "bar", label: "Moyennes min et max de classe", diff --git a/src/components/app/Grades/Grade.jsx b/src/components/app/Grades/Grade.jsx index 7e94bf4..ff6c8c0 100644 --- a/src/components/app/Grades/Grade.jsx +++ b/src/components/app/Grades/Grade.jsx @@ -14,7 +14,10 @@ export default function Grade({ grade, subject, className = "", ...props }) { const [selectedPeriod, setSelectedPeriod] = useState(userData.get("activePeriod")); const generalAverage = sortedGrades[selectedPeriod].generalAverage; - const subjectsSummedCoefs = getSummedCoef(sortedGrades[selectedPeriod].subjects); + const gradeCoef = grade.coef ?? 1; + let subjectCoef = grade?.subject?.coef ?? gradeCoef; + let subjectsSummedCoefs = getSummedCoef(sortedGrades[selectedPeriod].subjects); + function getSummedCoef(subjects) { let sum = 0; @@ -23,12 +26,20 @@ export default function Grade({ grade, subject, className = "", ...props }) { sum += subjects[key].coef; } } + // if all subjects have 0 as coef, we replace all coef by 1 + if (sum === 0) { + sum = Object.keys(subjects).length; + subjectCoef = 1; + } + return sum; } // Use subject coef if subject is provided, otherwise use grade's coef - const gradeCoef = grade.coef ?? 1; - const subjectCoef = grade?.subject?.coef ?? gradeCoef; + + // if all subjects have 0 as coef, we replace all coef by 1 to avoid division by 0 + + const gradeScore = (subjectCoef * (grade.value - generalAverage)) / ((subjectsSummedCoefs - subjectCoef) || 1); const coefficientEnabled = useUserData().get("gradesEnabledFeatures")?.coefficient; diff --git a/src/components/app/Messaging/Inbox.jsx b/src/components/app/Messaging/Inbox.jsx index 5bba942..3954428 100644 --- a/src/components/app/Messaging/Inbox.jsx +++ b/src/components/app/Messaging/Inbox.jsx @@ -64,7 +64,7 @@ export default function Inbox({ selectedMessage, setSelectedMessage, selectedFol try { // regexp = new RegExp(removeAccents(search.toLowerCase())); } catch { return -1 } - const filterBy = [message.subject, message.from.name, message.content?.content, message.files?.map((file) => file.name)].flat(); + const filterBy = [message.subject, message.from.nom, message.content?.content, message.files?.map((file) => file.name)].flat(); for (let filter of filterBy) { if (filter) { filter = removeAccents(filter.toLowerCase()); @@ -92,7 +92,7 @@ export default function Inbox({ selectedMessage, setSelectedMessage, selectedFol ?