@@ -11,8 +11,15 @@ import {
1111} from "@chakra-ui/react" ;
1212import { useTimetable } from "../../../services/sbhsApi/useTimetable" ;
1313import { TimetableDay } from "../../../services/sbhsApi/schemas" ;
14+ import { useState } from "react" ;
15+
16+ function Period ( props : {
17+ period : TimetableDay [ "periods" ] [ number ] ;
18+ setActiveSubject : ( subject : string | null ) => void ;
19+ activeSubject : string | null ;
20+ } ) {
21+ const isActive = props . activeSubject === props . period . title ;
1422
15- function Period ( props : TimetableDay [ "periods" ] [ number ] ) {
1623 return (
1724 < Flex
1825 direction = { [ "column" , "column" , "row" ] }
@@ -21,26 +28,38 @@ function Period(props: TimetableDay["periods"][number]) {
2128 gap = { 1 }
2229 align = "center"
2330 fontFamily = { "Poppins, sans-serif" }
31+ onClick = { ( ) =>
32+ props . setActiveSubject ( isActive ? null : props . period . title )
33+ }
34+ shadow = { isActive ? "outline" : undefined }
2435 >
2536 < Text
2637 fontSize = { "sm" }
27- bg = { props . room ? "primary.500" : undefined }
38+ bg = {
39+ props . period . room && ( isActive || props . activeSubject === null )
40+ ? "primary.500"
41+ : undefined
42+ }
2843 p = { 2 }
2944 rounded = "lg"
3045 minW = { [ "full" , "full" , "5ch" ] }
3146 textAlign = "center"
3247 >
33- { props . title . split ( " " ) [ 0 ] }
48+ { props . period . title . split ( " " ) [ 0 ] }
3449 </ Text >
3550 < Spacer />
3651 < Text fontSize = { "sm" } fontWeight = { "bold" } pr = { [ 0 , 0 , 2 ] } >
37- { props . room }
52+ { props . period . room }
3853 </ Text >
3954 </ Flex >
4055 ) ;
4156}
4257
43- function Day ( props : TimetableDay ) {
58+ function Day ( props : {
59+ day : TimetableDay ;
60+ setActiveSubject : ( subject : string | null ) => void ;
61+ activeSubject : string | null ;
62+ } ) {
4463 return (
4564 < Flex direction = { "column" } gap = { 1 } >
4665 < Text
@@ -49,17 +68,23 @@ function Day(props: TimetableDay) {
4968 alignSelf = "center"
5069 fontSize = { "sm" }
5170 >
52- { props . dayname }
71+ { props . day . dayname }
5372 </ Text >
54- { Object . values ( props . periods ) . map ( ( period , index ) => (
55- < Period key = { index } { ...period } />
73+ { Object . values ( props . day . periods ) . map ( ( period , index ) => (
74+ < Period
75+ key = { index }
76+ period = { period }
77+ setActiveSubject = { props . setActiveSubject }
78+ activeSubject = { props . activeSubject }
79+ />
5680 ) ) }
5781 </ Flex >
5882 ) ;
5983}
6084
6185export default function CycleTimetable ( ) {
6286 const { data } = useTimetable ( ) ;
87+ const [ activeSubject , setActiveSubject ] = useState < string | null > ( null ) ;
6388
6489 if ( ! data ) {
6590 return (
@@ -78,7 +103,11 @@ export default function CycleTimetable() {
78103 >
79104 { data ?. map ( ( day , index ) => (
80105 < GridItem w = "100%" key = { index } >
81- < Day { ...day } />
106+ < Day
107+ day = { day }
108+ setActiveSubject = { setActiveSubject }
109+ activeSubject = { activeSubject }
110+ />
82111 </ GridItem >
83112 ) ) }
84113 </ Grid >
0 commit comments