import config from "../config.ts"; import { displayName } from "../lib/users.ts"; import type { SessionUser } from "../middleware/session.ts"; import { Avatar } from "./Avatar.tsx"; import { DateWithEdited } from "./DateWithEdited.tsx"; import { ReactionBar, type ReactionCount } from "./ReactionBar.tsx"; export interface ThreadComment { id: number; author_id: number | null; author_username: string; author_avatar_version: number | null; body: string; bodyHtml: string; created_at: string; edited_at: string | null; } interface CommentThreadProps { user: SessionUser | null; comments: ThreadComment[]; commentReactions: Map; baseUrl: string; parentStatus: string; } export function CommentThread({ user, comments, commentReactions, baseUrl, parentStatus, }: CommentThreadProps) { const reactUrl = `${baseUrl}/react`; const canEditComment = (c: ThreadComment) => user != null && (user.isAdmin || (user.id === c.author_id && parentStatus === "open")); return ( <> {comments.map((comment) => (
{displayName(comment.author_username)}
{canEditComment(comment) && (
Edit Stop editing
)}
{canEditComment(comment) && (
)}
{comment.bodyHtml as "safe"}
))} {!!user && (

Add a comment