]> Untitled Git - lemmy.git/blob - ui/src/components/community-link.tsx
Merge pull request #687 from LemmyNet/undo_delete_community
[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   realLink?: boolean;
16 }
17
18 export class CommunityLink extends Component<CommunityLinkProps, any> {
19   constructor(props: any, context: any) {
20     super(props, context);
21   }
22
23   render() {
24     let community = this.props.community;
25     let name_: string, link: string;
26     let local = community.local == null ? true : community.local;
27     if (local) {
28       name_ = community.name;
29       link = `/c/${community.name}`;
30     } else {
31       name_ = `${community.name}@${hostname(community.actor_id)}`;
32       link = !this.props.realLink
33         ? `/community/${community.id}`
34         : community.actor_id;
35     }
36     return <Link to={link}>{name_}</Link>;
37   }
38 }