Skip to content

Commit 5c11f7c

Browse files
committed
Fix lint / formatting
1 parent b5eec09 commit 5c11f7c

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

site/components/Navbar/UserDropdown.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import Avatar from "@material-ui/core/Avatar"
21
import Badge from "@material-ui/core/Badge"
2+
import Divider from "@material-ui/core/Divider"
33
import ListItemIcon from "@material-ui/core/ListItemIcon"
44
import ListItemText from "@material-ui/core/ListItemText"
55
import MenuItem from "@material-ui/core/MenuItem"
@@ -12,7 +12,7 @@ import { BorderedMenu } from "./BorderedMenu"
1212
import { UserProfileCard } from "../User/UserProfileCard"
1313

1414
import { User } from "../../contexts/UserContext"
15-
import Divider from "@material-ui/core/Divider"
15+
import { UserAvatar } from "../User"
1616

1717
export interface UserDropdownProps {
1818
user: User
@@ -37,7 +37,7 @@ export const UserDropdown: React.FC<UserDropdownProps> = ({ user, onSignOut }: U
3737
<div className={styles.inner}>
3838
{user && (
3939
<Badge overlap="circle">
40-
<Avatar>T</Avatar>
40+
<UserAvatar user={user} />
4141
</Badge>
4242
)}
4343
{anchorEl ? (

site/components/User/UserAvatar.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import Avatar from "@material-ui/core/Avatar"
2+
import React from "react"
3+
import { User } from "../../contexts/UserContext"
4+
5+
export interface UserAvatarProps {
6+
user: User
7+
className?: string
8+
}
9+
10+
export const UserAvatar: React.FC<UserAvatarProps> = ({ user, className }) => {
11+
return <Avatar className={className}>{firstLetter(user.username)}</Avatar>
12+
}
13+
14+
/**
15+
* `firstLetter` extracts the first character and returns it, uppercased
16+
*
17+
* If the string is empty or null, returns an empty string
18+
*/
19+
export const firstLetter = (str: string): string => {
20+
if (str && str.length > 0) {
21+
return str[0].toLocaleUpperCase()
22+
}
23+
24+
return ""
25+
}

site/components/User/UserProfileCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import Avatar from "@material-ui/core/Avatar"
21
import { makeStyles } from "@material-ui/core/styles"
32
import Typography from "@material-ui/core/Typography"
43
import React from "react"
54

65
import { User } from "../../contexts/UserContext"
6+
import { UserAvatar } from "./UserAvatar"
77

88
interface UserProfileCardProps {
99
user: User
@@ -15,7 +15,7 @@ export const UserProfileCard: React.FC<UserProfileCardProps> = ({ user }) => {
1515
return (
1616
<div className={styles.root}>
1717
<div className={styles.avatarContainer}>
18-
<Avatar className={styles.avatar}>T</Avatar>
18+
<UserAvatar className={styles.avatar} user={user} />
1919
</div>
2020
<Typography className={styles.userName}>{user.username}</Typography>
2121
<Typography className={styles.userEmail}>{user.email}</Typography>

site/components/User/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from "./UserAvatar"
2+
export * from "./UserProfileCard"

0 commit comments

Comments
 (0)