2023-06-21 22:28:24 +00:00
|
|
|
import { showAvatars } from "@utils/app";
|
|
|
|
import { hostname } from "@utils/helpers";
|
2021-02-22 02:39:04 +00:00
|
|
|
import { Component } from "inferno";
|
|
|
|
import { Link } from "inferno-router";
|
2023-05-11 18:32:32 +00:00
|
|
|
import { Community } from "lemmy-js-client";
|
2023-06-21 22:28:24 +00:00
|
|
|
import { relTags } from "../../config";
|
2021-07-17 20:42:55 +00:00
|
|
|
import { PictrsImage } from "../common/pictrs-image";
|
2020-09-06 16:15:25 +00:00
|
|
|
|
|
|
|
interface CommunityLinkProps {
|
2023-05-11 18:32:32 +00:00
|
|
|
community: Community;
|
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() {
|
2023-06-05 21:31:12 +00:00
|
|
|
const community = this.props.community;
|
2021-01-23 22:23:49 +00:00
|
|
|
let name_: string, title: string, link: string;
|
2023-06-05 21:31:12 +00:00
|
|
|
const local = community.local == null ? true : community.local;
|
2020-09-06 16:15:25 +00:00
|
|
|
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 {
|
2023-06-05 21:31:12 +00:00
|
|
|
const domain = hostname(community.actor_id);
|
2021-07-21 15:01:32 +00:00
|
|
|
name_ = `${community.name}@${domain}`;
|
|
|
|
title = `${community.title}@${domain}`;
|
|
|
|
link = !this.props.realLink ? `/c/${name_}` : community.actor_id;
|
2020-09-06 16:15:25 +00:00
|
|
|
}
|
|
|
|
|
2023-06-05 21:31:12 +00:00
|
|
|
const apubName = `!${name_}`;
|
|
|
|
const displayName = this.props.useApubName ? apubName : title;
|
2021-05-05 14:57:41 +00:00
|
|
|
return !this.props.realLink ? (
|
2020-09-06 16:15:25 +00:00
|
|
|
<Link
|
|
|
|
title={apubName}
|
2023-06-20 18:46:16 +00:00
|
|
|
className={`community-link ${this.props.muted ? "text-muted" : ""}`}
|
2020-09-06 16:15:25 +00:00
|
|
|
to={link}
|
|
|
|
>
|
2021-05-05 14:57:41 +00:00
|
|
|
{this.avatarAndName(displayName)}
|
|
|
|
</Link>
|
|
|
|
) : (
|
|
|
|
<a
|
|
|
|
title={apubName}
|
2023-06-20 18:46:16 +00:00
|
|
|
className={`community-link ${this.props.muted ? "text-muted" : ""}`}
|
2021-05-05 14:57:41 +00:00
|
|
|
href={link}
|
2022-02-24 15:31:44 +00:00
|
|
|
rel={relTags}
|
2021-05-05 14:57:41 +00:00
|
|
|
>
|
|
|
|
{this.avatarAndName(displayName)}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
avatarAndName(displayName: string) {
|
2023-06-05 21:31:12 +00:00
|
|
|
const icon = this.props.community.icon;
|
2021-05-05 14:57:41 +00:00
|
|
|
return (
|
|
|
|
<>
|
2023-03-27 02:10:35 +00:00
|
|
|
{!this.props.hideAvatar &&
|
|
|
|
!this.props.community.removed &&
|
|
|
|
showAvatars() &&
|
|
|
|
icon && <PictrsImage src={icon} icon />}
|
2022-09-22 15:03:35 +00:00
|
|
|
<span className="overflow-wrap-anywhere">{displayName}</span>
|
2021-05-05 14:57:41 +00:00
|
|
|
</>
|
2020-09-06 16:15:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|