Refactor empty avatar component

This commit is contained in:
Sinclair Chen 2022-06-23 12:55:41 -05:00
parent 9757ed1d8b
commit 00c2012ccf
3 changed files with 19 additions and 9 deletions

View File

@ -1,7 +1,7 @@
import Router from 'next/router' import Router from 'next/router'
import clsx from 'clsx' import clsx from 'clsx'
import { MouseEvent } from 'react' import { MouseEvent } from 'react'
import { UserCircleIcon } from '@heroicons/react/solid' import { UserCircleIcon, UserIcon, UsersIcon } from '@heroicons/react/solid'
export function Avatar(props: { export function Avatar(props: {
username?: string username?: string
@ -45,3 +45,17 @@ export function Avatar(props: {
/> />
) )
} }
export function EmptyAvatar(props: { size?: number; multi?: boolean }) {
const { size = 8, multi } = props
const insize = size - 3
const Icon = multi ? UsersIcon : UserIcon
return (
<div
className={`flex h-${size} w-${size} items-center justify-center rounded-full bg-gray-200`}
>
<Icon className={`h-${insize} w-${insize} text-gray-500`} aria-hidden />
</div>
)
}

View File

@ -4,7 +4,7 @@ import { Bet } from 'common/bet'
import { User } from 'common/user' import { User } from 'common/user'
import { useUser, useUserById } from 'web/hooks/use-user' import { useUser, useUserById } from 'web/hooks/use-user'
import { Row } from 'web/components/layout/row' import { Row } from 'web/components/layout/row'
import { Avatar } from 'web/components/avatar' import { Avatar, EmptyAvatar } from 'web/components/avatar'
import clsx from 'clsx' import clsx from 'clsx'
import { UserIcon, UsersIcon } from '@heroicons/react/solid' import { UserIcon, UsersIcon } from '@heroicons/react/solid'
import { formatMoney } from 'common/util/format' import { formatMoney } from 'common/util/format'
@ -50,9 +50,7 @@ export function FeedBet(props: {
/> />
) : ( ) : (
<div className="relative px-1"> <div className="relative px-1">
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200"> <EmptyAvatar />
<UserIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
</div>
</div> </div>
)} )}
<div className={'min-w-0 flex-1 py-1.5'}> <div className={'min-w-0 flex-1 py-1.5'}>

View File

@ -7,7 +7,7 @@ import {
notification_source_types, notification_source_types,
notification_source_update_types, notification_source_update_types,
} from 'common/notification' } from 'common/notification'
import { Avatar } from 'web/components/avatar' import { Avatar, EmptyAvatar } from 'web/components/avatar'
import { Row } from 'web/components/layout/row' import { Row } from 'web/components/layout/row'
import { Page } from 'web/components/page' import { Page } from 'web/components/page'
import { Title } from 'web/components/title' import { Title } from 'web/components/title'
@ -235,9 +235,7 @@ function NotificationGroupItem(props: {
/> />
)} )}
<Row className={'items-center text-gray-500 sm:justify-start'}> <Row className={'items-center text-gray-500 sm:justify-start'}>
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200"> <EmptyAvatar multi />
<UsersIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
</div>
<div className={'flex-1 overflow-hidden pl-2 sm:flex'}> <div className={'flex-1 overflow-hidden pl-2 sm:flex'}>
<div <div
onClick={() => setExpanded(!expanded)} onClick={() => setExpanded(!expanded)}