Skip to content

Commit

Permalink
fixed documents content loader, author name in MessageReader, and wea…
Browse files Browse the repository at this point in the history
…knesses ranking
  • Loading branch information
Truiteseche committed Nov 11, 2024
1 parent 43c8c99 commit 53d1a0f
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 70 deletions.
127 changes: 62 additions & 65 deletions src/components/app/Account/Account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 (
<div id="account">
Expand Down Expand Up @@ -158,44 +155,45 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati
{isLoadingDocuments ? (
<div>
<div className="document-category">
{Array.from({ length: 5 }).map((_, index) => (
<div style={{padding: "15px"}}>
<h3 style={{paddingBottom: "10px"}}>
<ContentLoader
animate={settings.get("displayMode") === "quality"}
speed={1}
backgroundColor={actualDisplayTheme === "dark" ? "#63638c" : "#9d9dbd"}
foregroundColor={actualDisplayTheme === "dark" ? "#7e7eb2" : "#bcbce3"}
height="30"
style={{ width: "30%" }}
>
<rect x="0" y="0" rx="5" ry="5" width="100%" height="100%" />
</ContentLoader>
</h3>
{Array.from({ length: Math.floor(Math.random() * 10 + 1) }, (_, index) => (
<div className="file-box-loader " style={{paddingBottom: "3px"}}>
<ContentLoader
animate={settings.get("displayMode") === "quality"}
speed={1}
backgroundColor={actualDisplayTheme === "dark" ? "#63638c" : "#9d9dbd"}
foregroundColor={actualDisplayTheme === "dark" ? "#7e7eb2" : "#bcbce3"}
height="30"
style={{ width: `${Math.floor(Math.random() * 31) + 60}%` }}
>
<rect x="0" y="0" rx="5" ry="5" width="100%" height="100%" />
</ContentLoader>
<h2 className="file-date"> <ContentLoader
animate={settings.get("displayMode") === "quality"}
speed={1}
backgroundColor={actualDisplayTheme === "dark" ? "#63638c" : "#9d9dbd"}
foregroundColor={actualDisplayTheme === "dark" ? "#7e7eb2" : "#bcbce3"}
height="30"
style={{ width: "100%" }}
>
<rect x="0" y="0" rx="5" ry="5" width="100%" height="100%" />
</ContentLoader></h2>
</div>
))}
{Array.from({ length: 3 }).map((_, index) => (
<div style={{ padding: "15px" }}>
<h3 style={{ paddingBottom: "10px" }}>
<ContentLoader
animate={settings.get("displayMode") === "quality"}
speed={1}
backgroundColor={actualDisplayTheme === "dark" ? "#5b5abd" : "#9595cc"}
foregroundColor={actualDisplayTheme === "dark" ? "#494897" : "#b0b0f2"}
height="30"
style={{ width: "30%" }}
>
<rect x="0" y="0" rx="5" ry="5" width="100%" height="100%" />
</ContentLoader>
</h3>
{Array.from({ length: contentLoaderRandomValues.current.documentsNumber[index] }, (_, index) => (
<div className="file-box-loader " style={{ marginBottom: "10px" }}>
<ContentLoader
animate={settings.get("displayMode") === "quality"}
speed={1}
backgroundColor={actualDisplayTheme === "dark" ? "#5b5abd" : "#9595cc"}
foregroundColor={actualDisplayTheme === "dark" ? "#494897" : "#b0b0f2"}
height="25"
style={{ width: `${contentLoaderRandomValues.current.fileNameWidth[index]}%` }}
>
<rect x="0" y="0" rx="5" ry="5" width="100%" height="100%" />
</ContentLoader>
<h2 className="file-date" style={{ display: "flex", alignItems: "center"}}>
<ContentLoader
animate={settings.get("displayMode") === "quality"}
speed={1}
backgroundColor={actualDisplayTheme === "dark" ? "#5b5abd" : "#9595cc"}
foregroundColor={actualDisplayTheme === "dark" ? "#494897" : "#b0b0f2"}
height="20"
style={{ width: "100%" }}
>
<rect x="0" y="0" rx="5" ry="5" width="100%" height="100%" />
</ContentLoader></h2>
</div>
))}
</div>
))}
</div>
Expand All @@ -209,7 +207,6 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati
// && documents?.inscriptionsReinscriptions?.length === 0
? (
<span className="no-available-documents">Aucun document disponible.</span>
// TODO: add content-loader
) : (
<>
{/* {module.params.DocumentsInscriptionsReinscriptionsActif === "1" && documents?.inscriptionsReinscriptions?.length > 0 && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/app/Grades/Strengths.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function Strengths({ activeAccount, sortedGrades, selectedPeriod,
(displayType === 0 ? strengths : weaknesses).map((strength, idx) => <li key={strength?.subject?.name || crypto.randomUUID()} style={{ "--order": idx }} className="strength-container">
<Link to={"#" + strength?.subject?.id} className="strength-wrapper">
<span className="subject-container">
<span className="subject-rank">{idx + 1}</span>
<span className="subject-rank">{displayType === 0 ? idx + 1 : (sortedGrades && Object.keys(sortedGrades[selectedPeriod].subjects).length || 3) - idx}</span>
<span className="subject-name">{strength?.subject?.name}</span>
</span>
<span className="subject-average"><Grade grade={{ value: strength?.subject?.average ?? "N/A" }} /></span>
Expand Down
2 changes: 1 addition & 1 deletion src/components/app/Messaging/Inbox.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default function Inbox({ selectedMessage, setSelectedMessage, selectedFol
? <ScrollShadedDiv className="messages-container">
<ul>
{messages.filter((message) => message.folderId === selectedFolder).filter(filterResearch).map((message, index) => <li style={{ "--order": index }} className={"message-container" + (selectedMessage === message.id ? " selected" : "")} data-read={message.read} onClick={() => handleClick(message)} onKeyDown={(event) => handleKeyDown(event, message)} key={message.id} role="button" tabIndex={0}>
<h4 className="message-subject"><span className="author-name">{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)}</span> <span className="actions"><button disabled={!message.read} onClick={(event) => handleMarkAsUnread(event, message)} className="mark-as-unread" title="Marquer comme non lu"><MarkAsUnread className="mark-as-unread-icon" /></button> {message.files?.length > 0 && <AttachmentIcon className="attachment-icon" />}</span></h4>
<h4 className="message-subject"><span className="author-name">{message.from.civilite + " " + (settings.get("isStreamerModeEnabled") ? "-".repeat((message.from.nom).length) : message.from.nom)}</span> <span className="actions"><button disabled={!message.read} onClick={(event) => handleMarkAsUnread(event, message)} className="mark-as-unread" title="Marquer comme non lu"><MarkAsUnread className="mark-as-unread-icon" /></button> {message.files?.length > 0 && <AttachmentIcon className="attachment-icon" />}</span></h4>
<p className="message-author">{message.subject}</p>
<p className="message-date">{(new Date(message.date)).toLocaleDateString("fr-FR", {
month: "long",
Expand Down
2 changes: 1 addition & 1 deletion src/components/app/Messaging/MessageReader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default function MessageReader({ selectedMessage, fetchMessageMarkAsUnrea
{selectedMessage !== null && messages && messages.length > 0
? <div className="message-container">
<div className="email-header">
<p className="author">{message && (settings.get("isStreamerModeEnabled") ? message?.from?.name?.split(" ")[0] + " " + "-".repeat(message?.from?.name?.length) : message?.from?.name)}</p>
<p className="author">{message && (message?.from?.civilite + " " + (settings.get("isStreamerModeEnabled") ? "-".repeat(message?.from?.nom?.length) : message?.from?.nom))}</p>
<h3>{message && capitalizeFirstLetter(message?.subject)}</h3>
<p className="send-date">{message && message?.date && (new Date(message.date).toLocaleDateString("fr-FR", {
month: "long",
Expand Down
4 changes: 2 additions & 2 deletions src/components/app/Messaging/Messaging.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/components/generic/FileComponent.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
}

.file-component .file-name {
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
Expand Down

0 comments on commit 53d1a0f

Please sign in to comment.