Skip to content

Commit 7ecedd1

Browse files
author
sk337
committed
finish leaderboard and add dummy registration page
1 parent 21143a1 commit 7ecedd1

File tree

5 files changed

+180
-43
lines changed

5 files changed

+180
-43
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"@radix-ui/react-navigation-menu": "^1.1.4",
2323
"@radix-ui/react-select": "^2.0.0",
2424
"@radix-ui/react-slot": "^1.0.2",
25+
"@radix-ui/react-tabs": "^1.0.4",
2526
"@radix-ui/react-toast": "^1.1.5",
2627
"@types/node": "^18.0.6",
2728
"@vitejs/plugin-react": "^4.2.1",

src/Leaderboard.jsx

+38-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from "react";
1+
import React, { useEffect, useState, useReducer } from "react";
22
import Nav from "@/components/nav";
33
import {
44
Select,
@@ -15,21 +15,31 @@ import { getPubInfo } from "@/utils/login";
1515
import UserCard from "@/components/usercard";
1616

1717
export default function Leaderboard() {
18+
const [ignored, forceUpdate] = useReducer(x => x + 1, 0);
1819
const [leaderboard, setLeaderboard] = useState([]);
19-
const profiles = [];
20+
const [profiles, setProfiles] = useState([]);
2021
const [upd, setUpd] = useState(0);
2122
const [range, setRange] = useState("all");
2223
const [type, setType] = useState("xp");
2324

25+
function userChk(e){
26+
let res = "empty";
27+
if (profiles.length === 0) {
28+
return res;
29+
}
30+
for (let i = 0; i < profiles.length; i++) {
31+
if (profiles[i] != undefined && profiles[i].account.username === e) {
32+
return profiles[i];
33+
}
34+
}
35+
return res;
36+
}
37+
2438
useEffect(() => {
2539
const fetchLeaderboard = async () => {
2640
const data = await getLeaderboard(range, type);
27-
data.forEach(async (element) => {
28-
let user = element.username;
29-
let info = await getPubInfo(user);
30-
profiles.push(info);
31-
setUpd(upd + 1);
32-
});
41+
console.log(data.length);
42+
3343

3444
setLeaderboard(data);
3545
};
@@ -70,16 +80,27 @@ export default function Leaderboard() {
7080
total += 1;
7181
return (
7282
<tr key={tmp} className="m-5">
73-
<td>
74-
<UserCard
75-
user={
76-
Object.prototype.hasOwnProperty.call(
77-
profiles,
78-
user.username
79-
)
80-
? profiles[user.username]
81-
: "empty"
83+
<td onMouseOver={( async (e)=>{
84+
const username = e.target.childNodes[0].innerText;
85+
console.log(username)
86+
for (let i = 0; i < profiles.length; i++) {
87+
if (profiles[i] === undefined) {
88+
} else if (Object.prototype.hasOwnProperty.call(profiles[i], "account") && profiles[i].account.username === username){
89+
return;
8290
}
91+
}
92+
93+
let ud = await getPubInfo(username);
94+
if (ud.error) {
95+
console.log("Error: ", ud.error);
96+
} else {
97+
let image= await import(`../vendor/swordbattle.io/client/public/assets/game/player/${id2skin(ud.account.skins.equipped).bodyFileName}`)
98+
ud["image"] = image.default;
99+
setProfiles(profiles =>[...profiles, ud]);
100+
}
101+
})}>
102+
<UserCard
103+
user={userChk(user.username)}
83104
>
84105
{user.username}
85106
</UserCard>

src/Login.jsx

+65-22
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ import {
77
CardHeader,
88
CardTitle,
99
} from "@/components/ui/card";
10+
import {
11+
Tabs,
12+
TabsContent,
13+
TabsList,
14+
TabsTrigger,
15+
} from "@/components/ui/tabs";
1016
import { Button } from "@/components/ui/button";
1117
import { Input } from "@/components/ui/input";
1218
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
@@ -28,6 +34,10 @@ export default function Login() {
2834
}
2935
});
3036
}
37+
38+
function register() {
39+
alert("For Now, Registration is not available for now. Please Login.")
40+
}
3141

3242
return (
3343
<main className="flex flex-col items-center justify-center">
@@ -39,28 +49,61 @@ export default function Login() {
3949
Invalid Username or Password
4050
</AlertDescription>
4151
</Alert>
42-
<Card className="w-full">
43-
<CardHeader>
44-
<CardTitle className=" text-center">
45-
Login With Swordbattle
46-
</CardTitle>
47-
</CardHeader>
48-
<CardContent>
49-
<Input id="username" placeholder="Username"></Input>
50-
<Input
51-
id="password"
52-
placeholder="Password"
53-
type="password"
54-
className="mt-3"
55-
></Input>
56-
<Button
57-
className="text-center mt-5 w-full bg-blue-500 hover:bg-blue-600"
58-
onClick={flogin}
59-
>
60-
Login
61-
</Button>
62-
</CardContent>
63-
</Card>
52+
<Tabs defaultValue="login" className="w-[400px]">
53+
<TabsList className=" grid w-full grid-cols-2">
54+
<TabsTrigger value="login">Log In</TabsTrigger>
55+
<TabsTrigger value="signup">Sign Up</TabsTrigger>
56+
</TabsList>
57+
<TabsContent value="login">
58+
<Card className="w-full">
59+
<CardHeader>
60+
<CardTitle className=" text-center">
61+
Login With Swordbattle
62+
</CardTitle>
63+
</CardHeader>
64+
<CardContent>
65+
<Input id="username" placeholder="Username"></Input>
66+
<Input
67+
id="password"
68+
placeholder="Password"
69+
type="password"
70+
className="mt-3"
71+
></Input>
72+
<Button
73+
className="text-center mt-5 w-full bg-blue-500 hover:bg-blue-600"
74+
onClick={flogin}
75+
>
76+
Login
77+
</Button>
78+
</CardContent>
79+
</Card>
80+
</TabsContent>
81+
<TabsContent value="signup">
82+
<Card className="w-full">
83+
<CardHeader>
84+
<CardTitle className=" text-center">
85+
Sign Up for Account
86+
</CardTitle>
87+
</CardHeader>
88+
<CardContent>
89+
<Input id="username" placeholder="Username"></Input>
90+
<Input
91+
id="password"
92+
placeholder="Password"
93+
type="password"
94+
className="mt-3"
95+
></Input>
96+
<Button
97+
className="text-center mt-5 w-full bg-blue-500 hover:bg-blue-600"
98+
onClick={register}
99+
>
100+
Sign Up
101+
</Button>
102+
</CardContent>
103+
</Card>
104+
</TabsContent>
105+
</Tabs>
106+
64107
</div>
65108
</main>
66109
);

src/components/ui/tabs.tsx

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import * as React from "react"
2+
import * as TabsPrimitive from "@radix-ui/react-tabs"
3+
4+
import { cn } from "@/utils/utils"
5+
6+
const Tabs = TabsPrimitive.Root
7+
8+
const TabsList = React.forwardRef<
9+
React.ElementRef<typeof TabsPrimitive.List>,
10+
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
11+
>(({ className, ...props }, ref) => (
12+
<TabsPrimitive.List
13+
ref={ref}
14+
className={cn(
15+
"inline-flex h-10 items-center justify-center rounded-md bg-muted p-1 text-muted-foreground",
16+
className
17+
)}
18+
{...props}
19+
/>
20+
))
21+
TabsList.displayName = TabsPrimitive.List.displayName
22+
23+
const TabsTrigger = React.forwardRef<
24+
React.ElementRef<typeof TabsPrimitive.Trigger>,
25+
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
26+
>(({ className, ...props }, ref) => (
27+
<TabsPrimitive.Trigger
28+
ref={ref}
29+
className={cn(
30+
"inline-flex items-center justify-center whitespace-nowrap rounded-sm px-3 py-1.5 text-sm font-medium ring-offset-background transition-all focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=active]:shadow-sm",
31+
className
32+
)}
33+
{...props}
34+
/>
35+
))
36+
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
37+
38+
const TabsContent = React.forwardRef<
39+
React.ElementRef<typeof TabsPrimitive.Content>,
40+
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
41+
>(({ className, ...props }, ref) => (
42+
<TabsPrimitive.Content
43+
ref={ref}
44+
className={cn(
45+
"mt-2 ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2",
46+
className
47+
)}
48+
{...props}
49+
/>
50+
))
51+
TabsContent.displayName = TabsPrimitive.Content.displayName
52+
53+
export { Tabs, TabsList, TabsTrigger, TabsContent }

src/components/usercard.jsx

+23-4
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,27 @@ import {
66
} from "@/components/ui/hover-card";
77
import { CalendarDays } from "lucide-react";
88
import { Skeleton } from "@/components/ui/skeleton";
9+
import { id2skin } from "@/utils/jsutils";
910

1011
export default function UserCard({ user, children }) {
12+
function dateparse(){
13+
let date = new Date(user.account.created_at).toString().split(" ");
14+
let monthMap= {
15+
"Jan": "January",
16+
"Feb": "February",
17+
"Mar": "March",
18+
"Apr": "April",
19+
"May": "May",
20+
"Jun": "June",
21+
"Jul": "July",
22+
"Aug": "August",
23+
"Sep": "September",
24+
"Oct": "October",
25+
"Nov": "November",
26+
"Dec": "December"
27+
}
28+
return `${monthMap[date[1]]} ${date[2]} ${date[3]}`;
29+
}
1130
if (user == "empty") {
1231
return (
1332
<HoverCard>
@@ -30,18 +49,18 @@ export default function UserCard({ user, children }) {
3049
<HoverCardContent className="w-80">
3150
<div className="flex justify-between space-x-4">
3251
<Avatar>
33-
<AvatarImage src="https://github.com/vercel.png" />
52+
<AvatarImage src={user.image} />
3453
<AvatarFallback>VC</AvatarFallback>
3554
</Avatar>
3655
<div className="space-y-1">
37-
<h4 className="text-sm font-semibold">@{user.username}</h4>
56+
<h4 className="text-sm font-semibold">@{user.account.username}</h4>
3857
<p className="text-sm">
39-
The React Framework – created and maintained by @vercel.
58+
If Gautam adds bios it will go here
4059
</p>
4160
<div className="flex items-center pt-2">
4261
<CalendarDays className="mr-2 h-4 w-4 opacity-70" />{" "}
4362
<span className="text-xs text-muted-foreground">
44-
Joined December 2021
63+
Joined {dateparse()}
4564
</span>
4665
</div>
4766
</div>

0 commit comments

Comments
 (0)