2021-02-22 02:39:04 +00:00
|
|
|
import { Component } from "inferno";
|
|
|
|
import { Link } from "inferno-router";
|
|
|
|
import { CommunitySafe } from "lemmy-js-client";
|
|
|
|
import { hostname, showAvatars } from "../utils";
|
|
|
|
import { PictrsImage } from "./pictrs-image";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface CommunityLinkProps {
|
2020-12-24 01:58:27 +00:00
|
|
|
// TODO figure this out better
|
|
|
|
community: CommunitySafe;
|
2020-09-06 16:15:25 +00:00
|
|
|
realLink?: boolean;
|
|
|
|
useApubName?: boolean;
|
|
|
|
muted?: boolean;
|
|
|
|
hideAvatar?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class CommunityLink extends Component<CommunityLinkProps, any> {
|
|
|
|
constructor(props: any, context: any) {
|
|
|
|
super(props, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
let community = this.props.community;
|
2021-01-23 22:23:49 +00:00
|
|
|
let name_: string, title: string, link: string;
|
2020-09-06 16:15:25 +00:00
|
|
|
let local = community.local == null ? true : community.local;
|
|
|
|
if (local) {
|
|
|
|
name_ = community.name;
|
2021-01-23 22:23:49 +00:00
|
|
|
title = community.title;
|
2020-09-06 16:15:25 +00:00
|
|
|
link = `/c/${community.name}`;
|
|
|
|
} else {
|
|
|
|
name_ = `${community.name}@${hostname(community.actor_id)}`;
|
2021-01-23 22:23:49 +00:00
|
|
|
title = `${community.title}@${hostname(community.actor_id)}`;
|
2020-09-06 16:15:25 +00:00
|
|
|
link = !this.props.realLink
|
|
|
|
? `/community/${community.id}`
|
|
|
|
: community.actor_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
let apubName = `!${name_}`;
|
2021-01-23 22:23:49 +00:00
|
|
|
let displayName = this.props.useApubName ? apubName : title;
|
2020-09-06 16:15:25 +00:00
|
|
|
return (
|
|
|
|
<Link
|
|
|
|
title={apubName}
|
2021-02-22 02:39:04 +00:00
|
|
|
className={`${this.props.muted ? "text-muted" : ""}`}
|
2020-09-06 16:15:25 +00:00
|
|
|
to={link}
|
|
|
|
>
|
|
|
|
{!this.props.hideAvatar && community.icon && showAvatars() && (
|
2020-10-14 19:36:37 +00:00
|
|
|
<PictrsImage src={community.icon} icon />
|
2020-09-06 16:15:25 +00:00
|
|
|
)}
|
|
|
|
<span>{displayName}</span>
|
|
|
|
</Link>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|