]> Untitled Git - lemmy.git/blob - ui/src/components/user-listing.tsx
Front end federation names and links for users, posts, and communities.
[lemmy.git] / ui / src / components / user-listing.tsx
1 import { Component } from 'inferno';
2 import { Link } from 'inferno-router';
3 import { UserView } from '../interfaces';
4 import { pictshareAvatarThumbnail, showAvatars, hostname } from '../utils';
5
6 interface UserOther {
7   name: string;
8   id?: number; // Necessary if its federated
9   avatar?: string;
10   local?: boolean;
11   actor_id?: string;
12 }
13
14 interface UserListingProps {
15   user: UserView | UserOther;
16 }
17
18 export class UserListing extends Component<UserListingProps, any> {
19   constructor(props: any, context: any) {
20     super(props, context);
21   }
22
23   render() {
24     let user = this.props.user;
25     let local = user.local == null ? true : user.local;
26     let name_: string, link: string;
27
28     if (local) {
29       name_ = user.name;
30       link = `/u/${user.name}`;
31     } else {
32       name_ = `${hostname(user.actor_id)}/${user.name}`;
33       link = `/user/${user.id}`;
34     }
35
36     return (
37       <Link className="text-body font-weight-bold" to={link}>
38         {user.avatar && showAvatars() && (
39           <img
40             height="32"
41             width="32"
42             src={pictshareAvatarThumbnail(user.avatar)}
43             class="rounded-circle mr-2"
44           />
45         )}
46         <span>{name_}</span>
47       </Link>
48     );
49   }
50 }