]> Untitled Git - lemmy.git/blob - ui/src/components/community-link.tsx
Merge branch 'master' into merge_master_2
[lemmy.git] / ui / src / components / community-link.tsx
1 import { Component } from 'inferno';
2 import { Link } from 'inferno-router';
3 import { Community } from '../interfaces';
4 import { hostname } from '../utils';
5
6 interface CommunityOther {
7   name: string;
8   id?: number; // Necessary if its federated
9   local?: boolean;
10   actor_id?: string;
11 }
12
13 interface CommunityLinkProps {
14   community: Community | CommunityOther;
15 }
16
17 export class CommunityLink extends Component<CommunityLinkProps, any> {
18   constructor(props: any, context: any) {
19     super(props, context);
20   }
21
22   render() {
23     let community = this.props.community;
24     let name_: string, link: string;
25     let local = community.local == null ? true : community.local;
26     if (local) {
27       name_ = community.name;
28       link = `/c/${community.name}`;
29     } else {
30       name_ = `${hostname(community.actor_id)}/${community.name}`;
31       link = `/community/${community.id}`;
32     }
33     return <Link to={link}>{name_}</Link>;
34   }
35 }