import { useEffect, useRef, useState } from 'react'; import MessageInput from './MessageInput'; import Avatar from './Avatar'; import { UserLink } from './UserInfo'; import Button from './Button'; import { format, embedUrls } from '../utils/embed'; import { chatItemStyle } from './helpers/BubbleStyle'; import { useVisitor } from './VisitorContext'; /** * @param {{ visitor: import('../client').SecureUser, msg: import('../client').Message, draft: string, active: number, setActive: Function, onStartEditing: Function, postComment: function({body:string, attach: string | File}) : void }} props props * @returns React.ReactElement */ export default function Comment({ msg, draft, active, setActive, onStartEditing, postComment }) { const [visitor] = useVisitor(); /** @type {React.MutableRefObject} */ const embedRef = useRef(null); /** @type {React.MutableRefObject} */ const msgRef = useRef(null); const [author] = useState(msg.user); useEffect(() => { if (msgRef.current && embedRef.current) { embedUrls(msgRef.current.querySelectorAll('a'), embedRef.current); if (!embedRef.current.hasChildNodes()) { embedRef.current.style.display = 'none'; } } }, []); return (
{ msg.to && msg.replyto && msg.replyto > 0 && ( ) }
{ msg.body &&

= 0) }} />

} { msg.photo &&
}
{ active === msg.rid && }
{ visitor.uid > 0 ? ( <> {active === msg.rid || setActive(msg.rid)}>Reply} { visitor.uid == msg.user.uid && <>  ·  onStartEditing(msg)}>Edit } ) : ( <>  · {active === msg.rid || } ) }
); } /** * @type {React.CSSProperties} */ const linkStyle = { cursor: 'pointer' };