commit 7fc29371b81daaa3f1cb14f001085b22100e341d
parent 4a83b2472310d9ac16d1f6aa488e4eb75dc28746
Author: I Mean I'm Just Saying <imeanimjustsaying@kiwifarms.st>
Date: Wed, 18 Nov 2026 06:38:02 -0500
common: PostBody in a file of its own -- the post viewer's body, its capture panel and `captureMediaKind` move to components/PostBody.tsx, and PostModal.tsx re-exports them, markup unchanged; a page with no modal and no query client around it draws a post as the viewer does
Co-Authored-By: Claude <noreply@anthropic.com>
Diffstat:
3 files changed, 326 insertions(+), 256 deletions(-)
diff --git a/common/components/PostBody.test.ts b/common/components/PostBody.test.ts
@@ -0,0 +1,55 @@
+// PostBody on its own (lane posts-library): the post viewer's body drawn with
+// no modal and no query client, and PostModal still exporting it.
+//
+// Run with: pnpm --filter yt-dlp-transcript-common exec tsx --test components/PostBody.test.ts
+
+import { test } from "node:test";
+import assert from "node:assert/strict";
+import * as React from "react";
+import { renderToStaticMarkup } from "react-dom/server";
+import { PostBody, PostCapturePanel } from "./PostBody";
+import * as modal from "./PostModal";
+import type { Post } from "../lib/posts";
+
+(globalThis as { React?: typeof React }).React = React;
+
+const POST: Post = {
+ id: "1900000000000001001",
+ slug: "lib/1900000000000001001",
+ channelSlug: "lib",
+ author: "teapot_news",
+ authorName: "Teapot News",
+ createdAt: "2026-11-16T12:00:00.000Z",
+ uploadDate: "20261116",
+ text: "The kettle festival opens today.",
+ url: "https://x.com/teapot_news/status/1900000000000001001",
+ platform: "twitter",
+ isReply: false,
+ isRepost: false,
+ links: ["https://example.org/a"],
+ mediaCount: 2,
+};
+
+test("a post is drawn with its author, words, links and footer; its captured media in the capture panel", () => {
+ const html = renderToStaticMarkup(
+ React.createElement(PostBody, {
+ post: POST,
+ capture: { capturedAt: "2026-11-17T10:00:00.000Z", state: "captured", shot: { src: "/m/shot.png" }, media: [{ src: "/m/a.jpg", name: "a.jpg" }, { src: "/m/b.mp4", name: "b.mp4" }] },
+ }),
+ );
+ assert.match(html, /data-post-id="1900000000000001001"/);
+ assert.match(html, /Teapot News/);
+ assert.match(html, /@teapot_news/);
+ assert.match(html, /The kettle festival opens today\./);
+ assert.match(html, /data-post-capture-shot=""/);
+ assert.match(html, /<video src="\/m\/b\.mp4"/);
+ assert.match(html, /2 media \(captured\)/);
+ assert.match(html, /Open original/);
+ // Not marked deleted: the word is nowhere.
+ assert.doesNotMatch(html, /deleted/i);
+});
+
+test("PostModal exports the same PostBody and capture panel", () => {
+ assert.equal(modal.PostBody, PostBody);
+ assert.equal(modal.PostCapturePanel, PostCapturePanel);
+});
diff --git a/common/components/PostBody.tsx b/common/components/PostBody.tsx
@@ -0,0 +1,267 @@
+"use client";
+
+// ONE POST, DRAWN: its author and time, its words, its captured screenshot
+// and media, its links and its footer. The body of the post viewer
+// (PostModal.tsx, which re-exports everything here), in a file of its own so
+// a page that shows posts with no modal and no query client around them
+// (umtool's Posts library) draws a post exactly as the viewer does.
+
+import { useMemo } from "react";
+import type { Post } from "../lib/posts";
+import { pageCaptureView } from "../lib/waybackPages/view";
+import { PageCaptureFacts } from "./PageCaptureFacts";
+
+export function formatWhen(iso: string): string {
+ const ms = Date.parse(iso);
+ if (!Number.isFinite(ms)) return iso;
+ const d = new Date(ms);
+ return d.toLocaleString(undefined, {
+ year: "numeric",
+ month: "short",
+ day: "numeric",
+ hour: "2-digit",
+ minute: "2-digit",
+ });
+}
+
+// A post's capture (a screenshot and its attached media, taken by the
+// editor's capture-posts job), as the page that renders this modal serves it.
+// EDITOR-ONLY: the files live beside the channel (`posts-media/<id>/`) and are
+// never published, so the export never passes `loadCapture` and never shows
+// any of this.
+export type PostCaptureView = {
+ capturedAt: string;
+ // The capture's state ("captured", "deleted", …), as recorded.
+ state: string;
+ // The post sat behind a sensitive-media cover when it was shot.
+ sensitive?: boolean;
+ shot?: { src: string };
+ media: { src: string; name: string }[];
+ // The X Article the post links to, when the capture opened it: its title,
+ // how that went, and its markdown when saved.
+ article?: { state: string; title?: string; md?: { src: string } };
+};
+
+export function PostBody({
+ post,
+ primary = false,
+ compact = false,
+ capture,
+}: {
+ post: Post;
+ primary?: boolean;
+ compact?: boolean;
+ capture?: PostCaptureView | null;
+}) {
+ const links = useMemo(() => post.links ?? [], [post.links]);
+ const capturedMedia = capture?.media.length ?? 0;
+ // A page record (a Wayback capture, release 37 S4): what the capture is,
+ // and the original named as possibly gone beside the Wayback copy.
+ const page = useMemo(() => pageCaptureView(post), [post]);
+ return (
+ <article
+ data-post-id={post.id}
+ className={
+ "rounded-md " +
+ (primary && compact ? "bg-warning-soft " : "") +
+ (compact ? "px-2 py-1.5" : "")
+ }
+ >
+ <header className="flex flex-wrap items-baseline gap-x-2 text-xs text-muted-foreground">
+ <span className="font-medium text-foreground">
+ {post.authorName || post.author}
+ </span>
+ {post.authorName && <span>@{post.author}</span>}
+ <span>·</span>
+ <time dateTime={post.createdAt}>{formatWhen(post.createdAt)}</time>
+ {post.isRepost && <Badge>repost</Badge>}
+ {/* Every forum post after the first answers the thread; the badge
+ would be on all of them. Its place in the thread says more. */}
+ {post.isReply && !post.forum && <Badge>reply</Badge>}
+ {post.forum?.position && <Badge>#{post.forum.position}</Badge>}
+ {post.forum?.editedAt && (
+ <span title={`Last edited ${formatWhen(post.forum.editedAt)}`}>
+ <Badge>edited</Badge>
+ </span>
+ )}
+ {/* The whole point of archiving: this post no longer exists upstream. */}
+ {post.isDeleted && (
+ <span
+ title={
+ post.availabilityCheckedAt
+ ? `Confirmed removed from the source (checked ${new Date(post.availabilityCheckedAt).toLocaleString()})`
+ : "Removed from the source platform"
+ }
+ className="rounded bg-rose-100 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-rose-800 dark:bg-rose-900/40 dark:text-rose-200"
+ >
+ deleted
+ </span>
+ )}
+ </header>
+
+ <p className={"whitespace-pre-wrap " + (compact ? "text-sm" : "text-base mt-2")}>
+ {post.text}
+ </p>
+
+ {capture && <PostCapturePanel capture={capture} />}
+
+ {page && !compact && <PageCaptureFacts view={page} links={false} className="mt-2" />}
+
+ {post.forum?.threadTitle && !compact && (
+ <p className="mt-1 text-xs text-muted-foreground">
+ In thread: {post.forum.threadTitle}
+ {post.forum.page ? ` · page ${post.forum.page}` : ""}
+ </p>
+ )}
+
+ {post.media && post.media.length > 0 && !capturedMedia && (
+ <ul data-post-media="" className="mt-2 flex flex-col gap-1">
+ {post.media.map((m) => (
+ <li key={`${m.kind}:${m.url}`} className="text-xs text-muted-foreground">
+ {m.kind}
+ {m.provider ? ` (${m.provider})` : ""}:{" "}
+ {/^https?:\/\//.test(m.url) ? (
+ <a
+ href={m.url}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-primary underline break-all"
+ >
+ {m.name || m.url}
+ </a>
+ ) : (
+ <span className="break-all">{m.name || m.url}</span>
+ )}
+ </li>
+ ))}
+ </ul>
+ )}
+
+ {links.length > 0 && (
+ <ul className="mt-2 flex flex-col gap-1">
+ {links.map((href) => (
+ <li key={href}>
+ <a
+ href={href}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="text-xs text-primary underline break-all"
+ >
+ {href}
+ </a>
+ </li>
+ ))}
+ </ul>
+ )}
+
+ <footer className="mt-2 flex flex-wrap items-center gap-x-3 text-xs text-muted-foreground">
+ {page ? (
+ <>
+ <a href={page.links.original.url} target="_blank" rel="noopener noreferrer" className="underline">
+ {post.isDeleted ? "Original (deleted)" : page.links.original.label}
+ </a>
+ <a href={page.links.copy.url} target="_blank" rel="noopener noreferrer" className="underline">
+ {page.links.copy.label}
+ </a>
+ </>
+ ) : (
+ <a
+ href={post.url}
+ target="_blank"
+ rel="noopener noreferrer"
+ className="underline"
+ >
+ {post.isDeleted ? "Original (deleted)" : "Open original"}
+ </a>
+ )}
+ {post.engagement?.likes != null && (
+ <span>{post.engagement.likes} likes</span>
+ )}
+ {post.engagement?.reposts != null && (
+ <span>{post.engagement.reposts} reposts</span>
+ )}
+ {post.engagement?.replies != null && (
+ <span>{post.engagement.replies} replies</span>
+ )}
+ {capturedMedia > 0 ? (
+ <span>{capturedMedia} media (captured)</span>
+ ) : post.mediaCount ? (
+ <span>{post.mediaCount} media (not archived)</span>
+ ) : null}
+ </footer>
+ </article>
+ );
+}
+
+function Badge({ children }: { children: React.ReactNode }) {
+ return (
+ <span className="rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase tracking-wide">
+ {children}
+ </span>
+ );
+}
+
+// What a captured file is, by its extension.
+export function captureMediaKind(name: string): "image" | "video" | "other" {
+ const ext = name.toLowerCase().split(".").pop() ?? "";
+ if (["jpg", "jpeg", "png", "gif", "webp", "avif"].includes(ext)) return "image";
+ if (["mp4", "webm", "mov", "m4v"].includes(ext)) return "video";
+ return "other";
+}
+
+// The captured screenshot and media of one post, and a line for its article.
+// Nothing when the capture holds none of them (a deleted post's record, say).
+export function PostCapturePanel({ capture }: { capture: PostCaptureView }) {
+ const { article } = capture;
+ if (!capture.shot && capture.media.length === 0 && !article) return null;
+ return (
+ <section data-post-capture="" className="mt-3 flex flex-col gap-2">
+ <h3 className="text-xs uppercase tracking-wide text-muted-foreground">
+ Captured {formatWhen(capture.capturedAt)}
+ {capture.sensitive ? " · behind a sensitive-media cover" : ""}
+ </h3>
+ {article && (
+ <p data-post-capture-article="" className="text-xs text-muted-foreground">
+ Article: {article.title ?? "untitled"}
+ {article.state !== "captured" ? ` (${article.state})` : ""}
+ {article.md && (
+ <>
+ {" · "}
+ <a href={article.md.src} className="text-primary underline">
+ article.md
+ </a>
+ </>
+ )}
+ </p>
+ )}
+ {capture.shot && (
+ <img
+ src={capture.shot.src}
+ alt="Screenshot of the post as captured"
+ data-post-capture-shot=""
+ className="max-w-full rounded-md border border-border"
+ />
+ )}
+ {capture.media.length > 0 && (
+ <ul className="flex flex-col gap-2">
+ {capture.media.map((m) => {
+ const kind = captureMediaKind(m.name);
+ return (
+ <li key={m.src} data-post-capture-media={kind}>
+ {kind === "image" ? (
+ <img src={m.src} alt={m.name} className="max-w-full rounded-md" />
+ ) : kind === "video" ? (
+ <video src={m.src} controls preload="metadata" className="max-w-full rounded-md" />
+ ) : (
+ <a href={m.src} className="text-xs text-primary underline break-all">
+ {m.name}
+ </a>
+ )}
+ </li>
+ );
+ })}
+ </ul>
+ )}
+ </section>
+ );
+}
diff --git a/common/components/PostModal.tsx b/common/components/PostModal.tsx
@@ -8,51 +8,22 @@
// that applies to a post. This renders the post, its thread context and its
// outbound links, and nothing else.
-import { useEffect, useMemo } from "react";
+import { useEffect } from "react";
import { useQuery } from "@tanstack/react-query";
import { XIcon } from "lucide-react";
import { Button } from "./ui/button";
import { useUrlParams, writeUrlParams } from "./urlState";
import { fetchPost, fetchThread } from "./postsCache";
import { postPlatformLabel, type Post } from "../lib/posts";
-import { pageCaptureView } from "../lib/waybackPages/view";
-import { PageCaptureFacts } from "./PageCaptureFacts";
+import { PostBody, type PostCaptureView } from "./PostBody";
-function formatWhen(iso: string): string {
- const ms = Date.parse(iso);
- if (!Number.isFinite(ms)) return iso;
- const d = new Date(ms);
- return d.toLocaleString(undefined, {
- year: "numeric",
- month: "short",
- day: "numeric",
- hour: "2-digit",
- minute: "2-digit",
- });
-}
+// The post itself is drawn by PostBody.tsx; its exports are this module's too.
+export { captureMediaKind, PostBody, PostCapturePanel, type PostCaptureView } from "./PostBody";
function platformLabel(platform: Post["platform"]): string {
return postPlatformLabel(platform);
}
-// A post's capture (a screenshot and its attached media, taken by the
-// editor's capture-posts job), as the page that renders this modal serves it.
-// EDITOR-ONLY: the files live beside the channel (`posts-media/<id>/`) and are
-// never published, so the export never passes `loadCapture` and never shows
-// any of this.
-export type PostCaptureView = {
- capturedAt: string;
- // The capture's state ("captured", "deleted", …), as recorded.
- state: string;
- // The post sat behind a sensitive-media cover when it was shot.
- sensitive?: boolean;
- shot?: { src: string };
- media: { src: string; name: string }[];
- // The X Article the post links to, when the capture opened it: its title,
- // how that went, and its markdown when saved.
- article?: { state: string; title?: string; md?: { src: string } };
-};
-
export type PostModalProps = {
// Where the editor reads a post's capture from. Absent (the export): no
// capture is looked for or shown.
@@ -157,226 +128,3 @@ export default function PostModal({ loadCapture }: PostModalProps = {}) {
);
}
-function PostBody({
- post,
- primary = false,
- compact = false,
- capture,
-}: {
- post: Post;
- primary?: boolean;
- compact?: boolean;
- capture?: PostCaptureView | null;
-}) {
- const links = useMemo(() => post.links ?? [], [post.links]);
- const capturedMedia = capture?.media.length ?? 0;
- // A page record (a Wayback capture, release 37 S4): what the capture is,
- // and the original named as possibly gone beside the Wayback copy.
- const page = useMemo(() => pageCaptureView(post), [post]);
- return (
- <article
- data-post-id={post.id}
- className={
- "rounded-md " +
- (primary && compact ? "bg-warning-soft " : "") +
- (compact ? "px-2 py-1.5" : "")
- }
- >
- <header className="flex flex-wrap items-baseline gap-x-2 text-xs text-muted-foreground">
- <span className="font-medium text-foreground">
- {post.authorName || post.author}
- </span>
- {post.authorName && <span>@{post.author}</span>}
- <span>·</span>
- <time dateTime={post.createdAt}>{formatWhen(post.createdAt)}</time>
- {post.isRepost && <Badge>repost</Badge>}
- {/* Every forum post after the first answers the thread; the badge
- would be on all of them. Its place in the thread says more. */}
- {post.isReply && !post.forum && <Badge>reply</Badge>}
- {post.forum?.position && <Badge>#{post.forum.position}</Badge>}
- {post.forum?.editedAt && (
- <span title={`Last edited ${formatWhen(post.forum.editedAt)}`}>
- <Badge>edited</Badge>
- </span>
- )}
- {/* The whole point of archiving: this post no longer exists upstream. */}
- {post.isDeleted && (
- <span
- title={
- post.availabilityCheckedAt
- ? `Confirmed removed from the source (checked ${new Date(post.availabilityCheckedAt).toLocaleString()})`
- : "Removed from the source platform"
- }
- className="rounded bg-rose-100 px-1.5 py-0.5 text-[10px] uppercase tracking-wide text-rose-800 dark:bg-rose-900/40 dark:text-rose-200"
- >
- deleted
- </span>
- )}
- </header>
-
- <p className={"whitespace-pre-wrap " + (compact ? "text-sm" : "text-base mt-2")}>
- {post.text}
- </p>
-
- {capture && <PostCapturePanel capture={capture} />}
-
- {page && !compact && <PageCaptureFacts view={page} links={false} className="mt-2" />}
-
- {post.forum?.threadTitle && !compact && (
- <p className="mt-1 text-xs text-muted-foreground">
- In thread: {post.forum.threadTitle}
- {post.forum.page ? ` · page ${post.forum.page}` : ""}
- </p>
- )}
-
- {post.media && post.media.length > 0 && !capturedMedia && (
- <ul data-post-media="" className="mt-2 flex flex-col gap-1">
- {post.media.map((m) => (
- <li key={`${m.kind}:${m.url}`} className="text-xs text-muted-foreground">
- {m.kind}
- {m.provider ? ` (${m.provider})` : ""}:{" "}
- {/^https?:\/\//.test(m.url) ? (
- <a
- href={m.url}
- target="_blank"
- rel="noopener noreferrer"
- className="text-primary underline break-all"
- >
- {m.name || m.url}
- </a>
- ) : (
- <span className="break-all">{m.name || m.url}</span>
- )}
- </li>
- ))}
- </ul>
- )}
-
- {links.length > 0 && (
- <ul className="mt-2 flex flex-col gap-1">
- {links.map((href) => (
- <li key={href}>
- <a
- href={href}
- target="_blank"
- rel="noopener noreferrer"
- className="text-xs text-primary underline break-all"
- >
- {href}
- </a>
- </li>
- ))}
- </ul>
- )}
-
- <footer className="mt-2 flex flex-wrap items-center gap-x-3 text-xs text-muted-foreground">
- {page ? (
- <>
- <a href={page.links.original.url} target="_blank" rel="noopener noreferrer" className="underline">
- {post.isDeleted ? "Original (deleted)" : page.links.original.label}
- </a>
- <a href={page.links.copy.url} target="_blank" rel="noopener noreferrer" className="underline">
- {page.links.copy.label}
- </a>
- </>
- ) : (
- <a
- href={post.url}
- target="_blank"
- rel="noopener noreferrer"
- className="underline"
- >
- {post.isDeleted ? "Original (deleted)" : "Open original"}
- </a>
- )}
- {post.engagement?.likes != null && (
- <span>{post.engagement.likes} likes</span>
- )}
- {post.engagement?.reposts != null && (
- <span>{post.engagement.reposts} reposts</span>
- )}
- {post.engagement?.replies != null && (
- <span>{post.engagement.replies} replies</span>
- )}
- {capturedMedia > 0 ? (
- <span>{capturedMedia} media (captured)</span>
- ) : post.mediaCount ? (
- <span>{post.mediaCount} media (not archived)</span>
- ) : null}
- </footer>
- </article>
- );
-}
-
-function Badge({ children }: { children: React.ReactNode }) {
- return (
- <span className="rounded bg-muted px-1.5 py-0.5 text-[10px] uppercase tracking-wide">
- {children}
- </span>
- );
-}
-
-// What a captured file is, by its extension.
-export function captureMediaKind(name: string): "image" | "video" | "other" {
- const ext = name.toLowerCase().split(".").pop() ?? "";
- if (["jpg", "jpeg", "png", "gif", "webp", "avif"].includes(ext)) return "image";
- if (["mp4", "webm", "mov", "m4v"].includes(ext)) return "video";
- return "other";
-}
-
-// The captured screenshot and media of one post, and a line for its article.
-// Nothing when the capture holds none of them (a deleted post's record, say).
-export function PostCapturePanel({ capture }: { capture: PostCaptureView }) {
- const { article } = capture;
- if (!capture.shot && capture.media.length === 0 && !article) return null;
- return (
- <section data-post-capture="" className="mt-3 flex flex-col gap-2">
- <h3 className="text-xs uppercase tracking-wide text-muted-foreground">
- Captured {formatWhen(capture.capturedAt)}
- {capture.sensitive ? " · behind a sensitive-media cover" : ""}
- </h3>
- {article && (
- <p data-post-capture-article="" className="text-xs text-muted-foreground">
- Article: {article.title ?? "untitled"}
- {article.state !== "captured" ? ` (${article.state})` : ""}
- {article.md && (
- <>
- {" · "}
- <a href={article.md.src} className="text-primary underline">
- article.md
- </a>
- </>
- )}
- </p>
- )}
- {capture.shot && (
- <img
- src={capture.shot.src}
- alt="Screenshot of the post as captured"
- data-post-capture-shot=""
- className="max-w-full rounded-md border border-border"
- />
- )}
- {capture.media.length > 0 && (
- <ul className="flex flex-col gap-2">
- {capture.media.map((m) => {
- const kind = captureMediaKind(m.name);
- return (
- <li key={m.src} data-post-capture-media={kind}>
- {kind === "image" ? (
- <img src={m.src} alt={m.name} className="max-w-full rounded-md" />
- ) : kind === "video" ? (
- <video src={m.src} controls preload="metadata" className="max-w-full rounded-md" />
- ) : (
- <a href={m.src} className="text-xs text-primary underline break-all">
- {m.name}
- </a>
- )}
- </li>
- );
- })}
- </ul>
- )}
- </section>
- );
-}