import styles from './Comment.module.scss' import { Icon } from '../_shared/Icon' import { AuthorCard } from '../Author/AuthorCard' import { Show, createMemo, createSignal, For, lazy, Suspense } from 'solid-js' import { clsx } from 'clsx' import type { Author, Reaction } from '../../graphql/types.gen' import MD from './MD' import { formatDate } from '../../utils' import Userpic from '../Author/Userpic' import { useSession } from '../../context/session' import { ReactionKind } from '../../graphql/types.gen' import { useReactions } from '../../context/reactions' import { useSnackbar } from '../../context/snackbar' import { ShowIfAuthenticated } from '../_shared/ShowIfAuthenticated' import { useLocalize } from '../../context/localize' import { CommentRatingControl } from './CommentRatingControl' const CommentEditor = lazy(() => import('../_shared/CommentEditor')) type Props = { comment: Reaction compact?: boolean isArticleAuthor?: boolean sortedComments?: Reaction[] lastSeen?: Date } export const Comment = (props: Props) => { const { t } = useLocalize() const [isReplyVisible, setIsReplyVisible] = createSignal(false) const [loading, setLoading] = createSignal(false) const [editMode, setEditMode] = createSignal(false) const [submitted, setSubmitted] = createSignal(false) const { session } = useSession() const { actions: { createReaction, deleteReaction, updateReaction } } = useReactions() const { actions: { showSnackbar } } = useSnackbar() const isCommentAuthor = createMemo(() => props.comment.createdBy?.slug === session()?.user?.slug) const comment = createMemo(() => props.comment) const body = createMemo(() => (comment().body || '').trim()) const remove = async () => { if (comment()?.id) { try { await deleteReaction(comment().id) showSnackbar({ body: t('Comment successfully deleted') }) } catch (error) { console.error('[deleteReaction]', error) } } } const handleCreate = async (value) => { try { setLoading(true) await createReaction({ kind: ReactionKind.Comment, replyTo: props.comment.id, body: value, shout: props.comment.shout.id }) setIsReplyVisible(false) setLoading(false) setSubmitted(true) } catch (error) { console.error('[handleCreate reaction]:', error) } } const formattedDate = (date) => createMemo(() => formatDate(new Date(date), { hour: 'numeric', minute: 'numeric' })) const toggleEditMode = () => { setEditMode((oldEditMode) => !oldEditMode) } const handleUpdate = async (value) => { setLoading(true) try { await updateReaction(props.comment.id, { kind: ReactionKind.Comment, body: value, shout: props.comment.shout.id }) setEditMode(false) setLoading(false) } catch (error) { console.error('[handleCreate reaction]:', error) } } const createdAt = new Date(comment()?.createdAt) return (
  • props.lastSeen })}> } >
    {t('Author')}
    {formattedDate(comment()?.createdAt)()}
    {t('Edited')} {formattedDate(comment()?.updatedAt)()}
    }> {t('Loading')}

    }> handleUpdate(value)} />
    {/**/} {/* */} {/* {t('Share')}*/} {/* */} {/* }*/} {/*/>*/} {/* showModal('reportComment')}*/} {/*>*/} {/* {t('Report')}*/} {/**/}
    {t('Loading')}

    }> handleCreate(value)} cancel={() => setIsReplyVisible(false)} />
      r.replyTo === props.comment.id)}> {(c) => ( )}
  • ) }