11import { useState , useCallback } from 'react' ;
22
33import classNames from 'classnames' ;
4+ import { Link } from 'react-router-dom' ;
45
56import { useHovering } from 'mastodon/hooks/useHovering' ;
67import { autoPlayGif } from 'mastodon/initial_state' ;
78import type { Account } from 'mastodon/models/account' ;
89
910interface Props {
10- account : Account | undefined ; // FIXME: remove `undefined` once we know for sure its always there
11- size : number ;
11+ account :
12+ | Pick < Account , 'id' | 'acct' | 'avatar' | 'avatar_static' >
13+ | undefined ; // FIXME: remove `undefined` once we know for sure its always there
14+ size ?: number ;
1215 style ?: React . CSSProperties ;
1316 inline ?: boolean ;
1417 animate ?: boolean ;
18+ withLink ?: boolean ;
1519 counter ?: number | string ;
1620 counterBorderColor ?: string ;
1721}
@@ -21,6 +25,7 @@ export const Avatar: React.FC<Props> = ({
2125 animate = autoPlayGif ,
2226 size = 20 ,
2327 inline = false ,
28+ withLink = false ,
2429 style : styleFromParent ,
2530 counter,
2631 counterBorderColor,
@@ -35,10 +40,7 @@ export const Avatar: React.FC<Props> = ({
3540 height : `${ size } px` ,
3641 } ;
3742
38- const src =
39- hovering || animate
40- ? account ?. get ( 'avatar' )
41- : account ?. get ( 'avatar_static' ) ;
43+ const src = hovering || animate ? account ?. avatar : account ?. avatar_static ;
4244
4345 const handleLoad = useCallback ( ( ) => {
4446 setLoading ( false ) ;
@@ -48,7 +50,7 @@ export const Avatar: React.FC<Props> = ({
4850 setError ( true ) ;
4951 } , [ setError ] ) ;
5052
51- return (
53+ const avatar = (
5254 < div
5355 className = { classNames ( 'account__avatar' , {
5456 'account__avatar--inline' : inline ,
@@ -72,4 +74,18 @@ export const Avatar: React.FC<Props> = ({
7274 ) }
7375 </ div >
7476 ) ;
77+
78+ if ( withLink ) {
79+ return (
80+ < Link
81+ to = { `/@${ account ?. acct } ` }
82+ title = { `@${ account ?. acct } ` }
83+ data-hover-card-account = { account ?. id }
84+ >
85+ { avatar }
86+ </ Link >
87+ ) ;
88+ }
89+
90+ return avatar ;
7591} ;
0 commit comments