Skip to content

Commit

Permalink
Merge pull request #9 from BYU-CPC/multiple-leaderboards
Browse files Browse the repository at this point in the history
multiple leaderboards
  • Loading branch information
joshbtay authored Sep 19, 2024
2 parents 7b1d33c + ba623a8 commit 838c4b7
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/components/Leaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export function Leaderboard() {
const { data: allProblems } = useProblems();
const { data: leaderboardIndex } = useLeaderboardIndex();
const leaderboardData = leaderboardIndex?.combined?.[leaderboard];
const hasAffiliation = !!leaderboardIndex?.dynamic?.[leaderboard];
useEffect(() => {
document.title = leaderboardData?.name ?? "Leaderboard";
}, [leaderboardData?.name]);
Expand Down Expand Up @@ -151,13 +152,32 @@ export function Leaderboard() {
)}
{calculatedUsers
.filter((a) => !!a.score || a.user.id === user?.uid)
.filter(
(u) =>
!hasAffiliation ||
!!(
u.user.affiliation &&
leaderboard
.toLowerCase()
.startsWith(u.user.affiliation.toLowerCase())
)
)
.sort((a, b) => b.score - a.score)
.map((u, i) => (
<LeaderboardRow
key={u.user.id}
userStats={u}
rank={i + 1}
isMe={u.user?.id === user?.uid}
isAffiliated={
!hasAffiliation ||
!!(
u.user.affiliation &&
leaderboard
.toLowerCase()
.startsWith(u.user.affiliation.toLowerCase())
)
}
/>
))}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/LeaderboardSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function LeaderboardSelector() {
key={key}
setLeaderboard={(leaderboard) => setLeaderboard({ leaderboard })}
isSelected={key === leaderboard}
isDynamic={data.dynamic.hasOwnProperty(key)}
isDynamic={!!data.dynamic?.hasOwnProperty(key)}
name={board.name ?? key}
/>
));
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/UseLeaderboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const useLeaderboardIndex = () => {
: undefined;
const data = {
combined: { ...(transformedData ?? {}), ...staticLeaderboard },
dynamic: transformedData ?? {},
dynamic: transformedData,
static: staticLeaderboard,
};
return {
Expand Down
1 change: 1 addition & 0 deletions src/hooks/UseUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export type User = {
display_name: string;
id: string;
kattis_submissions: Record<string, number>;
affiliation?: string;
codeforces_submissions:
| (Record<
string,
Expand Down
4 changes: 4 additions & 0 deletions src/output.css
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,10 @@ video {
opacity: 0.1;
}

.opacity-50 {
opacity: 0.5;
}

.shadow-lg {
--tw-shadow: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
--tw-shadow-colored: 0 10px 15px -3px var(--tw-shadow-color), 0 4px 6px -4px var(--tw-shadow-color);
Expand Down

0 comments on commit 838c4b7

Please sign in to comment.