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 { useState } from 'react' import { gql, useQuery } from '@apollo/client' import { timeSince } from '../lib/time' import UpVote from './upvote' function Parent ({ item }) { const { data } = useQuery( gql`{ root(id: ${item.id}) { id title } }` ) const ParentFrag = () => ( <> \ parent ) if (!data) { return } return ( <> {data.root.id !== item.parentId && } \ {data.root.title} ) } export default function Comment ({ item, children, replyOpen, includeParent, cacheId, noReply }) { const [reply, setReply] = useState(replyOpen) return ( <>
@{item.user.name} {timeSince(new Date(item.createdAt))} \ {item.sats} sats \ {item.ncomments} replies {includeParent && }
{item.text}
{!noReply &&
setReply(!reply)} > {reply ? 'cancel' : 'reply'}
} {reply && setReply(replyOpen || false)} cacheId={cacheId} />} {children}
{item.comments ? item.comments.map((item) => ( )) : null}
) } export function CommentSkeleton ({ skeletonChildren }) { const comments = skeletonChildren ? new Array(2).fill(null) : [] return ( <>
{comments ? comments.map((_, i) => ( )) : null}
) }