Skip to content

Commit 6501caf

Browse files
feat: improved leaderboard page sizing + popup
1 parent 6e1f7bd commit 6501caf

3 files changed

Lines changed: 33 additions & 24 deletions

File tree

src/components/Leaderboard/LeaderboardColumn.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export const LeaderboardColumn: React.FC<Props> = ({
1919
}: Props) => {
2020
return (
2121
<div className="flex flex-col rounded border border-white/10 bg-background-1/60">
22-
<div className="flex flex-row items-center justify-start gap-3 rounded-t bg-background-2 px-6 py-4">
23-
<i className="*:h-6 *:w-6">{icon}</i>
24-
<h2 className="text-2xl font-bold uppercase">{name}</h2>
22+
<div className="flex flex-row items-center justify-start gap-2 rounded-t bg-background-2 px-4 py-2">
23+
<i className="*:h-5 *:w-5">{icon}</i>
24+
<h2 className="text-xl font-bold uppercase">{name}</h2>
2525
</div>
2626
<div className="flex w-full flex-col rounded-b">
2727
{ranking.map((player, index) => (

src/components/Leaderboard/LeaderboardEntry.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ export const LeaderboardEntry = ({
128128

129129
return (
130130
<div
131-
className={`relative flex w-full items-center justify-between px-6 py-2 ${index % 2 === 0 ? 'bg-opacity-0' : 'bg-white bg-opacity-[0.015]'}`}
131+
className={`relative flex w-full items-center justify-between px-4 py-1.5 ${index % 2 === 0 ? 'bg-opacity-0' : 'bg-white bg-opacity-[0.015]'}`}
132132
onMouseEnter={() => setHover(true)}
133133
onMouseLeave={() => setHover(false)}
134134
>
@@ -145,19 +145,19 @@ export const LeaderboardEntry = ({
145145
</div>
146146
<p>{elo}</p>
147147
{isPopupVisible && stats && (
148-
<div className="absolute left-0 top-[100%] z-20 flex w-full max-w-[26rem] flex-col overflow-hidden rounded border border-white/10 bg-background-1">
149-
<div className="flex w-full justify-between bg-backdrop/50 px-4 py-2">
148+
<div className="absolute left-0 top-[100%] z-20 flex w-full max-w-[26rem] flex-col overflow-hidden rounded-lg border-2 border-white/20 bg-background-1 outline outline-1 outline-white/5 backdrop-blur-sm">
149+
<div className="flex w-full justify-between border-b border-white/10 bg-gradient-to-r from-background-2/80 to-background-2/60 px-4 py-2">
150150
<p>
151151
<span className="font-bold">{display_name}</span>&apos;s {type}{' '}
152152
Statistics
153153
</p>
154154
<Link href={`/profile/${display_name}`}>
155-
<i className="material-symbols-outlined select-none text-lg text-primary hover:text-human-1">
155+
<i className="material-symbols-outlined select-none text-lg text-primary transition-colors hover:text-human-1">
156156
open_in_new
157157
</i>
158158
</Link>
159159
</div>
160-
<div className="flex items-center justify-between px-4 py-2">
160+
<div className="flex items-center justify-between bg-gradient-to-b from-background-1 to-background-1/95 px-4 py-3">
161161
<div className="flex flex-col items-center justify-center gap-0.5 text-human-1">
162162
<p className="text-sm xl:text-base">Rating</p>
163163
<b className="text-3xl xl:text-3xl">{stats[ratingKey]}</b>

src/pages/leaderboard.tsx

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,25 @@ const Leaderboard: React.FC = () => {
2222
id: 'regular' | 'train' | 'turing' | 'hand' | 'brain'
2323
}[]
2424
>()
25+
26+
const getTimeAgo = (date: Date) => {
27+
const now = new Date()
28+
const diffInMinutes = Math.floor(
29+
(now.getTime() - date.getTime()) / (1000 * 60),
30+
)
31+
32+
if (diffInMinutes < 1) return 'Just now'
33+
if (diffInMinutes < 60)
34+
return `${diffInMinutes} minute${diffInMinutes > 1 ? 's' : ''} ago`
35+
36+
const diffInHours = Math.floor(diffInMinutes / 60)
37+
if (diffInHours < 24)
38+
return `${diffInHours} hour${diffInHours > 1 ? 's' : ''} ago`
39+
40+
const diffInDays = Math.floor(diffInHours / 24)
41+
return `${diffInDays} day${diffInDays > 1 ? 's' : ''} ago`
42+
}
43+
2544
const fetchLeaderboard = useCallback(async () => {
2645
const lb = await getLeaderboard()
2746
setLastUpdated(new Date(lb.last_updated + 'Z'))
@@ -65,31 +84,21 @@ const Leaderboard: React.FC = () => {
6584

6685
return (
6786
<LeaderboardProvider>
68-
<div className="mx-auto flex h-full w-[90%] flex-col items-start justify-center gap-8 py-[2%]">
87+
<div className="mx-auto flex h-full w-[90%] flex-col items-start justify-center gap-4 py-[1%]">
6988
<Head>
7089
<title>Leaderboard – Maia Chess</title>
7190
<meta
7291
name="description"
7392
content="Top users across all Maia Chess leaderboards"
7493
/>
7594
</Head>
76-
<div className="flex flex-col">
77-
<h1 className="text-4xl font-bold">Rating Leaderboards</h1>
78-
<p>
79-
Last Updated:{' '}
80-
{lastUpdated
81-
? lastUpdated.toLocaleString(undefined, {
82-
year: 'numeric',
83-
month: 'short',
84-
day: 'numeric',
85-
hour: '2-digit',
86-
minute: '2-digit',
87-
hour12: true,
88-
})
89-
: '...'}
95+
<div className="flex w-full flex-row items-end justify-between">
96+
<h1 className="text-3xl font-bold">Rating Leaderboards</h1>
97+
<p className="text-sm text-secondary">
98+
Last updated: {lastUpdated ? getTimeAgo(lastUpdated) : '...'}
9099
</p>
91100
</div>
92-
<div className="grid h-full w-full grid-cols-1 justify-start gap-4 md:grid-cols-2 lg:grid-cols-3">
101+
<div className="grid h-full w-full grid-cols-1 justify-start gap-3 md:grid-cols-2 lg:grid-cols-3">
93102
{leaderboard?.map((column, index) => (
94103
<LeaderboardColumn key={index} {...column} />
95104
))}

0 commit comments

Comments
 (0)