|
| 1 | +import { Trophy } from 'lucide-react'; |
1 | 2 | import { getMostQuestionsAnswered } from '@/utils/data/leaderboard/get-most-questions-answered';
|
2 |
| -import Card from '@/components/global/Card'; |
3 | 3 | import ProfilePicture from '@/components/ui/profile-picture';
|
4 | 4 | import { UserRecord } from '@/types/User';
|
5 | 5 | import { shortenText } from '@/utils';
|
6 | 6 | import { getUserDisplayName } from '@/utils/user';
|
7 |
| -import { Trophy } from 'lucide-react'; |
8 |
| - |
9 |
| -const header = () => { |
10 |
| - return ( |
11 |
| - <div className="flex w-full justify-between items-center"> |
12 |
| - <div className="flex flex-col gap-y-0.5"> |
13 |
| - <div className="flex gap-x-2 items-center"> |
14 |
| - <Trophy className="hidden md:block size-5 text-yellow-400" /> |
15 |
| - <h3 className="text-lg">Top users by questions answered</h3> |
16 |
| - </div> |
17 |
| - <p className="text-xs text-gray-400"> |
18 |
| - Battle your way to the top of TechBlitz! |
19 |
| - </p> |
20 |
| - </div> |
21 |
| - </div> |
22 |
| - ); |
23 |
| -}; |
| 7 | +import { |
| 8 | + Table, |
| 9 | + TableBody, |
| 10 | + TableCell, |
| 11 | + TableHead, |
| 12 | + TableHeader, |
| 13 | + TableRow, |
| 14 | +} from '@/components/ui/table'; |
| 15 | +import { |
| 16 | + Card, |
| 17 | + CardHeader, |
| 18 | + CardTitle, |
| 19 | + CardDescription, |
| 20 | + CardContent, |
| 21 | +} from '@/components/ui/card'; |
| 22 | +import { Badge } from '@/components/ui/badge'; |
| 23 | +import ShowTimeTakenToggle from './show-time-taken'; |
24 | 24 |
|
25 |
| -export default async function LeaderboardMostQuestionsAnswered(opts: { |
| 25 | +export default async function LeaderboardMostQuestionsAnswered({ |
| 26 | + userUid, |
| 27 | +}: { |
26 | 28 | userUid?: string;
|
27 | 29 | }) {
|
28 |
| - const { userUid } = opts; |
29 | 30 | const topUsersByQuestionCount = await getMostQuestionsAnswered();
|
30 | 31 |
|
31 | 32 | return (
|
32 |
| - <Card header={header()}> |
33 |
| - <div className="flex flex-col divide-y-[1px] divide-black-50"> |
34 |
| - {/* Headings Row */} |
35 |
| - <div className="flex items-center px-4 py-2 bg-black-75 font-medium font-ubuntu text-xs"> |
36 |
| - <span className="w-[30%]">Position</span> |
37 |
| - <span className="w-[50%]">User</span> |
38 |
| - <span className="w-[20%] text-right">Answered</span> |
39 |
| - </div> |
40 |
| - |
41 |
| - {topUsersByQuestionCount.map((user, index) => ( |
42 |
| - <div |
43 |
| - key={user.uid} |
44 |
| - className={`flex items-center px-4 py-3 ${ |
45 |
| - index % 2 === 0 ? 'bg-black' : 'bg-[#000]' |
46 |
| - }`} |
47 |
| - > |
48 |
| - {/* Position */} |
49 |
| - <span className="w-[30%]">#{index + 1}</span> |
50 |
| - |
51 |
| - {/* User */} |
52 |
| - <div className="w-[50%] flex items-center gap-4"> |
53 |
| - <ProfilePicture |
54 |
| - src={user.userProfilePicture} |
55 |
| - alt={`${user.username} profile picture`} |
56 |
| - /> |
57 |
| - <span> |
58 |
| - {shortenText( |
59 |
| - getUserDisplayName(user as unknown as UserRecord), |
60 |
| - 25 |
61 |
| - )} |
62 |
| - </span> |
63 |
| - {userUid === user.uid && ( |
64 |
| - <span className="text-xs text-gray-500">(You)</span> |
65 |
| - )} |
| 33 | + <Card className="border-none"> |
| 34 | + <CardHeader className="p-0 md:p-6 w-full flex gap-2 justify-between"> |
| 35 | + <div className="flex flex-wrap items-center justify-between gap-2"> |
| 36 | + <div className="flex items-center gap-x-2"> |
| 37 | + <Trophy className="size-5 text-accent" /> |
| 38 | + <div> |
| 39 | + <CardTitle className="text-white"> |
| 40 | + Top Users Leaderboard |
| 41 | + </CardTitle> |
| 42 | + <CardDescription className="text-gray-400"> |
| 43 | + Battle your way to the top of TechBlitz! |
| 44 | + </CardDescription> |
66 | 45 | </div>
|
67 |
| - |
68 |
| - {/* Answered */} |
69 |
| - <span className="w-[20%] text-right">{user._count.answers}</span> |
70 | 46 | </div>
|
71 |
| - ))} |
72 |
| - </div> |
| 47 | + <ShowTimeTakenToggle /> |
| 48 | + </div> |
| 49 | + </CardHeader> |
| 50 | + <CardContent className="p-0 pt-6 md:p-6 md:pt-0"> |
| 51 | + <Table> |
| 52 | + <TableHeader className="bg-transparent"> |
| 53 | + <TableRow className="bg-transparent"> |
| 54 | + <TableHead className="!border-t-0 w-12 md:w-[100px] text-white bg-transparent"> |
| 55 | + Rank |
| 56 | + </TableHead> |
| 57 | + <TableHead className="!border-t-0 text-white bg-transparent"> |
| 58 | + User |
| 59 | + </TableHead> |
| 60 | + <TableHead className="!border-t-0 text-right text-white bg-transparent"> |
| 61 | + Questions Solved |
| 62 | + </TableHead> |
| 63 | + </TableRow> |
| 64 | + </TableHeader> |
| 65 | + <TableBody> |
| 66 | + {topUsersByQuestionCount.map((user, index) => ( |
| 67 | + <TableRow |
| 68 | + key={user.uid} |
| 69 | + className="border-white/10 hover:bg-white/5 transition-colors" |
| 70 | + > |
| 71 | + <TableCell className="font-medium text-white"> |
| 72 | + {index < 3 ? ( |
| 73 | + <Badge |
| 74 | + variant={index === 0 ? 'default' : 'secondary'} |
| 75 | + className={` |
| 76 | + ${index === 0 && 'bg-yellow-500/20 text-yellow-300 hover:bg-yellow-500/30'} |
| 77 | + ${index === 1 && 'bg-gray-400/20 text-gray-300 hover:bg-gray-400/30'} |
| 78 | + ${index === 2 && 'bg-amber-700/20 text-amber-500 hover:bg-amber-700/30'} |
| 79 | + `} |
| 80 | + > |
| 81 | + #{index + 1} |
| 82 | + </Badge> |
| 83 | + ) : ( |
| 84 | + <span className="text-gray-400">#{index + 1}</span> |
| 85 | + )} |
| 86 | + </TableCell> |
| 87 | + <TableCell> |
| 88 | + <div className="flex items-center gap-4"> |
| 89 | + <ProfilePicture |
| 90 | + src={user.userProfilePicture} |
| 91 | + alt={`${user.username} profile picture`} |
| 92 | + className="text-white" |
| 93 | + /> |
| 94 | + <div className="flex gap-2"> |
| 95 | + <span className="text-white font-medium"> |
| 96 | + {shortenText( |
| 97 | + getUserDisplayName(user as unknown as UserRecord), |
| 98 | + 25 |
| 99 | + )} |
| 100 | + </span> |
| 101 | + {userUid === user.uid && ( |
| 102 | + <span className="text-xs text-white">(You)</span> |
| 103 | + )} |
| 104 | + </div> |
| 105 | + </div> |
| 106 | + </TableCell> |
| 107 | + <TableCell className="text-right"> |
| 108 | + <Badge |
| 109 | + variant="outline" |
| 110 | + className="border-white/10 text-white" |
| 111 | + > |
| 112 | + {user._count.answers} |
| 113 | + </Badge> |
| 114 | + </TableCell> |
| 115 | + </TableRow> |
| 116 | + ))} |
| 117 | + </TableBody> |
| 118 | + </Table> |
| 119 | + </CardContent> |
73 | 120 | </Card>
|
74 | 121 | );
|
75 | 122 | }
|
0 commit comments