import React, { useState } from 'react'
import ReactButton from './reactButton.js'
import styles from './comments.module.css'
function CommentInput({ onSubmit }) {
const [val, setVal] = useState('')
return (
)
}
function Comment({ comment, index, onComment, onDelete, onReact, uid }) {
const [displayed, setDisplayed] = useState(true)
const [commenting, setCommenting] = useState(false)
const { text, subComments, date, user, reacts } = comment
const own = uid === user
return (
{
setDisplayed(!displayed)
}}
>
{displayed ? '[-]' : '[+]'}
User #{user}
{date}
{text}
{
setCommenting(true)
}}
>
Reply...
{own && (
{
onDelete([index])
}}
>
Delete
)}
{
onReact([index], reaction, isDelete)
}}
uid={uid}
existingReacts={reacts}
/>
{commenting && (
{
onComment([index], e)
setCommenting(false)
}}
/>
)}
{subComments &&
subComments.map((sc, i) => {
return (
{
onReact([...path, index], reaction, isDelete)
}}
onDelete={(path) => {
onDelete([...path, index])
}}
onComment={(path, text) => {
onComment([...path, index], text)
}}
index={i}
key={i}
uid={uid}
/>
)
})}
)
}
export default function Comments({
comments,
onComment,
onDelete,
onReact,
uid,
}) {
const [addingNewComment, setAddingNewComment] = useState(false)
return (
{comments && comments.length > 0 ? (
comments.map((comment, i) => {
return (
)
})
) : (
)}
{addingNewComment ? (
{
setAddingNewComment(false)
onComment([], e)
}}
/>
) : (
{
setAddingNewComment(true)
}}
className={styles.button}
>
Add new
)}
)
}