import styles from './Comment.module.scss' import { Icon } from '../_shared/Icon' import { AuthorCard } from '../Author/Card' import { Show, createMemo, createSignal, For, lazy, Suspense } from 'solid-js' import { clsx } from 'clsx' import type { Author, Reaction } from '../../graphql/types.gen' import { t } from '../../utils/intl' import { createReaction, deleteReaction, updateReaction } from '../../stores/zine/reactions' import MD from './MD' import { formatDate } from '../../utils' import Userpic from '../Author/Userpic' import { useSession } from '../../context/session' import { ReactionKind } from '../../graphql/types.gen' const CommentEditor = lazy(() => import('../_shared/CommentEditor')) type Props = { comment: Reaction compact?: boolean reactions?: Reaction[] isArticleAuthor?: boolean } export const Comment = (props: Props) => { const [isReplyVisible, setIsReplyVisible] = createSignal(false) const [loading, setLoading] = createSignal(false) const [editMode, setEditMode] = 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) setLoading(false) } 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) } } return (
  • } >
    {t('Author')}
    {formattedDate(comment()?.createdAt)}
    {t('Edited')} {formattedDate(comment()?.updatedAt)}
    0, [styles.commentRatingNegative]: comment().stat?.rating < 0 }} >
    }> {t('Loading')}

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

    }> handleCreate(value)} />
      r.replyTo === props.comment.id)}> {(reaction) => ( )}
  • ) } export default Comment