Cleanup avatar again (#161)

* Reinstate avatar component cleanup

This was reverted due to a bug, fixed in the subsequent commit.

* Kill additional wrapper divs around avatars

This also fixes a bug where the `w-8` answer row wrapper div was
constraining the width of the `w-10` avatar, leading it to be `w-8`
and `h-10` and appear as an oval.
This commit is contained in:
Marshall Polaris 2022-05-09 14:32:59 -07:00 committed by GitHub
parent 9fc9fc0dd6
commit 8a99f3772a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 44 additions and 59 deletions

View File

@ -8,10 +8,8 @@ export function Avatar(props: {
noLink?: boolean noLink?: boolean
size?: number | 'xs' | 'sm' size?: number | 'xs' | 'sm'
className?: string className?: string
containerClassName?: string
}) { }) {
const { username, avatarUrl, noLink, size, className, containerClassName } = const { username, avatarUrl, noLink, size, className } = props
props
const s = size == 'xs' ? 6 : size === 'sm' ? 8 : size || 10 const s = size == 'xs' ? 6 : size === 'sm' ? 8 : size || 10
const onClick = const onClick =
@ -21,32 +19,28 @@ export function Avatar(props: {
e.stopPropagation() e.stopPropagation()
Router.push(`/${username}`) Router.push(`/${username}`)
} }
return (
<div // there can be no avatar URL or username in the feed, we show a "submit comment"
// item with a fake grey user circle guy even if you aren't signed in
return avatarUrl ? (
<img
className={clsx( className={clsx(
`flex-shrink-0 rounded-full bg-white w-${s} h-${s}`, 'flex-shrink-0 rounded-full rounded-full bg-white object-cover',
containerClassName `w-${s} h-${s}`,
!noLink && 'cursor-pointer',
className
)} )}
> src={avatarUrl}
{avatarUrl ? ( onClick={onClick}
<img alt={username}
className={clsx( />
'flex items-center justify-center rounded-full object-cover', ) : (
`w-${s} h-${s}`, <UserCircleIcon
!noLink && 'cursor-pointer', className={clsx(
className `flex-shrink-0 rounded-full bg-white w-${s} h-${s} text-gray-500`,
)} className
src={avatarUrl}
onClick={onClick}
alt={username}
/>
) : (
// TODO: After 2022-03-01, can just assume that all contracts have an avatarUrl
<UserCircleIcon
className={`w-${s} h-${s} text-gray-500`}
aria-hidden="true"
/>
)} )}
</div> aria-hidden="true"
/>
) )
} }

View File

@ -262,9 +262,7 @@ export function CommentInput(props: {
return ( return (
<> <>
<Row className={'flex w-full gap-2'}> <Row className={'flex w-full gap-2'}>
<div> <Avatar avatarUrl={user?.avatarUrl} username={user?.username} />
<Avatar avatarUrl={user?.avatarUrl} username={user?.username} />
</div>
<div className={'min-w-0 flex-1'}> <div className={'min-w-0 flex-1'}>
<div className="text-sm text-gray-500"> <div className="text-sm text-gray-500">
{mostRecentCommentableBet && ( {mostRecentCommentableBet && (
@ -413,32 +411,27 @@ export function FeedBet(props: {
return ( return (
<> <>
<Row className={'flex w-full gap-2 pt-3'}> <Row className={'flex w-full gap-2 pt-3'}>
<div> {isSelf ? (
{isSelf ? ( <Avatar
<Avatar className={clsx(smallAvatar && 'ml-1')}
className={clsx(smallAvatar && 'ml-1')} size={smallAvatar ? 'sm' : undefined}
size={smallAvatar ? 'sm' : undefined} avatarUrl={user.avatarUrl}
avatarUrl={user.avatarUrl} username={user.username}
username={user.username} />
/> ) : bettor ? (
) : bettor ? ( <Avatar
<Avatar className={clsx(smallAvatar && 'ml-1')}
className={clsx(smallAvatar && 'ml-1')} size={smallAvatar ? 'sm' : undefined}
size={smallAvatar ? 'sm' : undefined} avatarUrl={bettor.avatarUrl}
avatarUrl={bettor.avatarUrl} username={bettor.username}
username={bettor.username} />
/> ) : (
) : ( <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">
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200"> <UserIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
<UserIcon
className="h-5 w-5 text-gray-500"
aria-hidden="true"
/>
</div>
</div> </div>
)} </div>
</div> )}
<div className={'min-w-0 flex-1 py-1.5'}> <div className={'min-w-0 flex-1 py-1.5'}>
<BetStatusText <BetStatusText
bet={bet} bet={bet}
@ -807,9 +800,7 @@ function FeedAnswerGroup(props: {
<Row className="my-4 gap-3"> <Row className="my-4 gap-3">
<div className="px-1"> <div className="px-1">
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200"> <Avatar username={username} avatarUrl={avatarUrl} />
<Avatar username={username} avatarUrl={avatarUrl} />
</div>
</div> </div>
<Col className="min-w-0 flex-1 gap-2"> <Col className="min-w-0 flex-1 gap-2">
<div className="text-sm text-gray-500"> <div className="text-sm text-gray-500">

View File

@ -60,7 +60,7 @@ export function BottomNavBar() {
) : user ? ( ) : user ? (
<> <>
<Avatar <Avatar
containerClassName={'mx-auto my-1'} className="mx-auto my-1"
size="xs" size="xs"
username={user.username} username={user.username}
avatarUrl={user.avatarUrl} avatarUrl={user.avatarUrl}