Skip to content

Commit

Permalink
feat: user bar team badge
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamerblue committed Dec 7, 2024
1 parent 5c05c72 commit f42f254
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/@types/models.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ interface IUserLite {
avatar: string;
bannerImage: string;
rating?: number;
type?: number;
}

interface IUserProblemResultStats {
Expand Down
2 changes: 1 addition & 1 deletion src/common
Submodule common updated 1 files
+3 −0 contracts/solution.ts
10 changes: 8 additions & 2 deletions src/components/UserBar.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import React from 'react';
import { Avatar, Tooltip } from 'antd';
import { Avatar, Icon, Tooltip } from 'antd';
import { Link } from 'react-router-dom';
import pages from '@/configs/pages';
import { formatAvatarUrl, urlf } from '@/utils/format';
import classNames from 'classnames';
import { getRatingLevel } from '@/utils/rating';
import { EUserType } from '@/common/enums';

export interface Props {
user: IUser | IUserLite;
Expand Down Expand Up @@ -34,11 +35,15 @@ const UserBar: React.FC<Props> = ({
if (!user) {
return <span>--</span>;
}
const isTeam = user.type === EUserType.team;
const avatar = !hideAvatar ? (
<Avatar size="small" icon="user" src={formatAvatarUrl(user.avatar)} />
) : null;
const teamBadge = isTeam ? <Icon type="team" className="ml-sm-md" /> : null;
const username = !hideName ? (
<span style={{ marginLeft: hideAvatar ? '0' : '8px' }}>{nameFormat?.(user) ?? user.nickname}</span>
<span style={{ marginLeft: hideAvatar ? '0' : '8px' }}>
{nameFormat?.(user) ?? user.nickname}
</span>
) : null;
const rating = user.rating;
const userRatingLevel = getRatingLevel(rating);
Expand All @@ -48,6 +53,7 @@ const UserBar: React.FC<Props> = ({
<span className={classNames('no-wrap', className)} style={ratingStyle}>
{avatar}
{username}
{teamBadge}
</span>
);
if (isContestUser || showAsText) {
Expand Down

0 comments on commit f42f254

Please sign in to comment.