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