diff --git a/src/components/Article/Comment.module.scss b/src/components/Article/Comment.module.scss index ce52e65a..a4f8dc15 100644 --- a/src/components/Article/Comment.module.scss +++ b/src/components/Article/Comment.module.scss @@ -9,11 +9,32 @@ margin-bottom: 0; } - $levels: 0, 1, 2, 3, 4; - $padding: 1rem; - @each $level in $levels { - &.commentLevel-#{level} { - padding-left: $padding * $level; + .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; } } diff --git a/src/components/Article/Comment.tsx b/src/components/Article/Comment.tsx index 402ff5f5..db77395c 100644 --- a/src/components/Article/Comment.tsx +++ b/src/components/Article/Comment.tsx @@ -13,6 +13,7 @@ import { SharePopup } from './SharePopup' import stylesHeader from '../Nav/Header.module.scss' import Userpic from '../Author/Userpic' import { apiClient } from '../../utils/apiClient' +import { ReactionKind } from '../../graphql/types.gen' type Props = { level?: number @@ -41,20 +42,18 @@ export default (props: Props) => { event.preventDefault() // await createReaction({ await apiClient.createReaction({ + kind: 7, replyTo: props.parent, body: postMessageText(), - shout: comment().shout.slug, - kind: 7 + shout: comment().shout.id }) } const formattedDate = createMemo(() => formatDate(new Date(comment()?.createdAt), { hour: 'numeric', minute: 'numeric' }) ) - console.log('!!! lvl:', props.level) return ( -
  • - {props.level} +
  • {
    + + +
  • ) } diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx index 6ed45c06..44e3e8e1 100644 --- a/src/components/Article/CommentsTree.tsx +++ b/src/components/Article/CommentsTree.tsx @@ -11,7 +11,7 @@ import { byCreated, byStat } from '../../utils/sortby' import { Loading } from '../Loading' type NestedReaction = { - children: Reaction[] + children: Reaction[] | [] } & Reaction const ARTICLE_COMMENTS_PAGE_SIZE = 50 @@ -53,6 +53,24 @@ export const CommentsTree = (props: { shoutSlug: string }) => { } onMount(async () => await loadMore()) + const nestComments = (commentList) => { + const commentMap = {} + commentList.forEach((comment) => { + commentMap[comment.id] = comment + if (comment.replyTo !== null) { + const parent = commentMap[comment.replyTo] ?? [] + ;(parent.children = parent.children || []).push(comment) + } + }) + return commentList.filter((comment) => { + return !comment.replyTo + }) + } + + createEffect(() => { + console.log('!!! re:', nestComments(reactions())) + }) + return ( <> }> @@ -88,13 +106,16 @@ export const CommentsTree = (props: { shoutSlug: string }) => {