This repository was archived by the owner on Aug 2, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +53
-1
lines changed
Expand file tree Collapse file tree 3 files changed +53
-1
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import DatePicker from "../../../components/DatePicker";
1111import { useRef } from "react" ;
1212import { DateTime } from "luxon" ;
1313import { useDtt } from "../../../services/sbhsApi/useDtt" ;
14+ import { useDay } from "../../../services/sbhsApi/useDay" ;
1415
1516export 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 >
Original file line number Diff line number Diff 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+ ) ;
Original file line number Diff line number Diff line change 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 ;
You can’t perform that action at this time.
0 commit comments