/** * Copyright (c) 2025 adoravel * SPDX-License-Identifier: AGPL-3.0-or-later */ import { css } from "~/lib/css.ts"; import { ease, fontFamily, fontSize, radius, spacing, theme } from "~/layout.tsx"; import type { Post, TextSegment } from "~/content/post.ts"; import { type Profile } from "~/services/post.ts"; import { Bluesky } from "~/components/ui/Icon.tsx"; import { flattenThread, formatPostDate } from "~/util/formatting.ts"; const Styled = css(` :scope { position: relative; display: flex; flex-direction: column; background: ${theme.base}; border: 1px solid ${theme.baseBorder}; border-radius: ${radius.lg}; padding: ${spacing[4]} ${spacing[5]}; text-decoration: none; color: inherit; transform: translateY(0px); transition: transform ${ease.spring}, box-shadow ${ease.spring}, border-color ${ease.fast}, background-color ${ease.fast}; &:hover { border-color: ${theme.surfaceBorderHover}; background-color: ${theme.surfaceHover}; transform: translateY(-4px); box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45); } } .post-inner { display: flex; gap: ${spacing[3]}; } .pfp-wrapper { perspective: 600px; flex-shrink: 0; width: 48px; height: 48px; } .pfp-card { position: relative; width: 100%; height: 100%; transform-style: preserve-3d; transition: transform ${ease.spring}; cursor: pointer; } :scope:hover .pfp-card { transform: rotateY(180deg); } .pfp-face { position: absolute; inset: 0; backface-visibility: hidden; border-radius: 50%; background: ${theme.surface}; display: flex; align-items: center; justify-content: center; color: ${theme.textMuted}; border: 1px solid ${theme.baseBorder}; overflow: hidden; img { width: 100%; height: 100%; object-fit: cover; } } .pfp-back { transform: rotateY(180deg); background: ${theme.lift}; color: ${theme.textMuted}; } .content-col { flex: 1; min-width: 0; } .header { display: flex; align-items: center; flex-wrap: wrap; gap: ${spacing[1]}; } .name { font-weight: 600; color: ${theme.text}; font-size: ${fontSize.md}; } .handle { color: ${theme.textMuted}; font-size: ${fontSize.sm}; } .body { display: inline; color: ${theme.subtext}; font-size: ${fontSize.body}; white-space: pre-wrap; word-break: break-word; } .body a { color: ${theme.accent}; text-decoration: none; &::after { display: none !important; } } .body .tl-hashtag { color: ${theme.accent}; } .thread-indicator { display: inline-flex; align-items: center; vertical-align: middle; gap: ${spacing[2]}; margin-left: 1ch; color: ${theme.accent}; font-size: ${fontSize.sm}; font-weight: 500; svg { width: 12px; height: 12px; } } .footer { display: flex; align-items: center; gap: ${spacing[3]}; margin-top: ${spacing[3]}; padding-top: ${spacing[2]}; border-top: 1px solid ${theme.baseBorder}; font-size: ${fontSize.xs}; color: ${theme.textMuted}; font-family: ${fontFamily.misc}; letter-spacing: ${spacing.letter.misc}; } `); function renderSegments(segments: TextSegment[]) { return segments.map((seg, i) => { switch (seg.type) { case "link": return ( e.stopPropagation()} > {seg.text} ); case "mention": return ( e.stopPropagation()} > {seg.text} ); case "tag": return ( e.stopPropagation()} > {seg.text} ); default: return seg.text; } }); } function Knot() { return ( More posts ); } function truncateSegments(segments: TextSegment[]): TextSegment[] { if (!segments.length) return segments; const last = segments[segments.length - 1]; if (last.type !== "text" || !last.text) return segments; const text = last.text.replace(/[.,]+\s*$/, ""); return [ ...segments.slice(0, -1), { ...last, text: text + "…" }, ]; } export default function TimelinePost({ post, profile }: { post: Post; profile: Profile }) { const hasReplies = post.replies && post.replies.length > 0; const items = flattenThread(post); return ( {profile.avatarUrl ? : } {profile.displayName} @{profile.handle ?? "handle.invalid"} {renderSegments(truncateSegments(post.segments))} {hasReplies && ( {items.length - 1} more {(items.length - 1) === 1 ? "skeet" : "more skeets"}{" "} in this thread )} ); }