]> Untitled Git - lemmy-ui.git/blob - src/shared/components/community-link.tsx
8bf73ca38e0d62211a4a3c02a1053b4ac6ab3eab
[lemmy-ui.git] / src / shared / components / community-link.tsx
1 import { Component } from 'inferno';
2 import { Link } from 'inferno-router';
3 import { Community } from 'lemmy-js-client';
4 import { hostname, showAvatars } from '../utils';
5 import { PictrsImage } from './pictrs-image';
6
7 interface CommunityOther {
8   name: string;
9   id?: number; // Necessary if its federated
10   icon?: string;
11   local?: boolean;
12   actor_id?: string;
13 }
14
15 interface CommunityLinkProps {
16   community: Community | CommunityOther;
17   realLink?: boolean;
18   useApubName?: boolean;
19   muted?: boolean;
20   hideAvatar?: boolean;
21 }
22
23 export class CommunityLink extends Component<CommunityLinkProps, any> {
24   constructor(props: any, context: any) {
25     super(props, context);
26   }
27
28   render() {
29     let community = this.props.community;
30     let name_: string, link: string;
31     let local = community.local == null ? true : community.local;
32     if (local) {
33       name_ = community.name;
34       link = `/c/${community.name}`;
35     } else {
36       name_ = `${community.name}@${hostname(community.actor_id)}`;
37       link = !this.props.realLink
38         ? `/community/${community.id}`
39         : community.actor_id;
40     }
41
42     let apubName = `!${name_}`;
43     let displayName = this.props.useApubName ? apubName : name_;
44     return (
45       <Link
46         title={apubName}
47         className={`${this.props.muted ? 'text-muted' : ''}`}
48         to={link}
49         target={this.props.realLink ? '_blank' : ''}
50       >
51         {!this.props.hideAvatar && community.icon && showAvatars() && (
52           <PictrsImage src={community.icon} icon />
53         )}
54         <span>{displayName}</span>
55       </Link>
56     );
57   }
58 }