{post.title}
: null}{post.text ?? post.content}
{error}
: null}import { useEffect, useState } from "react"; import { Link } from "react-router-dom"; function getImageFilename(post) { return post.image || post.image_filename || post.filename || null; } function getAuthorName(post, authorId) { return post.author?.name || post.author_name || (post.author_username ? `@${post.author_username}` : `User ${authorId || ""}`); } function getAuthorUsername(post) { return post.author_username || post.author?.username || null; } function getInitials(name) { if (!name) return "?"; const cleaned = name.replace(/^@/, ""); return cleaned .split(" ") .filter(Boolean) .slice(0, 2) .map((part) => part[0]) .join("") .toUpperCase() || "?"; } function formatDate(timestamp) { if (!timestamp) return null; try { const date = new Date(timestamp); if (Number.isNaN(date.getTime())) return String(timestamp); return new Intl.DateTimeFormat("en-US", { month: "short", day: "numeric", year: "numeric", hour: "numeric", minute: "2-digit", }).format(date); } catch { return String(timestamp); } } function AuthenticatedImage({ filename, alt, loadImage }) { const [source, setSource] = useState(""); const [error, setError] = useState(""); useEffect(() => { let active = true; let objectUrl = ""; if (!filename) { setSource(""); return () => {}; } loadImage(filename) .then((blob) => { if (active) { objectUrl = URL.createObjectURL(blob); setSource(objectUrl); } }) .catch(() => { if (active) { setError("Image unavailable."); } }); return () => { active = false; if (objectUrl) { URL.revokeObjectURL(objectUrl); } }; }, [filename, loadImage]); if (error) { return
{error}
; } return source ?{post.text ?? post.content}
{error}
: null}