Skip to content

Commit

Permalink
Merge branch 'main' into leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
BanEvading authored Jan 3, 2025
2 parents ccc5074 + df0800c commit f6db438
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 17 deletions.
3 changes: 2 additions & 1 deletion components/Avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default function Avatar(props: {
onClick?: () => void | undefined;
className?: string | undefined;
online?: boolean;
gearSize?: number;
}) {
const { session, status } = useCurrentSession();
const user = props.user ?? session?.user;
Expand Down Expand Up @@ -38,7 +39,7 @@ export default function Avatar(props: {
</div>
{admin ? (
<div className="absolute z-10 -bottom-2 -left-2 text-slate-300 animate-spin-slow">
<BsGearFill size={36} />
<BsGearFill size={props.gearSize ?? 36}></BsGearFill>
</div>
) : (
<></>
Expand Down
1 change: 1 addition & 0 deletions components/Container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ export default function Container(props: ContainerProps) {
imgHeightOverride="h-11"
showLevel={false}
borderThickness={2}
gearSize={24}
/>
</Link>
) : (
Expand Down
53 changes: 38 additions & 15 deletions components/XpProgressBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,44 @@ export default function XpProgressBar({
const [hovered, setHovered] = useState(false);

return (
<div
className={`radial-progress text-accent m-2 text-${hovered ? "xs" : "sm"}`}
style={
{
"--value": (user.xp / xpRequiredForNextLevel(user.level)) * 100,
"--size": size,
} as any
}
role="progressbar"
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
>
{hovered
? `${user.xp}/${xpRequiredForNextLevel(user.level)}`
: `Lvl ${user.level}`}
<div className="text-accent m-2">
{/* Desktop layout */}
<div
className={`max-sm:hidden radial-progress text-${hovered ? "xs" : "sm"}`}
style={
{
"--value":
((user.xp - xpRequiredForNextLevel(user.level - 1)) /
(xpRequiredForNextLevel(user.level) -
xpRequiredForNextLevel(user.level - 1))) *
100,
"--size": size,
} as any
}
role="progressbar"
onMouseEnter={() => setHovered(true)}
onMouseLeave={() => setHovered(false)}
>
{hovered
? `${user.xp}/${xpRequiredForNextLevel(user.level)}`
: `Lvl ${user.level}`}
</div>
{/* Desktop layout */}
<div className="sm:hidden">
<div className="divider" />
<div>
Level {user.level} - XP: {user.xp}/
{xpRequiredForNextLevel(user.level)}
</div>
<progress
className="progress progress-accent"
value={user.xp - xpRequiredForNextLevel(user.level - 1)}
max={
xpRequiredForNextLevel(user.level) -
xpRequiredForNextLevel(user.level - 1)
}
/>
</div>
</div>
);
}
1 change: 1 addition & 0 deletions components/competition/MatchScheduleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export default function MatchScheduleCard(props: {
showLevel={false}
borderThickness={2}
onClick={() => remindUserOnSlack(user._id!)}
gearSize={25}
/>
) : (
<div className="w-12 h-12"></div>
Expand Down
2 changes: 1 addition & 1 deletion lib/Xp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function levelToXp(level: number) {
}

export function xpRequiredForNextLevel(level: number) {
return levelToXp(level + 1);
return Math.max(levelToXp(level + 1), 0);
}

export function levelToClassName(level: number | undefined) {
Expand Down

0 comments on commit f6db438

Please sign in to comment.