import itemStyles from './item.module.css'
import styles from './comment.module.css'
import Text from './text'
import Link from 'next/link'
import Reply from './reply'
import { useEffect, useRef, useState } from 'react'
import { timeSince } from '../lib/time'
import UpVote from './upvote'
import Eye from '../svgs/eye-fill.svg'
import EyeClose from '../svgs/eye-close-line.svg'
import { useRouter } from 'next/router'
function Parent ({ item }) {
const ParentFrag = () => (
<>
\
e.stopPropagation()} className='text-reset'>parent
>
)
if (!item.root) {
return
}
return (
<>
{Number(item.root.id) !== Number(item.parentId) && }
\
e.stopPropagation()} className='text-reset'>root: {item.root.title}
>
)
}
export default function Comment ({ item, children, replyOpen, includeParent, cacheId, noComments, noReply, clickToContext }) {
const [reply, setReply] = useState(replyOpen)
const [collapse, setCollapse] = useState(false)
const ref = useRef(null)
const router = useRouter()
useEffect(() => {
if (Number(router.query.commentId) === Number(item.id)) {
ref.current.scrollIntoView()
// ref.current.classList.add('flash-it')
}
}, [item])
return (
{
if (clickToContext) {
router.push(`/items/${item.parentId}?commentId=${item.id}`, `/items/${item.parentId}`)
}
}} className={includeParent ? `${clickToContext ? styles.clickToContext : ''}` : `${styles.comment} ${collapse ? styles.collapsed : ''}`}
>
{!includeParent && (collapse
?
setCollapse(false)} />
: setCollapse(true)} />)}
{item.text}
{!noReply &&
setReply(!reply)}
>
{reply ? 'cancel' : 'reply'}
}
setReply(replyOpen || false)} cacheId={cacheId}
/>
{children}
{item.comments && !noComments
? item.comments.map((item) => (
))
: null}
)
}
export function CommentSkeleton ({ skeletonChildren }) {
return (
{skeletonChildren
?
: null}
)
}