import { useEffect, useRef, useState } from 'react' import type { ThreadSnap } from './model' import type { CollabUser } from '../collab/user' function timeAgo(ts: number): string { const s = Math.floor((Date.now() - ts) / 1000) if (s < 60) return 'just now' const m = Math.floor(s / 60) if (m < 60) return `${m}m` const h = Math.floor(m / 60) if (h < 24) return `${h}h` return `${Math.floor(h / 24)}d` } export interface NewComment { quote: string } export function CommentsPanel({ threads, me, activeId, composing, onSubmitNew, onCancelNew, onReply, onResolve, onDelete, onFocus, onClose, }: { threads: ThreadSnap[] me: CollabUser activeId: string | null composing: NewComment | null onSubmitNew: (text: string) => void onCancelNew: () => void onReply: (threadId: string, text: string) => void onResolve: (threadId: string, resolved: boolean) => void onDelete: (threadId: string) => void onFocus: (thread: ThreadSnap) => void onClose: () => void }) { const open = threads.filter((t) => !t.resolved) const resolved = threads.filter((t) => t.resolved) open.sort((a, b) => (a.from ?? Infinity) - (b.from ?? Infinity)) return ( ) } function NewCommentCard({ composing, onSubmit, onCancel, }: { composing: NewComment onSubmit: (text: string) => void onCancel: () => void }) { const [text, setText] = useState('') const ref = useRef(null) useEffect(() => ref.current?.focus(), []) return (
{composing.quote &&
“{composing.quote}”
}