feat: add syllabus
All checks were successful
Deploy to Netlify / Deploy to Netlify (push) Successful in 1m17s
All checks were successful
Deploy to Netlify / Deploy to Netlify (push) Successful in 1m17s
This commit is contained in:
parent
5e65243598
commit
4aebc41e2b
2 changed files with 99 additions and 3 deletions
|
|
@ -152,3 +152,48 @@ export const getSubjectColor = (subject: string, pref: UserPreferences) => {
|
||||||
|
|
||||||
// === DEBUG UTILS ===
|
// === DEBUG UTILS ===
|
||||||
export const clearCache = () => del(CACHE_KEY);
|
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;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,18 +20,26 @@ import {
|
||||||
Share2,
|
Share2,
|
||||||
ExternalLink,
|
ExternalLink,
|
||||||
Users,
|
Users,
|
||||||
|
Album,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import { Separator } from "~/components/ui/separator";
|
import { Separator } from "~/components/ui/separator";
|
||||||
import ColleDetailsSkeleton from "~/components/details/skeleton-details";
|
import ColleDetailsSkeleton from "~/components/details/skeleton-details";
|
||||||
import AttachmentItem from "~/components/details/attachment";
|
import AttachmentItem from "~/components/details/attachment";
|
||||||
import Error from "~/components/error";
|
import Error from "~/components/error";
|
||||||
import { Badge } from "~/components/ui/badge";
|
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 { toast } from "sonner";
|
||||||
import {
|
import {
|
||||||
formatDate,
|
formatDate,
|
||||||
formatGrade,
|
formatGrade,
|
||||||
formatTime,
|
formatTime,
|
||||||
|
getColleWeek,
|
||||||
getColorClass,
|
getColorClass,
|
||||||
getSubjectColor,
|
getSubjectColor,
|
||||||
getSubjectEmoji,
|
getSubjectEmoji,
|
||||||
|
|
@ -81,6 +89,37 @@ export default function ColleDetailPage() {
|
||||||
|
|
||||||
const handleToggleFavorite = () => {};
|
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 = () => {
|
const handleReload = () => {
|
||||||
setIsReloading(true);
|
setIsReloading(true);
|
||||||
refreshColle(colle.id)
|
refreshColle(colle.id)
|
||||||
|
|
@ -146,6 +185,7 @@ export default function ColleDetailPage() {
|
||||||
getSubjectColor(colle.subject.name, user.preferences)
|
getSubjectColor(colle.subject.name, user.preferences)
|
||||||
);
|
);
|
||||||
const subjectEmoji = getSubjectEmoji(colle.subject.name, user.preferences);
|
const subjectEmoji = getSubjectEmoji(colle.subject.name, user.preferences);
|
||||||
|
const syllabusLink = getColleSyllabus(colle);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="container mx-auto py-6 px-4 pb-20 md:pb-6 md:py-8">
|
<div className="container mx-auto py-6 px-4 pb-20 md:pb-6 md:py-8">
|
||||||
|
|
@ -156,7 +196,7 @@ export default function ColleDetailPage() {
|
||||||
</Button>
|
</Button>
|
||||||
<div className="flex md:hidden items-center gap-2">
|
<div className="flex md:hidden items-center gap-2">
|
||||||
<div className="space-x-2">
|
<div className="space-x-2">
|
||||||
<Button
|
{/* <Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon"
|
size="icon"
|
||||||
className="h-10 w-10"
|
className="h-10 w-10"
|
||||||
|
|
@ -167,7 +207,18 @@ export default function ColleDetailPage() {
|
||||||
className={`h-5 w-5 ${isReloading ? "animate-spin" : ""}`}
|
className={`h-5 w-5 ${isReloading ? "animate-spin" : ""}`}
|
||||||
/>
|
/>
|
||||||
<span className="sr-only">Recharger</span>
|
<span className="sr-only">Recharger</span>
|
||||||
</Button>
|
</Button> */}
|
||||||
|
{syllabusLink && (
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
className="h-10 w-10"
|
||||||
|
onClick={() => window.open(syllabusLink, "_blank")}
|
||||||
|
>
|
||||||
|
<Album className={"h-5 w-5"} />
|
||||||
|
<span className="sr-only">Programme de colle</span>
|
||||||
|
</Button>
|
||||||
|
)}
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
size="icon"
|
size="icon"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue