Skip to content

Commit

Permalink
added exception dates to calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienR1 committed Mar 2, 2025
1 parent 27fae14 commit 64b0f5e
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
27 changes: 16 additions & 11 deletions packages/common/src/models/activities.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { z } from "zod";

export const Time = z.object({ hour: z.number(), minute: z.number() })
export const Time = z.object({ hour: z.number(), minute: z.number() });

export const Activity = z.object({
type: z.number(),
title: z.string(),
subtitle: z.string().optional(),
time: z.object({ start: Time, end: Time }),
lessons: z.object({ count: z.number(), first: z.date(), last: z.date() }),
price: z.number(),
color: z.string()
})
type: z.number(),
title: z.string(),
subtitle: z.string().optional(),
time: z.object({ start: Time, end: Time }),
lessons: z.object({
count: z.number(),
first: z.date(),
last: z.date(),
exceptions: z.array(z.date()),
}),
price: z.number(),
color: z.string(),
});

export type Time = z.infer<typeof Time>
export type Activity = z.infer<typeof Activity>
export type Time = z.infer<typeof Time>;
export type Activity = z.infer<typeof Activity>;
31 changes: 30 additions & 1 deletion packages/web/src/components/Calendar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { Activity, Time } from "common";
import { gcd } from "../lib/maths";
import { cn, dark, contrast } from "../lib/utils";
import { dateFormatter } from "../lib/formatters";
import { dateFormatter, listFormatter } from "../lib/formatters";
import { weekdays } from "../lib/constants";
interface Props {
Expand Down Expand Up @@ -209,6 +209,14 @@ function shiftWeekday(weekday: number) {
data-amount={activity.price.toFixed(2)}
data-lessons={activity.lessons.count}
data-weekday={weekdays[weekday]}
data-except-dates={listFormatter.format(
activity.lessons.exceptions
.sort((a, b) => a.getTime() - b.getTime())
.map(
(date) =>
`<b class="text-nowrap">${dateFormatter.format(date)}</b>`,
),
)}
>
<span class="hidden sm:block text-xs whitespace-nowrap overflow-hidden">
{formatTime(activity.time.start)} -{" "}
Expand Down Expand Up @@ -303,6 +311,19 @@ function shiftWeekday(weekday: number) {
<span class="material-symbols-outlined">sell</span>
<span id="dialog-price"></span>
</p>
<p
id="dialog-except-dates"
class="items-center text-sm gap-2 hidden data-[visible=true]:flex"
data-visible="false"
>
<span class="material-symbols-outlined">
do_not_disturb_on
</span>
<span class="sm:max-w-56 ml-2 -indent-2">
Hormis ces dates:
<span id="dialog-except-dates-list"></span>{"."}
</span>
</p>
</div>
</div>
</div>
Expand All @@ -321,6 +342,10 @@ function shiftWeekday(weekday: number) {
const time = document.getElementById("dialog-time")!;
const dateRange = document.getElementById("dialog-date-range")!;
const price = document.getElementById("dialog-price")!;
const exceptDates = document.getElementById("dialog-except-dates")!;
const exceptDatesList = document.getElementById(
"dialog-except-dates-list",
)!;

const calendar = document.getElementById("calendar")!;
const activities = calendar.querySelectorAll<HTMLDivElement>(".activity");
Expand All @@ -343,6 +368,10 @@ function shiftWeekday(weekday: number) {
time.innerText = `${dataset.weekday}, de ${dataset.startTime} à ${dataset.endTime}`;
dateRange.innerText = `${dataset.firstLesson} au ${dataset.lastLesson}`;
price.innerText = `${dataset.amount}$ pour ${dataset.lessons} cours`;

const exceptions = dataset.exceptDates ?? "";
exceptDates.dataset.visible = (exceptions.length > 0).toString();
exceptDatesList.innerHTML = exceptions;
}

function position(activity: HTMLDivElement, xOffset = 0) {
Expand Down
2 changes: 2 additions & 0 deletions packages/web/src/lib/formatters.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const dateFormatter = new Intl.DateTimeFormat("fr-CA", {
dateStyle: "long",
});

export const listFormatter = new Intl.ListFormat("fr-CA");
11 changes: 11 additions & 0 deletions packages/web/src/pages/horaire.astro
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const activities: Activity[][] = [
count: 8,
first: new Date(2025, 1, 6),
last: new Date(2025, 5, 5),
exceptions: [],
},
price: 120,
color: "#ff00ff",
Expand All @@ -34,6 +35,7 @@ const activities: Activity[][] = [
count: 8,
first: new Date(2025, 1, 6),
last: new Date(2025, 5, 5),
exceptions: [],
},
price: 120,
color: "#0ff0ff",
Expand All @@ -49,6 +51,7 @@ const activities: Activity[][] = [
count: 8,
first: new Date(2025, 1, 6),
last: new Date(2025, 5, 5),
exceptions: [],
},
price: 120,
color: "#f0f0ff",
Expand All @@ -67,6 +70,7 @@ const activities: Activity[][] = [
count: 2,
first: new Date(2025, 2, 2),
last: new Date(2025, 3, 4),
exceptions: [],
},
price: 28,
color: "#12fa83",
Expand All @@ -83,6 +87,7 @@ const activities: Activity[][] = [
count: 2,
first: new Date(2025, 2, 2),
last: new Date(2025, 3, 4),
exceptions: [],
},
price: 28,
color: "#fa1283",
Expand All @@ -100,6 +105,7 @@ const activities: Activity[][] = [
count: 8,
first: new Date(2025, 1, 6),
last: new Date(2025, 5, 5),
exceptions: [],
},
price: 120,
color: "#0f0f00",
Expand All @@ -115,6 +121,7 @@ const activities: Activity[][] = [
count: 8,
first: new Date(2025, 1, 6),
last: new Date(2025, 5, 5),
exceptions: [],
},
price: 120,
color: "#f0f000",
Expand All @@ -130,6 +137,7 @@ const activities: Activity[][] = [
count: 8,
first: new Date(2025, 1, 6),
last: new Date(2025, 5, 5),
exceptions: [],
},
price: 120,
color: "#0fff30",
Expand All @@ -145,6 +153,7 @@ const activities: Activity[][] = [
count: 8,
first: new Date(2025, 1, 6),
last: new Date(2025, 5, 5),
exceptions: [],
},
price: 120,
color: "#ffff00",
Expand All @@ -164,6 +173,7 @@ const activities: Activity[][] = [
count: 8,
first: new Date(2025, 1, 6),
last: new Date(2025, 5, 5),
exceptions: [new Date(2025, 7, 1), new Date(2025, 6, 24)],
},
price: 120,
color: "#ff0000",
Expand All @@ -179,6 +189,7 @@ const activities: Activity[][] = [
count: 8,
first: new Date(2025, 1, 6),
last: new Date(2025, 5, 5),
exceptions: [],
},
price: 120,
color: "#0ff000",
Expand Down

0 comments on commit 64b0f5e

Please sign in to comment.