Skip to content

Commit b0cf292

Browse files
fisayoadabsfionaa-truongburtonjongskand088anthonyych4n
authored
Updating prod for infinite scheduler load (#258)
Co-authored-by: Fiona Truong <151110138+fionaa-truong@users.noreply.github.com> Co-authored-by: burtonjong <burtonjong05@gmail.com> Co-authored-by: Burton Jong <108391733+burtonjong@users.noreply.github.com> Co-authored-by: simar kandola <simarkandola51@gmail.com> Co-authored-by: Anthony <88424536+anthonyych4n@users.noreply.github.com>
1 parent d984e7f commit b0cf292

File tree

2 files changed

+97
-34
lines changed

2 files changed

+97
-34
lines changed

src/app/judging/JudgingTable.tsx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ export default function JudgingTable({
2020
}) {
2121
const [selectedTeam, setSelectedTeamId] = useState("");
2222
const [teamName, setTeamName] = useState("");
23-
const [teamsLeft, setTeamsLeft] = useState(0);
2423

2524
const { currentUser } = useUser();
2625
const { data: roomData, isFetching: roomIsFetching } = useQuery({
@@ -51,30 +50,31 @@ export default function JudgingTable({
5150
return teams;
5251
},
5352
});
54-
const isFetching = roomIsFetching && teamsForRoomIsFetching;
53+
54+
const { data: teamsLeft = 0, isFetching: teamsLeftIsFetching } = useQuery({
55+
queryKey: ["TeamsLeftCount", teamsForRoomData, currentUser.username],
56+
queryFn: async () => {
57+
if (!teamsForRoomData) return 0;
58+
const boolArray = await Promise.all(
59+
teamsForRoomData.map(async (team) => {
60+
const scores = await team?.scores();
61+
return (
62+
scores?.data.filter(
63+
(score) => score.judgeId === currentUser.username,
64+
).length === 0
65+
);
66+
}),
67+
);
68+
return teamsForRoomData.filter((_, i) => boolArray[i]).length;
69+
},
70+
enabled: !!teamsForRoomData && !!currentUser.username,
71+
});
72+
73+
const isFetching =
74+
roomIsFetching || teamsForRoomIsFetching || teamsLeftIsFetching;
5575
if (isFetching || !roomData || !teamsForRoomData) {
5676
return <KevinLoadingRing />;
5777
}
58-
async function getFilteredTeamsCount() {
59-
// https://medium.com/@debbs119/array-filter-and-array-map-with-async-functions-9636e1ae8d6e --> why it needs to map to a boolean array first
60-
if (!teamsForRoomData) {
61-
return;
62-
}
63-
const boolArray = await Promise.all(
64-
teamsForRoomData?.map(async (team) => {
65-
const scores = await team?.scores();
66-
return (
67-
scores?.data.filter((score) => score.judgeId === currentUser.username)
68-
.length === 0
69-
);
70-
}),
71-
);
72-
setTeamsLeft(
73-
teamsForRoomData?.filter((_, index) => boolArray[index]).length,
74-
);
75-
}
76-
77-
getFilteredTeamsCount();
7878

7979
const panelData = [
8080
{

src/app/judging/assigned-teams/page.tsx

Lines changed: 75 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,81 @@
1+
"use client";
2+
3+
import React from "react";
4+
import { client } from "@/app/QueryProvider";
5+
import { useUser } from "@/components/contexts/UserContext";
6+
import KevinLoadingRing from "@/components/KevinLoadingRing";
7+
import { useQuery } from "@tanstack/react-query";
8+
19
const AssignedTeamsPage = () => {
2-
const assignedTeams = [
3-
{ id: 1, name: "Team Alpha" },
4-
{ id: 2, name: "Team Beta" },
5-
{ id: 3, name: "Team Gamma" },
6-
];
10+
const { currentUser } = useUser();
11+
12+
const { data: roomData, isLoading: roomLoading } = useQuery({
13+
queryKey: ["RoomForJudge", currentUser?.JUDGE_roomId],
14+
queryFn: async () => {
15+
if (!currentUser?.JUDGE_roomId)
16+
throw new Error("No room assigned to judge");
17+
const { data, errors } = await client.models.Room.get({
18+
id: currentUser.JUDGE_roomId,
19+
});
20+
if (errors) throw new Error(errors[0]?.message || "Failed to load room");
21+
return data;
22+
},
23+
enabled: !!currentUser?.JUDGE_roomId,
24+
});
25+
26+
const { data: teamsForRoom, isLoading: teamsLoading } = useQuery({
27+
queryKey: ["TeamsForRoom", roomData?.id],
28+
queryFn: async () => {
29+
if (!roomData) return [];
30+
const teamRooms = (await roomData.teamRoom())?.data;
31+
if (!teamRooms) return [];
32+
const teams = await Promise.all(
33+
teamRooms.map(async (tr) => (await tr.team()).data),
34+
);
35+
return teams;
36+
},
37+
enabled: !!roomData,
38+
});
39+
40+
if (!currentUser)
41+
return <div className="p-6">Please sign in to see assigned teams.</div>;
42+
if (roomLoading || teamsLoading)
43+
return (
44+
<div className="flex items-center justify-center pt-16">
45+
<KevinLoadingRing />
46+
</div>
47+
);
48+
if (!roomData)
49+
return <div className="p-6">You have no room assigned yet.</div>;
750

851
return (
9-
<div>
10-
<h1> Put assinged teams here Assigned Teams</h1>
11-
<ul>
12-
{assignedTeams.map((team) => (
13-
<li key={team.id}>{team.name}</li>
14-
))}
15-
</ul>
52+
<div className="p-6">
53+
<h1 className="mb-4 text-2xl font-semibold">
54+
Your Teams: {roomData?.name ?? ""}
55+
</h1>
56+
{teamsForRoom && teamsForRoom.length > 0 ? (
57+
<div className="grid w-full grid-cols-1 gap-6 sm:grid-cols-2 lg:grid-cols-3">
58+
{teamsForRoom.map((team: any) => (
59+
<div
60+
key={team.id}
61+
className="flex flex-col justify-between rounded-lg border bg-white p-4 shadow-sm transition-shadow hover:shadow-lg"
62+
>
63+
<div>
64+
<div className="text-lg font-bold text-gray-900">
65+
<span>{team.name}</span>
66+
</div>
67+
<div className="mt-1 text-sm text-gray-500">
68+
<span>Team ID: {team.id}</span>
69+
</div>
70+
</div>
71+
</div>
72+
))}
73+
</div>
74+
) : (
75+
<div className="text-gray-600">
76+
No teams assigned to your room yet. Check back later!
77+
</div>
78+
)}
1679
</div>
1780
);
1881
};

0 commit comments

Comments
 (0)