lemmy-ui/src/shared/components/person/person-listing.tsx

85 lines
2.1 KiB
TypeScript
Raw Normal View History

2021-02-22 02:39:04 +00:00
import { Component } from "inferno";
import { Link } from "inferno-router";
2021-03-15 18:09:31 +00:00
import { PersonSafe } from "lemmy-js-client";
import { hostname, isCakeDay, showAvatars } from "../../utils";
import { PictrsImage } from "../common/pictrs-image";
2021-02-22 02:39:04 +00:00
import { CakeDay } from "./cake-day";
2021-03-15 18:09:31 +00:00
interface PersonListingProps {
person: PersonSafe;
realLink?: boolean;
useApubName?: boolean;
muted?: boolean;
hideAvatar?: boolean;
showApubName?: boolean;
}
2021-03-15 18:09:31 +00:00
export class PersonListing extends Component<PersonListingProps, any> {
constructor(props: any, context: any) {
super(props, context);
}
render() {
2021-03-15 18:09:31 +00:00
let person = this.props.person;
let local = person.local == null ? true : person.local;
let apubName: string, link: string;
if (local) {
2021-03-15 18:09:31 +00:00
apubName = `@${person.name}`;
link = `/u/${person.name}`;
} else {
let domain = hostname(person.actor_id);
apubName = `@${person.name}@${domain}`;
link = !this.props.realLink
? `/u/${person.name}@${domain}`
: person.actor_id;
}
let displayName = this.props.useApubName
? apubName
: person.display_name
? person.display_name
: apubName;
if (this.props.showApubName && !local && person.display_name) {
displayName = `${displayName} (${apubName})`;
}
return (
<>
{!this.props.realLink ? (
<Link
title={apubName}
className={this.props.muted ? "text-muted" : "text-info"}
to={link}
>
{this.avatarAndName(displayName)}
</Link>
) : (
<a
title={apubName}
className={this.props.muted ? "text-muted" : "text-info"}
href={link}
>
{this.avatarAndName(displayName)}
</a>
)}
2021-03-15 18:09:31 +00:00
{isCakeDay(person.published) && <CakeDay creatorName={apubName} />}
</>
);
}
avatarAndName(displayName: string) {
let person = this.props.person;
return (
<>
{!this.props.hideAvatar && person.avatar && showAvatars() && (
<PictrsImage src={person.avatar} icon />
)}
<span>{displayName}</span>
</>
);
}
}