diff --git a/src/components/Article/Comment.module.scss b/src/components/Article/Comment.module.scss index e1ae44ba..2172b0ba 100644 --- a/src/components/Article/Comment.module.scss +++ b/src/components/Article/Comment.module.scss @@ -1,18 +1,40 @@ .comment { background-color: #fff; - margin: 0 -2.4rem 1.5em; + margin: 0 -2.4rem 0.5em; padding: 0.8rem 2.4rem; transition: background-color 0.3s; + position: relative; - &:hover { - background-color: #f6f6f6; + &:last-child { + margin-bottom: 0; + } - .commentControlReply, - .commentControlShare, - .commentControlDelete, - .commentControlEdit, - .commentControlComplain { - opacity: 1; + .comment { + &:before, + &:after { + content: ''; + left: 0; + position: absolute; + } + + &:before { + border-bottom: 2px solid #ccc; + border-left: 2px solid #ccc; + border-radius: 0 0 0 1.2rem; + top: -1rem; + height: 2.4rem; + width: 1.2rem; + } + + &:after { + background: #ccc; + height: 100%; + top: 0; + width: 2px; + } + + &:last-child:after { + display: none; } } @@ -32,24 +54,16 @@ } } -.commentLevel1 { - margin-left: 3.2rem; -} - -.commentLevel2 { - margin-left: 6.4rem; -} - -.commentLevel3 { - margin-left: 9.6rem; -} - -.commentLevel4 { - margin-left: 12.8rem; -} - -.commentLevel5 { - margin-left: 16rem; +.commentContent { + &:hover { + .commentControlReply, + .commentControlShare, + .commentControlDelete, + .commentControlEdit, + .commentControlComplain { + opacity: 1; + } + } } .commentControls { diff --git a/src/components/Article/Comment.tsx b/src/components/Article/Comment.tsx index 0b3e5ee9..53e97dc3 100644 --- a/src/components/Article/Comment.tsx +++ b/src/components/Article/Comment.tsx @@ -1,25 +1,32 @@ import styles from './Comment.module.scss' import { Icon } from '../_shared/Icon' import { AuthorCard } from '../Author/Card' -import { Show, createMemo, createSignal } from 'solid-js' +import { Show, createMemo, createSignal, For } from 'solid-js' import { clsx } from 'clsx' -import type { Author, Reaction as Point } from '../../graphql/types.gen' +import type { Author, Reaction } from '../../graphql/types.gen' import { t } from '../../utils/intl' -// import { createReaction, updateReaction, deleteReaction } from '../../stores/zine/reactions' +import { createReaction, deleteReaction } from '../../stores/zine/reactions' import MD from './MD' -import { deleteReaction } from '../../stores/zine/reactions' 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' -export default (props: { - level?: number - comment: Partial - canEdit?: boolean +type Props = { + comment: Reaction compact?: boolean -}) => { + reactions?: Reaction[] +} + +export const Comment = (props: Props) => { const [isReplyVisible, setIsReplyVisible] = createSignal(false) + const [postMessageText, setPostMessageText] = createSignal('') + + const { session } = useSession() + + const canEdit = createMemo(() => props.comment.createdBy?.slug === session()?.user?.slug) const comment = createMemo(() => props.comment) const body = createMemo(() => (comment().body || '').trim()) @@ -29,12 +36,28 @@ export default (props: { deleteReaction(comment().id) } } + + const compose = (event) => setPostMessageText(event.target.value) + const handleCreate = async (event) => { + event.preventDefault() + try { + await createReaction({ + kind: ReactionKind.Comment, + replyTo: props.comment.id, + body: postMessageText(), + shout: comment().shout.id + }) + setIsReplyVisible(false) + } catch (error) { + console.log('!!! err:', error) + } + } const formattedDate = createMemo(() => formatDate(new Date(comment()?.createdAt), { hour: 'numeric', minute: 'numeric' }) ) return ( -
+
  • - +
    {comment().id}
    @@ -92,7 +115,7 @@ export default (props: { {t('Reply')} - + {/*FIXME implement edit comment modal*/} {/* -
    -