]> Untitled Git - lemmy-ui.git/blob - src/shared/components/community-link.tsx
Running newer prettier.
[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, title: string, link: string;
24     let local = community.local == null ? true : community.local;
25     if (local) {
26       name_ = community.name;
27       title = community.title;
28       link = `/c/${community.name}`;
29     } else {
30       name_ = `${community.name}@${hostname(community.actor_id)}`;
31       title = `${community.title}@${hostname(community.actor_id)}`;
32       link = !this.props.realLink
33         ? `/community/${community.id}`
34         : community.actor_id;
35     }
36
37     let apubName = `!${name_}`;
38     let displayName = this.props.useApubName ? apubName : title;
39     return (
40       <Link
41         title={apubName}
42         className={`${this.props.muted ? "text-muted" : ""}`}
43         to={link}
44       >
45         {!this.props.hideAvatar && community.icon && showAvatars() && (
46           <PictrsImage src={community.icon} icon />
47         )}
48         <span>{displayName}</span>
49       </Link>
50     );
51   }
52 }