diff --git a/src/components/Article/Comment.tsx b/src/components/Article/Comment.tsx index db77395c..ac0673d7 100644 --- a/src/components/Article/Comment.tsx +++ b/src/components/Article/Comment.tsx @@ -1,33 +1,34 @@ import styles from './Comment.module.scss' -import type { JSX } from 'solid-js/jsx-runtime' import { Icon } from '../_shared/Icon' import { AuthorCard } from '../Author/Card' -import { Show, createMemo, createSignal, createEffect } 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 { 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 { apiClient } from '../../utils/apiClient' -import { ReactionKind } from '../../graphql/types.gen' +import { useSession } from '../../context/session' type Props = { - level?: number - comment: Partial - canEdit?: boolean + level: number + comment: Reaction compact?: boolean - children?: JSX.Element[] - parent?: number + reactions: Reaction[] } -export default (props: Props) => { +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()) const remove = () => { @@ -43,7 +44,7 @@ export default (props: Props) => { // await createReaction({ await apiClient.createReaction({ kind: 7, - replyTo: props.parent, + replyTo: props.comment.id, body: postMessageText(), shout: comment().shout.id }) @@ -95,7 +96,7 @@ export default (props: Props) => {
@@ -111,7 +112,7 @@ export default (props: Props) => { {t('Reply')} - + {/*FIXME implement edit comment modal*/} {/* {
- - - + ) } diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx index 44e3e8e1..c4d5b2bb 100644 --- a/src/components/Article/CommentsTree.tsx +++ b/src/components/Article/CommentsTree.tsx @@ -1,6 +1,6 @@ import { For, Show, createMemo, createSignal, onMount, createEffect } from 'solid-js' import { useSession } from '../../context/session' -import Comment from './Comment' +import { Comment } from './Comment' import { t } from '../../utils/intl' import { showModal } from '../../stores/ui' import styles from '../../styles/Article.module.scss' @@ -10,10 +10,6 @@ import { clsx } from 'clsx' import { byCreated, byStat } from '../../utils/sortby' import { Loading } from '../Loading' -type NestedReaction = { - children: Reaction[] | [] -} & Reaction - const ARTICLE_COMMENTS_PAGE_SIZE = 50 const MAX_COMMENT_LEVEL = 6 @@ -106,18 +102,8 @@ export const CommentsTree = (props: { shoutSlug: string }) => { diff --git a/src/components/Views/Feed.tsx b/src/components/Views/Feed.tsx index b02f33bd..46ac954d 100644 --- a/src/components/Views/Feed.tsx +++ b/src/components/Views/Feed.tsx @@ -7,7 +7,7 @@ import { ArticleCard } from '../Feed/Card' import { AuthorCard } from '../Author/Card' import { t } from '../../utils/intl' import { FeedSidebar } from '../Feed/Sidebar' -import CommentCard from '../Article/Comment' +import { Comment as CommentCard } from '../Article/Comment' import { loadShouts, useArticlesStore } from '../../stores/zine/articles' import { useReactionsStore } from '../../stores/zine/reactions' import { useAuthorsStore } from '../../stores/zine/authors' @@ -128,7 +128,8 @@ export const FeedView = () => {

{t('Comments')}

- {(comment) => } + {/*FIXME: different components/better comment props*/} + {(comment) => }
0}>