Skip to content

Commit 91f6c4d

Browse files
authored
fixed the problem (#183)
1 parent 4d20234 commit 91f6c4d

File tree

1 file changed

+42
-31
lines changed

1 file changed

+42
-31
lines changed

src/components/admin/Judging/JudgingSchedule.tsx

+42-31
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export default function JudgingSchedule() {
6161
},
6262
});
6363

64-
const { data: roomData } = useQuery({
64+
const { data: roomData, isLoading: isLoadingRooms } = useQuery({
6565
queryKey: ["Room"],
6666
queryFn: async () => {
6767
const { data, errors } = await client.models.Room.list();
@@ -72,7 +72,7 @@ export default function JudgingSchedule() {
7272
},
7373
});
7474

75-
const { data: teamRoomData } = useQuery({
75+
const { data: teamRoomData, isLoading: isLoadingTeamRooms } = useQuery({
7676
queryKey: ["TeamRoom"],
7777
queryFn: async () => {
7878
const { data, errors } = await client.models.TeamRoom.list();
@@ -83,7 +83,7 @@ export default function JudgingSchedule() {
8383
},
8484
});
8585

86-
const { data: judgeData } = useQuery({
86+
const { data: judgeData, isLoading: isLoadingJudges } = useQuery({
8787
queryKey: ["User-Judge"],
8888
queryFn: async () => {
8989
const { data, errors } = await client.models.User.list({
@@ -101,7 +101,7 @@ export default function JudgingSchedule() {
101101
},
102102
});
103103

104-
const { data: teamData } = useQuery({
104+
const { data: teamData, isLoading: isLoadingTeams } = useQuery({
105105
queryKey: ["Teams"],
106106

107107
queryFn: async () => {
@@ -115,35 +115,46 @@ export default function JudgingSchedule() {
115115
},
116116
});
117117

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;
132120

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+
: [];
145138

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+
) : (
147158
<>
148159
<RoomAssigner judgingScheduleMutation={mutate} />
149160
<div className="flex justify-center">

0 commit comments

Comments
 (0)