From 4aebc41e2bfa9a7ea6d2eef0e395aa045b292db9 Mon Sep 17 00:00:00 2001 From: Nathan Lamy Date: Tue, 23 Dec 2025 11:59:01 +0100 Subject: [PATCH] feat: add syllabus --- app/lib/utils.ts | 45 ++++++++++++++++++++++++++++++++++ app/routes/colles.tsx | 57 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 99 insertions(+), 3 deletions(-) diff --git a/app/lib/utils.ts b/app/lib/utils.ts index 2a7133f..6d1dc00 100644 --- a/app/lib/utils.ts +++ b/app/lib/utils.ts @@ -152,3 +152,48 @@ export const getSubjectColor = (subject: string, pref: UserPreferences) => { // === DEBUG UTILS === export const clearCache = () => del(CACHE_KEY); + +// === MP* COLLES SYLLABUS CONSTANTS === +export function getColleWeek(date: Date) { + // Define week ranges [start, end, week_number] + const weeks = [ + ["15/09/2025", "20/09/2025", 0], + ["22/09/2025", "27/09/2025", 1], + ["29/09/2025", "04/10/2025", 2], + ["06/10/2025", "11/10/2025", 3], + ["13/10/2025", "18/10/2025", 4], + ["03/11/2025", "08/11/2025", 5], + ["10/11/2025", "15/11/2025", 6], + ["17/11/2025", "22/11/2025", 7], + ["24/11/2025", "29/11/2025", 8], + ["01/12/2025", "06/12/2025", 9], + ["08/12/2025", "13/12/2025", 10], + ["15/12/2025", "20/12/2025", 11], + ["05/01/2026", "10/01/2026", 12], + ["12/01/2026", "17/01/2026", 13], + ["19/01/2026", "24/01/2026", 14], + ["26/01/2026", "31/01/2026", 15], + ["02/02/2026", "07/02/2026", 16], + ["09/02/2026", "14/02/2026", 17], + ["09/03/2026", "14/03/2026", 18], + ["16/03/2026", "21/03/2026", 19], + ] as [string, string, number][]; + + // Helper function to parse DD/MM/YYYY string to Date + function parseDate(dateStr: string): Date { + const [day, month, year] = dateStr.split("/").map(Number); + return new Date(year, month - 1, day); + } + + // Check which week the date falls into + for (const [startStr, endStr, weekNum] of weeks) { + const startDate = parseDate(startStr); + const endDate = parseDate(endStr); + + if (date >= startDate && date <= endDate) { + return weekNum; + } + } + + return null; +} diff --git a/app/routes/colles.tsx b/app/routes/colles.tsx index c16a6dd..abcaa54 100644 --- a/app/routes/colles.tsx +++ b/app/routes/colles.tsx @@ -20,18 +20,26 @@ import { Share2, ExternalLink, Users, + Album, } from "lucide-react"; import { Separator } from "~/components/ui/separator"; import ColleDetailsSkeleton from "~/components/details/skeleton-details"; import AttachmentItem from "~/components/details/attachment"; import Error from "~/components/error"; import { Badge } from "~/components/ui/badge"; -import { AUTH_ERROR, refreshColle, useColle, useUser } from "~/lib/api"; +import { + AUTH_ERROR, + refreshColle, + useColle, + useUser, + type Colle, +} from "~/lib/api"; import { toast } from "sonner"; import { formatDate, formatGrade, formatTime, + getColleWeek, getColorClass, getSubjectColor, getSubjectEmoji, @@ -81,6 +89,37 @@ export default function ColleDetailPage() { const handleToggleFavorite = () => {}; + // TODO: Temp fix to get the colle syllabus + const getColleSyllabus = (colle: Colle) => { + // Return YYYYMMDD format + const formatDateForSyllabus = (date: Date) => { + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, "0"); + const day = String(date.getDate()).padStart(2, "0"); + return `${year}${month}${day}`; + }; + + // Physique-Chimie + if (colle.subject.name === "Physique-Chimie") { + return ( + "https://bjcolle.fr/syllabus_oral.php?disc=22&jour=" + + formatDateForSyllabus(new Date(colle.date)) + ); + } + + // Mathématiques + if (colle.subject.name === "Mathématiques") { + const week = getColleWeek(new Date(colle.date)); // Syllabus weeks are 1-indexed + if (week) + return "http://www.mp1.bginette.com/Colles/ColleXX.pdf".replace( + "XX", + (week + 1).toString().padStart(2, "0") + ); + } + + return null; + }; + const handleReload = () => { setIsReloading(true); refreshColle(colle.id) @@ -146,6 +185,7 @@ export default function ColleDetailPage() { getSubjectColor(colle.subject.name, user.preferences) ); const subjectEmoji = getSubjectEmoji(colle.subject.name, user.preferences); + const syllabusLink = getColleSyllabus(colle); return (
@@ -156,7 +196,7 @@ export default function ColleDetailPage() {
- + */} + {syllabusLink && ( + + )}