Skip to content

Commit 19fa675

Browse files
committed
loading ring for scores table
1 parent 221eb0e commit 19fa675

File tree

3 files changed

+31
-43
lines changed

3 files changed

+31
-43
lines changed

src/app/judging/JudgingTable.tsx

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use client";
22

33
import { useState } from "react";
4-
import Skeleton from "react-loading-skeleton";
54

65
import type { Schema } from "@/amplify/data/resource";
76
import LoadingRing from "@/components/LoadingRing";
@@ -51,15 +50,16 @@ export default function JudgingTable({
5150
return teams;
5251
},
5352
});
54-
const isFetching = roomIsFetching || teamsForRoomIsFetching;
53+
const isFetching = roomIsFetching && teamsForRoomIsFetching;
5554
if (isFetching || !roomData || !teamsForRoomData) {
5655
return (
57-
<div className="flex flex-1">
58-
<Skeleton className="h-full" containerClassName="flex-1" />
56+
<div>
57+
<LoadingRing />
5958
</div>
6059
);
6160
}
6261
async function getFilteredTeamsCount() {
62+
// https://medium.com/@debbs119/array-filter-and-array-map-with-async-functions-9636e1ae8d6e --> why it need to map to a boolean array first
6363
if (!teamsForRoomData) {
6464
return;
6565
}
@@ -72,21 +72,12 @@ export default function JudgingTable({
7272
);
7373
}),
7474
);
75-
76-
return teamsForRoomData?.filter((_, index) => boolArray[index]).length;
77-
}
78-
79-
if (!teamsForRoomData) return;
80-
81-
async function updateTeamsLeft() {
82-
const filteredCount = await getFilteredTeamsCount();
83-
if (!filteredCount) {
84-
return;
85-
}
86-
setTeamsLeft(filteredCount);
75+
setTeamsLeft(
76+
teamsForRoomData?.filter((_, index) => boolArray[index]).length,
77+
);
8778
}
8879

89-
updateTeamsLeft();
80+
getFilteredTeamsCount();
9081

9182
const panelData = [
9283
{
@@ -115,32 +106,26 @@ export default function JudgingTable({
115106

116107
return (
117108
<>
118-
{isFetching ? (
119-
<div className="flex h-screen w-full items-center justify-center">
120-
<LoadingRing />
121-
</div>
122-
) : (
123-
<div className="flex w-full flex-col justify-center gap-4 py-6 xl:flex-row">
124-
<div className=" flex w-full flex-row gap-4 xl:w-1/4 xl:flex-col">
125-
{panelData.map((item, index) => (
126-
<StatsPanel
127-
key={index}
128-
icon={item.icon}
129-
alt={item.alt}
130-
stat={item.stat}
131-
subheader={item.text}
132-
/>
133-
))}
134-
</div>
135-
<ScoresTable
136-
tableData={teamsForRoomData as Schema["Team"]["type"][]}
137-
onCreateScoreClick={handleCreateScoreClick}
138-
colorScheme="pink"
139-
entriesPerPage={150}
140-
hackathonData={hackathonData}
141-
/>
109+
<div className="flex w-full flex-col justify-center gap-4 py-6 xl:flex-row">
110+
<div className=" flex w-full flex-row gap-4 xl:w-1/4 xl:flex-col">
111+
{panelData.map((item, index) => (
112+
<StatsPanel
113+
key={index}
114+
icon={item.icon}
115+
alt={item.alt}
116+
stat={item.stat}
117+
subheader={item.text}
118+
/>
119+
))}
142120
</div>
143-
)}
121+
<ScoresTable
122+
tableData={teamsForRoomData as Schema["Team"]["type"][]}
123+
onCreateScoreClick={handleCreateScoreClick}
124+
colorScheme="pink"
125+
entriesPerPage={150}
126+
hackathonData={hackathonData}
127+
/>
128+
</div>
144129

145130
{selectedTeam !== "" && (
146131
<ModalPopup

src/components/Dashboard/Greetings.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import { twMerge } from "tailwind-merge";
44

5+
import LoadingRing from "@/components/LoadingRing";
6+
57
import { UserType, useUser } from "../contexts/UserContext";
68
import Card from "./Card";
79

@@ -32,8 +34,10 @@ export default function Greetings({
3234
<h2 className="text-lg font-normal md:text-xl lg:text-2xl">
3335
Hack the Change 2024
3436
</h2>
37+
3538
<h1 className="text-3xl md:text-4xl lg:text-6xl">
3639
Hello,
40+
{user.isFetching && <LoadingRing />}
3741
<span className={`capitalize italic ${nameColor}`}>
3842
{" "}
3943
{firstName} {lastName}!

src/components/judging/ScoresTable.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { type Schema } from "@/amplify/data/resource";
99
import { useQuery } from "@tanstack/react-query";
1010

1111
import Card from "../Dashboard/Card";
12-
// import LoadingRing from "../LoadingRing";
1312
import { useUser } from "../contexts/UserContext";
1413
import { type ScoreObject } from "./ModalPopup";
1514

0 commit comments

Comments
 (0)