Skip to content

Commit

Permalink
multiple fixes including undefined based errors and typos
Browse files Browse the repository at this point in the history
  • Loading branch information
Truiteseche committed Dec 6, 2024
1 parent 65f25e4 commit ce85fc8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ export default function App({ edpFetch }) {
subjectDatas[periodCode][subjectCode].push({ value: newGrade.value, coef: newGrade.coef, scale: newGrade.scale, isSignificant: newGrade.isSignificant, classAverage: newGrade.classAverage });
const nbSubjectGrades = periods[periodCode].subjects[subjectCode]?.grades.filter((el) => el.isSignificant).length ?? 0;
const subjectAverage = periods[periodCode].subjects[subjectCode].average;
const oldGeneralAverage = isNaN(periods[periodCode].generalAverage) ? 10 : periods[periodCode].generalAverage;
const oldGeneralAverage = isNaN(periods[periodCode]?.generalAverage) ? 10 : periods[periodCode]?.generalAverage;
const average = calcAverage(subjectDatas[periodCode][subjectCode]);
const classAverage = calcClassAverage(subjectDatas[periodCode][subjectCode]);

Expand Down
6 changes: 3 additions & 3 deletions src/components/app/Account/Account.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati
)}
{module?.params?.DocumentsAdministratifActif === "1" && documents?.administratifs?.length > 0 && (
<div className="document-category">
<h3>Documents Administratifs</h3>
<h3>Documents administratifs</h3>
{documents.administratifs.map(file => (
<div className="file-box">
<FileComponent key={file.id} file={file} />
Expand All @@ -266,7 +266,7 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati
)}
{module?.params?.DocumentsVSActif === "1" && documents?.viescolaire?.length > 0 && (
<div className="document-category">
<h3>Vie Scolaire</h3>
<h3>Vie scolaire</h3>
{documents.viescolaire.map(file => (
<div className="file-box">
<FileComponent key={file.id} file={file} />
Expand All @@ -277,7 +277,7 @@ export default function Account({ schoolLife, fetchSchoolLife, fetchAdministrati
)}
{module?.params?.DocumentsEntrepriseActif === "1" && documents?.entreprises?.length > 0 && (
<div className="document-category">
<h3>Documents Entreprise</h3>
<h3>Documents entreprise</h3>
{documents.entreprises.map(file => (
<div className="file-box">
<FileComponent key={file.id} file={file} />
Expand Down
4 changes: 2 additions & 2 deletions src/components/app/Grades/MobileResults.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export default function Results({ activeAccount, sortedGrades, selectedPeriod, s
<TooltipTrigger>
<span>
{sortedGrades && sortedGrades[selectedPeriod]
? <Grade grade={{ value: sortedGrades[selectedPeriod].generalAverage ?? "N/A", scale: 20, coef: 1, isSignificant: true }} />
? <Grade grade={{ value: sortedGrades[selectedPeriod]?.generalAverage ?? "N/A", scale: 20, coef: 1, isSignificant: true }} />
: <ContentLoader
animate={settings.get("displayMode") === "quality"}
speed={1}
Expand Down Expand Up @@ -139,7 +139,7 @@ export default function Results({ activeAccount, sortedGrades, selectedPeriod, s
</TooltipContent>
</Tooltip>
: sortedGrades && sortedGrades[selectedPeriod]
? <Grade grade={{ value: sortedGrades[selectedPeriod].generalAverage ?? "-", scale: 20, coef: 1, isSignificant: true }} />
? <Grade grade={{ value: sortedGrades[selectedPeriod]?.generalAverage ?? "-", scale: 20, coef: 1, isSignificant: true }} />
: <ContentLoader
animate={settings.get("displayMode") === "quality"}
speed={1}
Expand Down
4 changes: 2 additions & 2 deletions src/components/app/Grades/Results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export default function Results({ activeAccount, sortedGrades, selectedPeriod, s
<TooltipTrigger>
<span>
{sortedGrades && sortedGrades[selectedPeriod]
? <Grade grade={{ value: sortedGrades[selectedPeriod].generalAverage ?? "N/A", scale: 20, coef: 1, isSignificant: true }} />
? <Grade grade={{ value: sortedGrades[selectedPeriod]?.generalAverage ?? "N/A", scale: 20, coef: 1, isSignificant: true }} />
: <ContentLoader
animate={settings.get("displayMode") === "quality"}
speed={1}
Expand Down Expand Up @@ -142,7 +142,7 @@ export default function Results({ activeAccount, sortedGrades, selectedPeriod, s
</TooltipContent>
</Tooltip>
: sortedGrades && sortedGrades[selectedPeriod]
? <Grade grade={{ value: sortedGrades[selectedPeriod].generalAverage ?? "-", scale: 20, coef: 1, isSignificant: true }} />
? <Grade grade={{ value: sortedGrades[selectedPeriod]?.generalAverage ?? "-", scale: 20, coef: 1, isSignificant: true }} />
: <ContentLoader
animate={settings.get("displayMode") === "quality"}
speed={1}
Expand Down
3 changes: 2 additions & 1 deletion src/components/app/Homeworks/Calendar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { fr } from 'date-fns/locale';
import DropDownArrow from "../../graphics/DropDownArrow";

import './Calendar.css';
import { isValidDateFormat } from '../../../utils/date';

export default function Calendar({ onDateClick }) {
const today = new Date()
Expand All @@ -20,7 +21,7 @@ export default function Calendar({ onDateClick }) {

const navigate = useNavigate();
const hashParameters = location.hash.split(";");
const selectedISODate = hashParameters[0].slice(1) || format(today, "yyyy-MM-dd");
const selectedISODate = isValidDateFormat(hashParameters[0].slice(1)) ? hashParameters[0].slice(1) : Date.now();
const selectedDate = new Date(selectedISODate);

const userHomeworks = useUserData("sortedHomeworks");
Expand Down
4 changes: 2 additions & 2 deletions src/components/app/Homeworks/Interrogation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ export default function Interrogation({ task }) { // This component only exists
const taskColor = typeof task.id === "number" ? textToHSL(task.subjectCode) : undefined;

return typeof task.id === "number"
? <div tabIndex="0" role="a" onKeyDown={(e) => handleKeyDown(e, task.date, task.id)} onClick={() => handleClick(task.date, task.id)} className={`upcoming-assignments ${currentSortedHomeworks[task.date][task.index].isDone ? "done" : ""}`}
? <div tabIndex="0" role="a" onKeyDown={(e) => handleKeyDown(e, task.date, task.id)} onClick={() => handleClick(task.date, task.id)} className={`upcoming-assignments ${currentSortedHomeworks[task.date][task.index]?.isDone ? "done" : ""}`}
style={{
"--subject-main-color": actualDisplayTheme === "dark" ? `hsl(${taskColor[0]}, ${taskColor[1]}%, ${taskColor[2]}%)` : `hsl(${taskColor[0]}, ${taskColor[1] - 20}%, ${taskColor[2] - 30}%)`,
"--subject-bg-color": actualDisplayTheme === "dark" ? `hsla(${taskColor[0]}, ${taskColor[1]}%, ${taskColor[2]}%, .2)` : `hsla(${taskColor[0]}, ${taskColor[1] - 20}%, ${taskColor[2] - 30}%, .2)`,
// "--text-color-task": `hsl(${taskColor[0]}, ${taskColor[1] - 20}%, ${taskColor[2] - 20}%)`,
// "--background-color-task": `hsl(${taskColor[0]}, ${taskColor[1] - 5}%, ${taskColor[2] - 5}%)`,
}}>
<CheckBox onChange={() => { checkTask(task.date, task.index) }} ref={taskCheckboxRef} checked={currentSortedHomeworks[task.date][task.index].isDone} id={`${task.id}-upcoming-assignments"`} onMouseEnter={() => isMouseInCheckBoxRef.current = true} onMouseLeave={() => isMouseInCheckBoxRef.current = false} style={{ "backgroundImage": currentSortedHomeworks[task.date][task.index].isDone ? `url("data:image/svg+xml,%3Csvg width='126' height='90' viewBox='0 0 126 90' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3.00999 29.4982L4.7539 27.7442C8.77118 23.7036 15.3475 23.8312 19.205 28.0246L47.306 58.5723C48.849 60.2496 51.4795 60.3007 53.0864 58.6844L108.318 3.13256C112.228 -0.799963 118.591 -0.799963 122.501 3.13256L122.99 3.62419C126.868 7.5247 126.868 13.8249 122.99 17.7254L52.9741 88.147C51.4102 89.72 48.8649 89.72 47.301 88.147L3.00999 43.5994C-0.868052 39.6989 -0.868055 33.3987 3.00999 29.4982Z' fill='hsl(${taskColor[0]}, ${taskColor[1]}%, ${taskColor[2]}%)'/%3E%3C/svg%3E")` : "" }} />
<CheckBox onChange={() => { checkTask(task.date, task.index) }} ref={taskCheckboxRef} checked={currentSortedHomeworks[task.date][task.index]?.isDone} id={`${task.id}-upcoming-assignments"`} onMouseEnter={() => isMouseInCheckBoxRef.current = true} onMouseLeave={() => isMouseInCheckBoxRef.current = false} style={{ "backgroundImage": currentSortedHomeworks[task.date][task.index]?.isDone ? `url("data:image/svg+xml,%3Csvg width='126' height='90' viewBox='0 0 126 90' fill='none' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M3.00999 29.4982L4.7539 27.7442C8.77118 23.7036 15.3475 23.8312 19.205 28.0246L47.306 58.5723C48.849 60.2496 51.4795 60.3007 53.0864 58.6844L108.318 3.13256C112.228 -0.799963 118.591 -0.799963 122.501 3.13256L122.99 3.62419C126.868 7.5247 126.868 13.8249 122.99 17.7254L52.9741 88.147C51.4102 89.72 48.8649 89.72 47.301 88.147L3.00999 43.5994C-0.868052 39.6989 -0.868055 33.3987 3.00999 29.4982Z' fill='hsl(${taskColor[0]}, ${taskColor[1]}%, ${taskColor[2]}%)'/%3E%3C/svg%3E")` : "" }} />
<span><span className="interrogation-label">{task.subject}</span></span>
<span>{formatDateRelative(new Date(task.date))}</span>
</div>
Expand Down
8 changes: 8 additions & 0 deletions src/utils/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ export function formatDateRelative(date, short=true) {
}
}

export function isValidDateFormat(dateString) {
if (!dateString) {
return false;
}
const regex = /^\d{4}-\d{2}-\d{2}$/; // Matches YYYY-MM-DD format
return regex.test(dateString);
}

export function getCurrentSchoolYear() {
/**
* return an array:
Expand Down

0 comments on commit ce85fc8

Please sign in to comment.