From 70c7db810f20b1f488e7cae3794cb4bc5df7331b Mon Sep 17 00:00:00 2001 From: Dark-Louis Date: Thu, 13 Nov 2025 21:19:09 +0100 Subject: [PATCH 1/2] Grades subject - Added a badge on the grade cards to display the subject --- src/lib/utils/grades.ts | 40 +++++++++++++++++++++++++++++++++ src/pages/grades/grade-card.tsx | 24 ++++++++++++++++++-- 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/lib/utils/grades.ts b/src/lib/utils/grades.ts index 40601d5..197b419 100644 --- a/src/lib/utils/grades.ts +++ b/src/lib/utils/grades.ts @@ -34,3 +34,43 @@ export function getGrades({ return true; }); } + +export type GradeBadgeInfo = { + label: string; + rawCode: string; + normalizedCode: string; +}; + +const gradeBadgeKeywordMap: Array<{ keyword: string; label: string }> = [ + { keyword: "maths", label: "Maths" }, + { keyword: "physique", label: "Physique" }, + { keyword: "info", label: "Informatique" }, + { keyword: "anglais", label: "Anglais" }, + { keyword: "sii", label: "SII" }, + { keyword: "fhs", label: "FHS" }, +]; + +export function getGradeBadgeInfoFromCode(code?: string | null): GradeBadgeInfo | null { + const rawCode = (code ?? "").trim(); + if (!rawCode) return null; + + const normalizedBase = rawCode + .normalize("NFD") + .replace(/[\u0300-\u036f]/g, "") + .replace(/\s+/g, " ") + .trim(); + + const normalizedCode = normalizedBase.toUpperCase(); + const searchableCode = normalizedBase.toLowerCase(); + + const keywordMatch = gradeBadgeKeywordMap.find(({ keyword }) => + searchableCode.includes(keyword) + ); + const label = keywordMatch?.label ?? ""; + + return { + label, + rawCode, + normalizedCode, + }; +} diff --git a/src/pages/grades/grade-card.tsx b/src/pages/grades/grade-card.tsx index 014ff2f..ed7dd09 100644 --- a/src/pages/grades/grade-card.tsx +++ b/src/pages/grades/grade-card.tsx @@ -1,10 +1,12 @@ import { Card } from "@/components/ui/card"; +import { Badge } from "@/components/ui/badge"; import { Grade } from "@/types/aurion"; import { format } from "date-fns"; import { fr } from "date-fns/locale"; import { motion } from "framer-motion"; import { SquareArrowOutDownRightIcon } from "lucide-react"; import { useTranslation } from "react-i18next"; +import { getGradeBadgeInfoFromCode } from "@/lib/utils/grades"; const MotionCard = motion(Card); @@ -39,9 +41,10 @@ export function GradeCardAnimate({ initial="hidden" animate="show" exit="exit" - className="border-none bg-white shadow-md transition-shadow dark:bg-mauria-card p-4 h-full" + className="relative border-none bg-white shadow-md transition-shadow dark:bg-mauria-card p-4 h-full overflow-visible" onClick={onGradeClick.bind(null, grade)} > +
@@ -91,9 +94,10 @@ export function GradeCard({ return ( +
@@ -131,3 +135,19 @@ export function GradeCard({ ); } + +const GradeTypeBadge = ({ code }: { code?: string | null }) => { + if (!code?.trim()) return null; + + const badgeInfo = getGradeBadgeInfoFromCode(code); + if (!badgeInfo?.label) return null; + + return ( + + {badgeInfo.label} + + ); +}; From 3479e80977303b3444bd444be47df97f6d59f5a3 Mon Sep 17 00:00:00 2001 From: Dark-Louis Date: Thu, 13 Nov 2025 21:58:48 +0100 Subject: [PATCH 2/2] More subjects - Added more subjects --- src/lib/utils/grades.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/lib/utils/grades.ts b/src/lib/utils/grades.ts index 197b419..e9b7abc 100644 --- a/src/lib/utils/grades.ts +++ b/src/lib/utils/grades.ts @@ -42,9 +42,12 @@ export type GradeBadgeInfo = { }; const gradeBadgeKeywordMap: Array<{ keyword: string; label: string }> = [ - { keyword: "maths", label: "Maths" }, - { keyword: "physique", label: "Physique" }, + { keyword: "math", label: "Maths" }, + { keyword: "phys", label: "Physique" }, + { keyword: "optique", label: "Physique" }, { keyword: "info", label: "Informatique" }, + { keyword: "prog", label: "Informatique" }, + { keyword: "web", label: "Informatique" }, { keyword: "anglais", label: "Anglais" }, { keyword: "sii", label: "SII" }, { keyword: "fhs", label: "FHS" },