1
1
"use client" ;
2
2
3
3
import { useState } from "react" ;
4
- import Skeleton from "react-loading-skeleton" ;
5
4
6
5
import type { Schema } from "@/amplify/data/resource" ;
7
6
import LoadingRing from "@/components/LoadingRing" ;
@@ -51,15 +50,16 @@ export default function JudgingTable({
51
50
return teams ;
52
51
} ,
53
52
} ) ;
54
- const isFetching = roomIsFetching || teamsForRoomIsFetching ;
53
+ const isFetching = roomIsFetching && teamsForRoomIsFetching ;
55
54
if ( isFetching || ! roomData || ! teamsForRoomData ) {
56
55
return (
57
- < div className = "flex flex-1" >
58
- < Skeleton className = "h-full" containerClassName = "flex-1" />
56
+ < div >
57
+ < LoadingRing />
59
58
</ div >
60
59
) ;
61
60
}
62
61
async function getFilteredTeamsCount ( ) {
62
+ // https://medium.com/@debbs 119/array-filter-and-array-map-with-async-functions-9636e1ae8d6e --> why it need to map to a boolean array first
63
63
if ( ! teamsForRoomData ) {
64
64
return ;
65
65
}
@@ -72,21 +72,12 @@ export default function JudgingTable({
72
72
) ;
73
73
} ) ,
74
74
) ;
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
+ ) ;
87
78
}
88
79
89
- updateTeamsLeft ( ) ;
80
+ getFilteredTeamsCount ( ) ;
90
81
91
82
const panelData = [
92
83
{
@@ -115,32 +106,26 @@ export default function JudgingTable({
115
106
116
107
return (
117
108
< >
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
+ ) ) }
142
120
</ 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 >
144
129
145
130
{ selectedTeam !== "" && (
146
131
< ModalPopup
0 commit comments