11"use client" ;
22
3- import { graphql , useFragment , type FragmentType } from "@/gql" ;
3+ import DataTablePagination from "@/components/data-table/pagination" ;
4+ import { Badge } from "@/components/ui/badge" ;
5+ import { Card , CardContent , CardHeader , CardTitle } from "@/components/ui/card" ;
6+ import { Select , SelectContent , SelectItem , SelectTrigger , SelectValue } from "@/components/ui/select" ;
7+ import { Table , TableBody , TableCell , TableHead , TableHeader , TableRow } from "@/components/ui/table" ;
8+ import { type FragmentType , graphql , useFragment } from "@/gql" ;
49import { RankingBy , RankingOrder , RankingPeriod } from "@/gql/graphql" ;
510import { useSuspenseQuery } from "@apollo/client/react" ;
611import { useState } from "react" ;
7- import { Card , CardContent , CardHeader , CardTitle } from "@/components/ui/card" ;
8- import {
9- Select ,
10- SelectContent ,
11- SelectItem ,
12- SelectTrigger ,
13- SelectValue ,
14- } from "@/components/ui/select" ;
15- import {
16- Table ,
17- TableBody ,
18- TableCell ,
19- TableHead ,
20- TableHeader ,
21- TableRow ,
22- } from "@/components/ui/table" ;
23- import DataTablePagination from "@/components/data-table/pagination" ;
24- import { Badge } from "@/components/ui/badge" ;
2512
2613const OVERVIEW_RANKING_QUERY = graphql ( `
2714 query OverviewRanking($filter: RankingFilter!, $first: Int!, $after: Cursor) {
@@ -93,10 +80,10 @@ export default function OverviewRanking() {
9380
9481 const [ rankingBy , setRankingBy ] = useState < RankingBy > ( RankingBy . Points ) ;
9582 const [ rankingOrder , setRankingOrder ] = useState < RankingOrder > (
96- RankingOrder . Desc
83+ RankingOrder . Desc ,
9784 ) ;
9885 const [ rankingPeriod , setRankingPeriod ] = useState < RankingPeriod > (
99- RankingPeriod . Daily
86+ RankingPeriod . Daily ,
10087 ) ;
10188 const [ cursors , setCursors ] = useState < string [ ] > ( [ ] ) ;
10289
@@ -170,7 +157,7 @@ export default function OverviewRanking() {
170157 < SelectItem key = { value } value = { value } >
171158 { label }
172159 </ SelectItem >
173- )
160+ ) ,
174161 ) }
175162 </ SelectContent >
176163 </ Select >
@@ -194,7 +181,7 @@ export default function OverviewRanking() {
194181 < SelectItem key = { value } value = { value } >
195182 { label }
196183 </ SelectItem >
197- )
184+ ) ,
198185 ) }
199186 </ SelectContent >
200187 </ Select >
@@ -213,48 +200,48 @@ export default function OverviewRanking() {
213200 </ TableRow >
214201 </ TableHeader >
215202 < TableBody >
216- { data . ranking . edges . length === 0 ? (
217- < TableRow >
218- < TableCell
219- colSpan = { 3 }
220- className = { `text-center text-muted-foreground` }
221- >
222- 無資料
223- </ TableCell >
224- </ TableRow >
225- ) : (
226- data . ranking . edges . map ( ( edge , index ) => {
227- const rank = index + 1 + cursors . length * PAGE_SIZE ;
228- return (
229- < TableRow key = { edge . node . id } >
230- < TableCell >
231- { rank <= 3 ? (
232- < Badge
233- variant = {
234- rank === 1
235- ? "default"
236- : rank === 2
237- ? "secondary "
238- : "outline"
239- }
240- className = "font-bold"
241- >
242- # { rank }
243- </ Badge >
244- ) : (
245- < span className = "text-muted-foreground" > # { rank } </ span >
246- ) }
247- </ TableCell >
248- < TableCell className = "font-medium" >
249- { edge . node . name }
250- </ TableCell >
251- < TableCell className = "text-right font-semibold" >
252- < ScoreCell userFragment = { edge } rankingBy = { rankingBy } />
253- </ TableCell >
254- </ TableRow >
255- ) ;
256- } )
257- ) }
203+ { data . ranking . edges . length === 0
204+ ? (
205+ < TableRow >
206+ < TableCell
207+ colSpan = { 3 }
208+ className = { `text-center text-muted-foreground` }
209+ >
210+ 無資料
211+ </ TableCell >
212+ </ TableRow >
213+ )
214+ : (
215+ data . ranking . edges . map ( ( edge , index ) => {
216+ const rank = index + 1 + cursors . length * PAGE_SIZE ;
217+ return (
218+ < TableRow key = { edge . node . id } >
219+ < TableCell >
220+ { rank <= 3
221+ ? (
222+ < Badge
223+ variant = { rank === 1
224+ ? "default "
225+ : rank === 2
226+ ? "secondary"
227+ : "outline" }
228+ className = "font-bold"
229+ >
230+ # { rank }
231+ </ Badge >
232+ )
233+ : < span className = "text-muted-foreground" > # { rank } </ span > }
234+ </ TableCell >
235+ < TableCell className = "font-medium" >
236+ { edge . node . name }
237+ </ TableCell >
238+ < TableCell className = "text-right font-semibold" >
239+ < ScoreCell userFragment = { edge } rankingBy = { rankingBy } />
240+ </ TableCell >
241+ </ TableRow >
242+ ) ;
243+ } )
244+ ) }
258245 </ TableBody >
259246 </ Table >
260247
@@ -271,17 +258,20 @@ export default function OverviewRanking() {
271258 ) ;
272259}
273260
274- function ScoreCell ( { userFragment, rankingBy } : { userFragment : FragmentType < typeof SCORE_CELL_FRAGMENT > , rankingBy : RankingBy } ) {
261+ function ScoreCell (
262+ { userFragment, rankingBy } : { userFragment : FragmentType < typeof SCORE_CELL_FRAGMENT > ; rankingBy : RankingBy } ,
263+ ) {
275264 const user = useFragment ( SCORE_CELL_FRAGMENT , userFragment ) ;
276265
277266 const components = {
278267 [ RankingBy . Points ] : < TotalPoints userFragment = { user } /> ,
279268 [ RankingBy . CompletedQuestions ] : < CompletedQuestion userFragment = { user } /> ,
280- }
269+ } ;
281270
282271 return (
283272 < span className = "font-semibold" >
284- { components [ rankingBy ] ?? < span className = "text-red-800" > 發現未定義的排序依據 { rankingBy } </ span > } { ' | ' }
273+ { components [ rankingBy ] ?? < span className = "text-red-800" > 發現未定義的排序依據 { rankingBy } </ span > }
274+ { " | " }
285275 < ScoreDiff userFragment = { user } />
286276 </ span >
287277 ) ;
0 commit comments