@@ -61,7 +61,7 @@ export default function JudgingSchedule() {
61
61
} ,
62
62
} ) ;
63
63
64
- const { data : roomData } = useQuery ( {
64
+ const { data : roomData , isLoading : isLoadingRooms } = useQuery ( {
65
65
queryKey : [ "Room" ] ,
66
66
queryFn : async ( ) => {
67
67
const { data, errors } = await client . models . Room . list ( ) ;
@@ -72,7 +72,7 @@ export default function JudgingSchedule() {
72
72
} ,
73
73
} ) ;
74
74
75
- const { data : teamRoomData } = useQuery ( {
75
+ const { data : teamRoomData , isLoading : isLoadingTeamRooms } = useQuery ( {
76
76
queryKey : [ "TeamRoom" ] ,
77
77
queryFn : async ( ) => {
78
78
const { data, errors } = await client . models . TeamRoom . list ( ) ;
@@ -83,7 +83,7 @@ export default function JudgingSchedule() {
83
83
} ,
84
84
} ) ;
85
85
86
- const { data : judgeData } = useQuery ( {
86
+ const { data : judgeData , isLoading : isLoadingJudges } = useQuery ( {
87
87
queryKey : [ "User-Judge" ] ,
88
88
queryFn : async ( ) => {
89
89
const { data, errors } = await client . models . User . list ( {
@@ -101,7 +101,7 @@ export default function JudgingSchedule() {
101
101
} ,
102
102
} ) ;
103
103
104
- const { data : teamData } = useQuery ( {
104
+ const { data : teamData , isLoading : isLoadingTeams } = useQuery ( {
105
105
queryKey : [ "Teams" ] ,
106
106
107
107
queryFn : async ( ) => {
@@ -115,35 +115,46 @@ export default function JudgingSchedule() {
115
115
} ,
116
116
} ) ;
117
117
118
- const judgeRooms = roomData
119
- ?. map ( ( room ) => ( {
120
- roomName : room . name ,
121
- room_id : room . id ,
122
- judgeNames :
123
- judgeData
124
- ?. filter ( ( judge ) => judge . JUDGE_roomId === room . id )
125
- . map ( ( judge ) => judge . firstName )
126
- . join ( " & " ) || "" ,
127
- color : "#D6C9FF" ,
128
- } ) )
129
- . sort ( ( a , b ) =>
130
- a . roomName > b . roomName ? 1 : b . roomName > a . roomName ? - 1 : 0 ,
131
- ) ;
118
+ const isLoading =
119
+ isLoadingRooms || isLoadingJudges || isLoadingTeamRooms || isLoadingTeams ;
132
120
133
- const judgingEvents = teamRoomData ?. map ( ( teamRoom ) => ( {
134
- event_id : teamRoom . id ,
135
- title :
136
- teamData
137
- ?. filter ( ( team ) => team . id === teamRoom . teamId )
138
- . map ( ( team ) => team . name )
139
- . join ( ", " ) || "No Team Name" ,
140
- room_id : teamRoom . roomId , // for some reason wont render if camelcase lol
141
- start : new Date ( teamRoom . time ) ,
142
- end : new Date ( new Date ( teamRoom . time ) . getTime ( ) + 15 * 60 * 1000 ) ,
143
- zoomLink : teamRoom . zoomLink ,
144
- } ) ) ;
121
+ const judgeRooms =
122
+ roomData && judgeData //make sure contents of roomData and judgeData are rendered first
123
+ ? roomData
124
+ . map ( ( room ) => ( {
125
+ roomName : room . name ,
126
+ room_id : room . id ,
127
+ judgeNames :
128
+ judgeData
129
+ ?. filter ( ( judge ) => judge . JUDGE_roomId === room . id )
130
+ . map ( ( judge ) => judge . firstName )
131
+ . join ( " & " ) || "No Names" ,
132
+ color : "#D6C9FF" ,
133
+ } ) )
134
+ . sort ( ( a , b ) =>
135
+ a . roomName > b . roomName ? 1 : b . roomName > a . roomName ? - 1 : 0 ,
136
+ )
137
+ : [ ] ;
145
138
146
- return (
139
+ const judgingEvents =
140
+ teamRoomData && teamData //make sure conteents of teamRoomData and teamData are mapped first
141
+ ? teamRoomData . map ( ( teamRoom ) => ( {
142
+ event_id : teamRoom . id ,
143
+ title :
144
+ teamData
145
+ ?. filter ( ( team ) => team . id === teamRoom . teamId )
146
+ . map ( ( team ) => team . name )
147
+ . join ( ", " ) || "No Team Name" ,
148
+ room_id : teamRoom . roomId ,
149
+ start : new Date ( teamRoom . time ) ,
150
+ end : new Date ( new Date ( teamRoom . time ) . getTime ( ) + 15 * 60 * 1000 ) ,
151
+ zoomLink : teamRoom . zoomLink ,
152
+ } ) )
153
+ : [ ] ;
154
+
155
+ return isLoading ? (
156
+ < div > Loading schedule...</ div > //JudgeTimeline component is only mapped if all isLoading flags are false
157
+ ) : (
147
158
< >
148
159
< RoomAssigner judgingScheduleMutation = { mutate } />
149
160
< div className = "flex justify-center" >
0 commit comments