From 492dabb7b92966fb2a3170694dc8c63b41746abd Mon Sep 17 00:00:00 2001 From: ilia tapazukk Date: Sat, 1 Apr 2023 04:20:14 +0000 Subject: [PATCH] [161] scroll to comments --- src/components/Article/FullArticle.tsx | 10 ++++++++-- src/components/Feed/Card.tsx | 15 +++++++++++++-- src/components/Nav/ProfilePopup.tsx | 21 ++++++++++++++++++--- src/components/Views/Author.tsx | 4 ++-- src/graphql/query/articles-load-by.ts | 1 + 5 files changed, 42 insertions(+), 9 deletions(-) diff --git a/src/components/Article/FullArticle.tsx b/src/components/Article/FullArticle.tsx index a350b1fb..702d7c48 100644 --- a/src/components/Article/FullArticle.tsx +++ b/src/components/Article/FullArticle.tsx @@ -2,7 +2,7 @@ import { capitalize, formatDate } from '../../utils' import './Full.scss' import { Icon } from '../_shared/Icon' import { AuthorCard } from '../Author/Card' -import { createMemo, createSignal, For, Match, onMount, Show, Switch } from 'solid-js' +import { createEffect, createMemo, createSignal, For, Match, onMount, Show, Switch } from 'solid-js' import type { Author, Shout } from '../../graphql/types.gen' import MD from './MD' import { SharePopup } from './SharePopup' @@ -16,7 +16,7 @@ import { useSession } from '../../context/session' import VideoPlayer from './VideoPlayer' import Slider from '../_shared/Slider' import { getPagePath } from '@nanostores/router' -import { router } from '../../stores/router' +import { router, useRouter } from '../../stores/router' import { useReactions } from '../../context/reactions' import { Title } from '@solidjs/meta' import { useLocalize } from '../../context/localize' @@ -112,6 +112,12 @@ export const FullArticle = (props: ArticleProps) => { } commentsRef.scrollIntoView({ behavior: 'smooth' }) } + const { searchParams } = useRouter() + createEffect(() => { + if (searchParams()?.scrollTo === 'comments') { + scrollToComments() + } + }) return ( <> diff --git a/src/components/Feed/Card.tsx b/src/components/Feed/Card.tsx index f6630608..29515264 100644 --- a/src/components/Feed/Card.tsx +++ b/src/components/Feed/Card.tsx @@ -12,7 +12,12 @@ import stylesHeader from '../Nav/Header.module.scss' import { getDescription } from '../../utils/meta' import { FeedArticlePopup } from './FeedArticlePopup' import { useLocalize } from '../../context/localize' +import { openPage } from '@nanostores/router' +import { router, useRouter } from '../../stores/router' +type ArticleSearchParams = { + scrollTo: 'comments' +} interface ArticleCardProps { settings?: { noicon?: boolean @@ -75,6 +80,12 @@ export const ArticleCard = (props: ArticleCardProps) => { const { cover, layout, slug, authors, stat, body } = props.article + const { changeSearchParam } = useRouter() + const scrollToComments = () => { + openPage(router, 'article', { slug: slug }) + changeSearchParam('scrollTo', 'comments') + } + return (
{ diff --git a/src/components/Nav/ProfilePopup.tsx b/src/components/Nav/ProfilePopup.tsx index 9dd0e135..1d5bfd5b 100644 --- a/src/components/Nav/ProfilePopup.tsx +++ b/src/components/Nav/ProfilePopup.tsx @@ -2,9 +2,10 @@ import { useSession } from '../../context/session' import type { PopupProps } from '../_shared/Popup' import { Popup } from '../_shared/Popup' import styles from '../_shared/Popup/Popup.module.scss' -import { getPagePath } from '@nanostores/router' -import { router } from '../../stores/router' +import { getPagePath, openPage } from '@nanostores/router' +import { router, useRouter } from '../../stores/router' import { useLocalize } from '../../context/localize' +import type { AuthorPageSearchParams } from '../Views/Author' type ProfilePopupProps = Omit @@ -15,6 +16,12 @@ export const ProfilePopup = (props: ProfilePopupProps) => { } = useSession() const { t } = useLocalize() + const { changeSearchParam } = useRouter() + + const openAuthorComments = () => { + openPage(router, 'author', { slug: userSlug() }) + changeSearchParam('by', 'commented') + } return ( @@ -29,7 +36,15 @@ export const ProfilePopup = (props: ProfilePopupProps) => { {t('Subscriptions')}
  • - {t('Comments')} + { + event.preventDefault() + openAuthorComments() + }} + > + {t('Comments')} +
  • {t('Bookmarks')} diff --git a/src/components/Views/Author.tsx b/src/components/Views/Author.tsx index f0de8463..535c915a 100644 --- a/src/components/Views/Author.tsx +++ b/src/components/Views/Author.tsx @@ -26,7 +26,7 @@ type AuthorProps = { authorSlug: string } -type AuthorPageSearchParams = { +export type AuthorPageSearchParams = { by: '' | 'viewed' | 'rating' | 'commented' | 'recent' | 'followed' | 'about' | 'popular' } @@ -131,7 +131,7 @@ export const AuthorView = (props: AuthorProps) => { */}
  • diff --git a/src/graphql/query/articles-load-by.ts b/src/graphql/query/articles-load-by.ts index 4baad70a..b7929c2c 100644 --- a/src/graphql/query/articles-load-by.ts +++ b/src/graphql/query/articles-load-by.ts @@ -37,6 +37,7 @@ export default gql` viewed reacted rating + commented } } }