diff --git a/src/components/Article/Comment.tsx b/src/components/Article/Comment.tsx index 28f91655..0c04c101 100644 --- a/src/components/Article/Comment.tsx +++ b/src/components/Article/Comment.tsx @@ -1,7 +1,7 @@ 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 { Show, createMemo, createSignal, For, lazy, Suspense, createEffect } from 'solid-js' import { clsx } from 'clsx' import type { Author, Reaction } from '../../graphql/types.gen' import MD from './MD' @@ -30,6 +30,7 @@ export const Comment = (props: Props) => { const [isReplyVisible, setIsReplyVisible] = createSignal(false) const [loading, setLoading] = createSignal(false) const [editMode, setEditMode] = createSignal(false) + const [submitted, setSubmitted] = createSignal(false) const { session } = useSession() const { @@ -66,6 +67,7 @@ export const Comment = (props: Props) => { }) setIsReplyVisible(false) setLoading(false) + setSubmitted(true) } catch (error) { console.error('[handleCreate reaction]:', error) } @@ -94,6 +96,7 @@ export const Comment = (props: Props) => { } const createdAt = new Date(comment()?.createdAt) + return (
  • props.lastSeen })}> @@ -201,7 +204,12 @@ export const Comment = (props: Props) => { {t('Loading')}

    }> - handleCreate(value)} /> + handleCreate(value)} + cancel={() => setIsReplyVisible(false)} + />
    diff --git a/src/components/Article/CommentsTree.tsx b/src/components/Article/CommentsTree.tsx index 5e4a9c88..69591e64 100644 --- a/src/components/Article/CommentsTree.tsx +++ b/src/components/Article/CommentsTree.tsx @@ -39,15 +39,16 @@ type Props = { } export const CommentsTree = (props: Props) => { + const { session } = useSession() + const { t } = useLocalize() const [commentsOrder, setCommentsOrder] = createSignal('createdAt') + const [newReactions, setNewReactions] = createSignal([]) + const [submitted, setSubmitted] = createSignal(false) const { reactionEntities, actions: { createReaction } } = useReactions() - const { t } = useLocalize() - const [newReactions, setNewReactions] = createSignal([]) - const comments = createMemo(() => Object.values(reactionEntities).filter((reaction) => reaction.kind === 'COMMENT') ) @@ -78,7 +79,7 @@ export const CommentsTree = (props: Props) => { setCookie() } else if (currentDate > dateFromLocalStorage) { const newComments = comments().filter((c) => { - if (c.replyTo) { + if (c.replyTo || c.createdBy.slug === session()?.user.slug) { return } const created = new Date(c.createdAt) @@ -89,8 +90,6 @@ export const CommentsTree = (props: Props) => { } }) - const { session } = useSession() - const [submitted, setSubmitted] = createSignal(false) const handleSubmitComment = async (value) => { try { await createReaction({ @@ -113,38 +112,39 @@ export const CommentsTree = (props: Props) => {  +{newReactions().length} - -
      - 0}> -
    • + 0}> +
        + 0}> +
      • +
      • +
        +
      • - -
      • -
      • -
      • -
      • -
      +
    • +
    • +
    +
      !r.replyTo)}> diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index ead27868..c299fbf8 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -23,6 +23,7 @@ import { useLocalize } from '../../context/localize' interface ArticleProps { article: Shout + scrollToComments?: boolean } interface MediaItem { @@ -88,6 +89,22 @@ export const FullArticle = (props: ArticleProps) => { return mi }) + const commentsRef: { current: HTMLDivElement } = { current: null } + + const scrollToComments = () => { + window.scrollTo({ + top: commentsRef.current.offsetTop - 96, + left: 0, + behavior: 'smooth' + }) + } + + createEffect(() => { + if (props.scrollToComments) { + scrollToComments() + } + }) + const { actions: { loadReactionsBy } } = useReactions() @@ -186,12 +203,10 @@ export const FullArticle = (props: ArticleProps) => { {props.article.stat?.viewed} - - +
      { )}
      -
      +
      (commentsRef.current = el)}> void } export const Header = (props: Props) => { @@ -78,6 +80,10 @@ export const Header = (props: Props) => { }) }) + const scrollToComments = (value) => { + props.scrollToComments(value) + } + return (
      { containerCssClass={styles.control} trigger={} /> - + diff --git a/src/components/_shared/CommentEditor/CommentEditor.tsx b/src/components/_shared/CommentEditor/CommentEditor.tsx index 819627cf..e17e4ba9 100644 --- a/src/components/_shared/CommentEditor/CommentEditor.tsx +++ b/src/components/_shared/CommentEditor/CommentEditor.tsx @@ -21,6 +21,7 @@ type Props = { placeholder?: string onSubmit: (value: string) => void clear?: boolean + cancel?: () => void initialContent?: string } @@ -69,6 +70,9 @@ const CommentEditor = (props: Props) => { const clearEditor = () => { editorViewRef.current.destroy() initEditor() + if (props.cancel) { + props.cancel() + } } createEffect(() => { @@ -76,7 +80,6 @@ const CommentEditor = (props: Props) => { clearEditor() } }) - return (
      (editorElRef.current = el)} /> diff --git a/src/components/_shared/PageLayout.tsx b/src/components/_shared/PageLayout.tsx index 30a7e84c..23ca13fd 100644 --- a/src/components/_shared/PageLayout.tsx +++ b/src/components/_shared/PageLayout.tsx @@ -2,7 +2,7 @@ import type { JSX } from 'solid-js' import { Header } from '../Nav/Header' import { Footer } from '../Discours/Footer' -import { Show } from 'solid-js' +import { createEffect, createSignal, Show } from 'solid-js' import { clsx } from 'clsx' import '../../styles/app.scss' import styles from './PageLayout.module.scss' @@ -10,6 +10,7 @@ import { Meta } from '@solidjs/meta' type PageLayoutProps = { headerTitle?: string + slug?: string articleBody?: string cover?: string children: JSX.Element @@ -17,19 +18,29 @@ type PageLayoutProps = { hideFooter?: boolean class?: string withPadding?: boolean + scrollToComments?: (value: boolean) => void } export const PageLayout = (props: PageLayoutProps) => { const isHeaderFixed = props.isHeaderFixed === undefined ? true : props.isHeaderFixed + const [scrollToComments, setScrollToComments] = createSignal(false) + + createEffect(() => { + if (props.scrollToComments) { + props.scrollToComments(scrollToComments()) + } + }) return ( <>
      setScrollToComments(value)} />
      { return ( (containerRef.current = el)}> - {props.trigger} + + {props.trigger} +
      { script.dataset.ackeeDomainId = '1004abeb-89b2-4e85-ad97-74f8d2c8ed2d' document.body.appendChild(script) }) + const [scrollToComments, setScrollToComments] = createSignal(false) return ( - + { + setScrollToComments(value) + }} + > }> - + diff --git a/src/styles/Article.module.scss b/src/styles/Article.module.scss index abdd02e7..ef42c9e5 100644 --- a/src/styles/Article.module.scss +++ b/src/styles/Article.module.scss @@ -172,13 +172,20 @@ img { a { border: none; - + text-decoration: none; &:hover { - .icon { - filter: invert(1); + background: unset; + color: #000; + + img { + filter: unset; } } } + + &:hover { + cursor: pointer; + } } .shoutStatsItemLikes {