Skip to content
This repository was archived by the owner on Aug 2, 2025. It is now read-only.

Commit ae6e007

Browse files
committed
fix: show correct week
1 parent 46b9654 commit ae6e007

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

apps/client/src/routes/Main/Home/DaySelect.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import DatePicker from "../../../components/DatePicker";
1111
import { useRef } from "react";
1212
import { DateTime } from "luxon";
1313
import { useDtt } from "../../../services/sbhsApi/useDtt";
14+
import { useDay } from "../../../services/sbhsApi/useDay";
1415

1516
export default function DaySelect({
1617
selected,
@@ -20,7 +21,9 @@ export default function DaySelect({
2021
setSelected: (date: Date) => void;
2122
}) {
2223
const initRef = useRef<HTMLButtonElement>(null);
24+
const date = selected ? DateTime.fromJSDate(selected).toISODate() : undefined;
2325
const { data: dtt } = useDtt();
26+
const { data: day } = useDay(date, date);
2427

2528
return (
2629
<Popover closeOnBlur={false} initialFocusRef={initRef}>
@@ -51,7 +54,9 @@ export default function DaySelect({
5154
year: "numeric",
5255
month: "numeric",
5356
day: "numeric",
54-
})} Wk 7`
57+
})} Wk ${
58+
date ? `${day?.[date]?.week}${day?.[date]?.weekType}` : ""
59+
}`
5560
: "Select date"}
5661
</Button>
5762
</PopoverTrigger>

apps/client/src/services/sbhsApi/schemas.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,3 +290,13 @@ export const sbhsKey =
290290
(endpoint: SbhsApiEndpoint) =>
291291
<T extends Record<string, string>>(options?: T) =>
292292
[`/sbhs/${endpoint}`, options] as const;
293+
294+
export const daySchema = z.record(
295+
z.object({
296+
date: z.coerce.string(),
297+
term: z.coerce.string(),
298+
week: z.coerce.string(),
299+
weekType: z.coerce.string(),
300+
dayNumber: z.coerce.string(),
301+
})
302+
);
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { useQuery } from "@tanstack/react-query";
2+
import { authActions } from "../../stores/auth";
3+
import { daySchema, sbhsKey } from "./schemas";
4+
5+
const queryFn = async (from?: string, to?: string) => {
6+
return daySchema.parse(
7+
await authActions.fetchAuthenticated(
8+
"calendar/days.json",
9+
from && to
10+
? {
11+
from,
12+
to,
13+
}
14+
: undefined
15+
)
16+
);
17+
};
18+
19+
const getQueryKey = sbhsKey("calendar/days.json");
20+
21+
export const useDay = (from?: string, to?: string) => {
22+
return useQuery({
23+
queryKey: getQueryKey(
24+
from && to
25+
? {
26+
from,
27+
to,
28+
}
29+
: undefined
30+
),
31+
queryFn: () => queryFn(from, to),
32+
enabled: !!from && !!to,
33+
});
34+
};
35+
36+
useDay.getQueryKey = getQueryKey;
37+
useDay.queryFn = queryFn;

0 commit comments

Comments
 (0)