import styles from './Comment.module.scss' import { Icon } from '../_shared/Icon' import { AuthorCard } from '../Author/Card' import { Show, createMemo, createSignal, For } from 'solid-js' import { clsx } from 'clsx' import type { Author, Reaction } from '../../graphql/types.gen' import { t } from '../../utils/intl' import { createReaction, deleteReaction } from '../../stores/zine/reactions' import MD from './MD' import { formatDate } from '../../utils' import { SharePopup } from './SharePopup' import stylesHeader from '../Nav/Header.module.scss' import Userpic from '../Author/Userpic' import { useSession } from '../../context/session' import { ReactionKind } from '../../graphql/types.gen' import CommentEditor from '../_shared/CommentEditor' import { ShowOnlyOnClient } from '../_shared/ShowOnlyOnClient' type Props = { comment: Reaction compact?: boolean reactions?: Reaction[] isArticleAuthor?: boolean } const Comment = (props: Props) => { const [isReplyVisible, setIsReplyVisible] = createSignal(false) const [loading, setLoading] = createSignal(false) const [submitted, setSubmitted] = createSignal(false) const { session } = useSession() const canEdit = 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) } 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 }, { name: session().user.name, userpic: session().user.userpic, slug: session().user.slug } ) setIsReplyVisible(false) setSubmitted(true) setLoading(false) } catch (error) { console.error('[handleCreate reaction]:', error) } } const formattedDate = createMemo(() => formatDate(new Date(comment()?.createdAt), { hour: 'numeric', minute: 'numeric' }) ) return (
  • } >
    {t('Author')}
    {formattedDate()}
    0, [styles.commentRatingNegative]: comment().stat?.rating < 0 }} >
    {/*FIXME implement edit comment modal*/} {/* showModal('editComment')}*/} {/*>*/} {/* */} {/* {t('Edit')}*/} {/**/} {t('Share')} } /> {/* showModal('reportComment')}*/} {/*>*/} {/* {t('Report')}*/} {/**/}
    handleCreate(value)} />
      r.replyTo === props.comment.id)}> {(reaction) => ( )}
  • ) } export default Comment