tutu/src/timelines/CompactToot.tsx

58 lines
1.7 KiB
TypeScript
Raw Normal View History

2024-07-14 20:28:44 +08:00
import type { mastodon } from "masto";
2024-08-17 18:09:55 +08:00
import { Show, type Component } from "solid-js";
2024-07-14 20:28:44 +08:00
import tootStyle from "./toot.module.css";
import { formatRelative } from "date-fns";
import Img from "../material/Img";
import { Body2 } from "../material/typography";
import { appliedCustomEmoji } from "../masto/toot";
2024-08-17 18:09:55 +08:00
import { TootPreviewCard } from "./RegularToot";
2024-07-14 20:28:44 +08:00
type CompactTootProps = {
status: mastodon.v1.Status;
now: Date;
class?: string;
};
const CompactToot: Component<CompactTootProps> = (props) => {
const toot = () => props.status;
return (
<section
2024-08-17 17:16:18 +08:00
class={[tootStyle.toot, tootStyle.compact, props.class || ""].join(" ")}
2024-07-14 20:28:44 +08:00
lang={toot().language || undefined}
>
<Img
src={toot().account.avatar}
2024-08-05 15:33:00 +08:00
class={[tootStyle.tootAvatar].join(" ")}
2024-07-14 20:28:44 +08:00
/>
2024-08-05 15:33:00 +08:00
<div class={[tootStyle.compactAuthorGroup].join(" ")}>
2024-07-14 20:28:44 +08:00
<Body2
ref={(e: { innerHTML: string }) => {
appliedCustomEmoji(
e,
toot().account.displayName,
toot().account.emojis,
);
}}
></Body2>
<span class={tootStyle.compactAuthorUsername}>
@{toot().account.username}@{new URL(toot().account.url).hostname}
</span>
<time datetime={toot().createdAt}>
{formatRelative(props.now, toot().createdAt)}
2024-07-14 20:28:44 +08:00
</time>
</div>
<div
ref={(e: { innerHTML: string }) => {
appliedCustomEmoji(e, toot().content, toot().emojis);
}}
2024-08-05 15:33:00 +08:00
class={[tootStyle.compactTootContent].join(" ")}
2024-07-14 20:28:44 +08:00
></div>
2024-08-17 18:09:55 +08:00
<Show when={toot().card}>
<TootPreviewCard src={toot().card!} alwaysCompact />
</Show>
2024-07-14 20:28:44 +08:00
</section>
);
};
export default CompactToot;