]> Untitled Git - lemmy.git/blob - ui/src/components/user-listing.tsx
Changing federated community and user links and searching.
[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   realLink?: boolean;
17 }
18
19 export class UserListing extends Component<UserListingProps, any> {
20   constructor(props: any, context: any) {
21     super(props, context);
22   }
23
24   render() {
25     let user = this.props.user;
26     let local = user.local == null ? true : user.local;
27     let name_: string, link: string;
28
29     if (local) {
30       name_ = user.name;
31       link = `/u/${user.name}`;
32     } else {
33       name_ = `${user.name}@${hostname(user.actor_id)}`;
34       link = !this.props.realLink ? `/user/${user.id}` : user.actor_id;
35     }
36
37     return (
38       <Link className="text-body font-weight-bold" to={link}>
39         {user.avatar && showAvatars() && (
40           <img
41             height="32"
42             width="32"
43             src={pictshareAvatarThumbnail(user.avatar)}
44             class="rounded-circle mr-2"
45           />
46         )}
47         <span>{name_}</span>
48       </Link>
49     );
50   }
51 }