Skip to content

Commit bcceddb

Browse files
Leaderboard frontend (#57)
* added leaderboard page with test data * added daily stats * undid min width css Co-authored-by: a-jason-liu21 <a.jason.liu21@gmail.com>
1 parent ffb4c6e commit bcceddb

File tree

3 files changed

+138
-8
lines changed

3 files changed

+138
-8
lines changed

frontend/src/App.module.css

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,49 @@ body {
7676

7777
.aboutPage {
7878
padding: 20px;
79+
}
80+
81+
/* --------------------------------------------------------- LEADERBOARD PAGE STYLES ---------------------------------------------------*/
82+
83+
.leaderboardPage {
84+
padding-left: 20px;
85+
white-space: pre-wrap;
86+
}
87+
88+
.userProfile {
89+
font-family: monospace;
90+
}
91+
92+
.profileText {
93+
padding-right: 8px;
94+
}
95+
96+
.userImg {
97+
padding-right: 4px;
98+
}
99+
100+
.link {
101+
color: #009900;
102+
text-decoration: none;
103+
}
104+
105+
.dayLink {
106+
color: #009900;
107+
text-decoration: none;
108+
cursor: pointer;
109+
padding-left: 4px;
110+
}
111+
112+
.daySelected {
113+
color: white;
114+
font-weight: 700;
115+
padding-left: 4px;
116+
}
117+
118+
.userNoLinkText {
119+
padding-left: 24px;
120+
}
121+
122+
.leaderBoardDays {
123+
padding-left: 4px;
79124
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { useEffect, useState } from "react";
2+
import styles from "../../App.module.css";
3+
import { UserDetails } from "../../pages/Leaderboard";
4+
5+
const UserProfile = (props: UserDetails) => {
6+
return (
7+
<div className={styles.userProfile}>
8+
<span className={styles.profileText}>{(props.position.toString() + ")").padStart(4)}</span>
9+
<span className={styles.profileText}>{props.userScore.toString().padStart(4)}</span>
10+
{(props.userLink != "")
11+
? <a className={styles.link} href={props.userLink} target="_blank">
12+
<span className={styles.userImg}>
13+
<img src={props.userLink + ".png"} height="20px"/>
14+
</span>
15+
{props.userName}
16+
</a>
17+
: <span className={styles.userNoLinkText}>
18+
{props.userName}
19+
</span>
20+
}
21+
</div>
22+
)
23+
};
24+
25+
export default UserProfile;

frontend/src/pages/Leaderboard.tsx

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,45 @@
11
import React, { useEffect, useState } from "react";
22
import { Button, Container } from "react-bootstrap";
3-
import { useNavigate } from "react-router-dom";
3+
import { Navigate, useNavigate } from "react-router-dom";
4+
import styles from "../App.module.css";
5+
import UserProfile from "../components/leaderboard/UserProfile"
46

57
import { BACKEND_URI } from "src/config";
68

9+
export interface UserDetails {
10+
position: number;
11+
userName: string;
12+
userScore: number;
13+
userLink: string;
14+
}
15+
716
const Leaderboard: React.FC<{}> = () => {
8-
const [times, setTimes] = useState(0);
17+
18+
const defaultUsers: UserDetails[] = [
19+
{
20+
position: 1,
21+
userName: "csesoc",
22+
userScore: 9999,
23+
userLink: "https://github.com/csesoc"
24+
},
25+
{
26+
position: 10,
27+
userName: "no_github_link",
28+
userScore: 999,
29+
userLink: ""
30+
},
31+
{
32+
position: 100,
33+
userName: "a-jason-liu21",
34+
userScore: 99,
35+
userLink: "https://github.com/a-jason-liu21"
36+
}
37+
]
38+
39+
const DAYS = 7;
40+
const OVERALL = 0;
41+
const [users, setUsers] = useState(defaultUsers);
42+
const [day, setDay] = useState(OVERALL);
943

1044
useEffect(() => {
1145
const verifyToken = async () => {
@@ -15,13 +49,39 @@ const Leaderboard: React.FC<{}> = () => {
1549
verifyToken();
1650
}, []);
1751

52+
useEffect(() => {
53+
console.log("Doing backend query for day " + day + "!");
54+
}, [day]);
55+
1856
return (
19-
<>
20-
<Container className="justify-content-center text-center">
21-
<p>You have clicked this button {times} times.</p>
22-
<Button onClick={() => setTimes(times + 1)}>Leaderboard Page</Button>
23-
</Container>
24-
</>
57+
<div className={styles.leaderboardPage}>
58+
<div>
59+
This is the {(day === OVERALL) ? "overall leaderboard" : ("leaderboard for day " + day)} of the <span className={styles.bold}>CSESoc Unnamed Puzzle Competition 2021</span>,
60+
which displays the users with the {(day === OVERALL) ? "highest cumulative points achieved during the contest" : "earliest submissions during the day"}.
61+
</div>
62+
<br />
63+
64+
<div>
65+
Points awarded for completing problems - the first to solve a problem receives 100 points, followed by 99 points for
66+
the second solver, then 98 and so on down to 1 point for the 100th solver.
67+
</div>
68+
<br />
69+
70+
<div>
71+
To see the leaderboard for a particular day, choose a day here:
72+
{Array.from({length: DAYS},(x, i) => <span className={(day === i + 1) ? styles.daySelected : styles.dayLink} onClick = {() => setDay(i + 1)}>{i + 1}</span>)}
73+
</div>
74+
75+
{day !== OVERALL &&
76+
<div>
77+
To see the overall leaderboard, click <span className={styles.link} onClick={() => setDay(0)}>here</span>.
78+
</div>}
79+
<br />
80+
81+
{users.map((user: UserDetails) => {
82+
return <UserProfile position={user.position} userName={user.userName} userScore={user.userScore} userLink={user.userLink}/>
83+
})}
84+
</div>
2585
)
2686
};
2787

0 commit comments

Comments
 (0)