From 53d1a0fe75513bae899ff975a0d2998e0ba27191 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Truite=20S=C3=A9ch=C3=A9e?= Date: Mon, 11 Nov 2024 14:52:46 +0100 Subject: [PATCH] fixed documents content loader, author name in MessageReader, and weaknesses ranking --- src/components/app/Account/Account.jsx | 127 +++++++++--------- src/components/app/Grades/Strengths.jsx | 2 +- src/components/app/Messaging/Inbox.jsx | 2 +- .../app/Messaging/MessageReader.jsx | 2 +- src/components/app/Messaging/Messaging.jsx | 4 +- src/components/generic/FileComponent.css | 1 + 6 files changed, 68 insertions(+), 70 deletions(-) diff --git a/src/components/app/Account/Account.jsx b/src/components/app/Account/Account.jsx index 88b15f7..95bf45c 100644 --- a/src/components/app/Account/Account.jsx +++ b/src/components/app/Account/Account.jsx @@ -27,8 +27,9 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati availableYearsArray.push(nextYear); const profilePictureRefs = useRef([]); + const contentLoaderRandomValues = useRef({ documentsNumber: Array.from({ length: 3 }, (_) => Math.floor(Math.random() * 10) + 1), fileNameWidth: Array.from({ length: 10 }, (_) => Math.floor(Math.random() * 31) + 60 ) }); - const [isLoadingDocuments, setIsLoadingDocuments] = useState(true);; + const [isLoadingDocuments, setIsLoadingDocuments] = useState(true); useEffect(() => { document.title = "Compte • Ecole Directe Plus"; @@ -76,33 +77,29 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati 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"); - if (data) { - setDocuments(data); - } else { - setDocuments({ factures: [], notes: [], viescolaire: [], administratifs: [], entreprises: [] }); + let data = userData.get("administrativeDocuments"); + if (data === undefined) { + const controller = new AbortController(); + const fetchDocuments = async () => { + try { + setIsLoadingDocuments(true); + let selectedYearFetch = selectedYear === availableYearsArray[availableYearsArray.length - 1] ? '' : selectedYear; + await fetchAdministrativeDocuments(selectedYearFetch, controller); + } catch (error) { + console.error("Error fetching documents:", error); } - 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(); - }; + }; + fetchDocuments(); + + return () => { + controller.abort(); + }; + } + + setDocuments(data); + setIsLoadingDocuments(false); } - }, [selectedYear, isLoggedIn]); + }, [selectedYear, isLoggedIn, userData.get("administrativeDocuments")]); return (
@@ -158,44 +155,45 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati {isLoadingDocuments ? (
- {Array.from({ length: 5 }).map((_, index) => ( -
-

- - - -

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

- -

-
- ))} + {Array.from({ length: 3 }).map((_, index) => ( +
+

+ + + +

+ {Array.from({ length: contentLoaderRandomValues.current.documentsNumber[index] }, (_, index) => ( +
+ + + +

+ + +

+
+ ))}
))}
@@ -209,7 +207,6 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati // && documents?.inscriptionsReinscriptions?.length === 0 ? ( Aucun document disponible. - // TODO: add content-loader ) : ( <> {/* {module.params.DocumentsInscriptionsReinscriptionsActif === "1" && documents?.inscriptionsReinscriptions?.length > 0 && ( diff --git a/src/components/app/Grades/Strengths.jsx b/src/components/app/Grades/Strengths.jsx index cc06acd..008601e 100644 --- a/src/components/app/Grades/Strengths.jsx +++ b/src/components/app/Grades/Strengths.jsx @@ -80,7 +80,7 @@ export default function Strengths({ activeAccount, sortedGrades, selectedPeriod, (displayType === 0 ? strengths : weaknesses).map((strength, idx) =>
  • - {idx + 1} + {displayType === 0 ? idx + 1 : (sortedGrades && Object.keys(sortedGrades[selectedPeriod].subjects).length || 3) - idx} {strength?.subject?.name} diff --git a/src/components/app/Messaging/Inbox.jsx b/src/components/app/Messaging/Inbox.jsx index 3954428..786cea5 100644 --- a/src/components/app/Messaging/Inbox.jsx +++ b/src/components/app/Messaging/Inbox.jsx @@ -92,7 +92,7 @@ export default function Inbox({ selectedMessage, setSelectedMessage, selectedFol ?
      {messages.filter((message) => message.folderId === selectedFolder).filter(filterResearch).map((message, index) =>
    • handleClick(message)} onKeyDown={(event) => handleKeyDown(event, message)} key={message.id} role="button" tabIndex={0}> -

      {settings.get("isStreamerModeEnabled") ? (message.from.civilite + " " + message.from.prenom + " " + message.from.nom).split(" ")[0] + " " + "-".repeat((message.from.civilite + " " + message.from.prenom + " " + message.from.nom).length) : (message.from.civilite + " " + message.from.prenom + " " + message.from.nom)} {message.files?.length > 0 && }

      +

      {message.from.civilite + " " + (settings.get("isStreamerModeEnabled") ? "-".repeat((message.from.nom).length) : message.from.nom)} {message.files?.length > 0 && }

      {message.subject}

      {(new Date(message.date)).toLocaleDateString("fr-FR", { month: "long", diff --git a/src/components/app/Messaging/MessageReader.jsx b/src/components/app/Messaging/MessageReader.jsx index f03cce0..cc17b13 100644 --- a/src/components/app/Messaging/MessageReader.jsx +++ b/src/components/app/Messaging/MessageReader.jsx @@ -70,7 +70,7 @@ export default function MessageReader({ selectedMessage, fetchMessageMarkAsUnrea {selectedMessage !== null && messages && messages.length > 0 ?

      -

      {message && (settings.get("isStreamerModeEnabled") ? message?.from?.name?.split(" ")[0] + " " + "-".repeat(message?.from?.name?.length) : message?.from?.name)}

      +

      {message && (message?.from?.civilite + " " + (settings.get("isStreamerModeEnabled") ? "-".repeat(message?.from?.nom?.length) : message?.from?.nom))}

      {message && capitalizeFirstLetter(message?.subject)}

      {message && message?.date && (new Date(message.date).toLocaleDateString("fr-FR", { month: "long", diff --git a/src/components/app/Messaging/Messaging.jsx b/src/components/app/Messaging/Messaging.jsx index 427ebdc..d955f17 100644 --- a/src/components/app/Messaging/Messaging.jsx +++ b/src/components/app/Messaging/Messaging.jsx @@ -46,13 +46,13 @@ export default function Messaging({ isLoggedIn, activeAccount, fetchMessages, fe const module = accountsListState[activeAccount].modules?.find(module => module.code === "MESSAGERIE"); - let canSendMessages = (module?.params?.destAdmin ?? "1") === "1" || + let canSendMessages = false && (module?.params?.destAdmin ?? "1") === "1" || (module?.params?.destEleve ?? "1") === "1" || (module?.params?.destFamille ?? "1") === "1" || (module?.params?.destProf ?? "1") === "1" || (module?.params?.destEspTravail ?? "1") === "1"; if (accountsListState[activeAccount].accountType !== "E") { - canSendMessages = true; + // canSendMessages = true; } const [isEditingFolder, setIsEditingFolder] = useState(false); diff --git a/src/components/generic/FileComponent.css b/src/components/generic/FileComponent.css index c5963bb..19215db 100644 --- a/src/components/generic/FileComponent.css +++ b/src/components/generic/FileComponent.css @@ -45,6 +45,7 @@ } .file-component .file-name { + flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;