lemmy-ui/src/shared/components/community/community-link.tsx

70 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-02-22 02:39:04 +00:00
import { Component } from "inferno";
import { Link } from "inferno-router";
import { Community } from "lemmy-js-client";
import { hostname, relTags, showAvatars } from "../../utils";
import { PictrsImage } from "../common/pictrs-image";
interface CommunityLinkProps {
community: Community;
realLink?: boolean;
useApubName?: boolean;
muted?: boolean;
hideAvatar?: boolean;
}
export class CommunityLink extends Component<CommunityLinkProps, any> {
constructor(props: any, context: any) {
super(props, context);
}
render() {
2023-06-05 21:31:12 +00:00
const community = this.props.community;
let name_: string, title: string, link: string;
2023-06-05 21:31:12 +00:00
const local = community.local == null ? true : community.local;
if (local) {
name_ = community.name;
title = community.title;
link = `/c/${community.name}`;
} else {
2023-06-05 21:31:12 +00:00
const domain = hostname(community.actor_id);
name_ = `${community.name}@${domain}`;
title = `${community.title}@${domain}`;
link = !this.props.realLink ? `/c/${name_}` : community.actor_id;
}
2023-06-05 21:31:12 +00:00
const apubName = `!${name_}`;
const displayName = this.props.useApubName ? apubName : title;
return !this.props.realLink ? (
<Link
title={apubName}
2023-06-20 18:46:16 +00:00
className={`community-link ${this.props.muted ? "text-muted" : ""}`}
to={link}
>
{this.avatarAndName(displayName)}
</Link>
) : (
<a
title={apubName}
2023-06-20 18:46:16 +00:00
className={`community-link ${this.props.muted ? "text-muted" : ""}`}
href={link}
rel={relTags}
>
{this.avatarAndName(displayName)}
</a>
);
}
avatarAndName(displayName: string) {
2023-06-05 21:31:12 +00:00
const icon = this.props.community.icon;
return (
<>
{!this.props.hideAvatar &&
!this.props.community.removed &&
showAvatars() &&
icon && <PictrsImage src={icon} icon />}
<span className="overflow-wrap-anywhere">{displayName}</span>
</>
);
}
}