]> Untitled Git - lemmy-ui.git/blob - src/shared/components/user-listing.tsx
First pass at v2_api
[lemmy-ui.git] / src / shared / components / user-listing.tsx
1 import { Component } from 'inferno';
2 import { Link } from 'inferno-router';
3 import { UserSafe } from 'lemmy-js-client';
4 import { showAvatars, hostname, isCakeDay } from '../utils';
5 import { CakeDay } from './cake-day';
6 import { PictrsImage } from './pictrs-image';
7
8 interface UserListingProps {
9   user: UserSafe;
10   realLink?: boolean;
11   useApubName?: boolean;
12   muted?: boolean;
13   hideAvatar?: boolean;
14   showApubName?: boolean;
15 }
16
17 export class UserListing extends Component<UserListingProps, any> {
18   constructor(props: any, context: any) {
19     super(props, context);
20   }
21
22   render() {
23     let user = this.props.user;
24     let local = user.local == null ? true : user.local;
25     let apubName: string, link: string;
26
27     if (local) {
28       apubName = `@${user.name}`;
29       link = `/u/${user.name}`;
30     } else {
31       apubName = `@${user.name}@${hostname(user.actor_id)}`;
32       link = !this.props.realLink ? `/user/${user.id}` : user.actor_id;
33     }
34
35     let displayName = this.props.useApubName
36       ? apubName
37       : user.preferred_username
38       ? user.preferred_username
39       : apubName;
40
41     if (this.props.showApubName && !local && user.preferred_username) {
42       displayName = `${displayName} (${apubName})`;
43     }
44
45     return (
46       <>
47         <Link
48           title={apubName}
49           className={this.props.muted ? 'text-muted' : 'text-info'}
50           to={link}
51           target={this.props.realLink ? '_blank' : ''}
52         >
53           {!this.props.hideAvatar && user.avatar && showAvatars() && (
54             <PictrsImage src={user.avatar} icon />
55           )}
56           <span>{displayName}</span>
57         </Link>
58
59         {isCakeDay(user.published) && <CakeDay creatorName={apubName} />}
60       </>
61     );
62   }
63 }