[161] scroll to comments

This commit is contained in:
ilia tapazukk 2023-04-01 04:20:14 +00:00
parent 5d0004242d
commit 492dabb7b9
5 changed files with 42 additions and 9 deletions

View File

@ -2,7 +2,7 @@ import { capitalize, formatDate } from '../../utils'
import './Full.scss' import './Full.scss'
import { Icon } from '../_shared/Icon' import { Icon } from '../_shared/Icon'
import { AuthorCard } from '../Author/Card' 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 type { Author, Shout } from '../../graphql/types.gen'
import MD from './MD' import MD from './MD'
import { SharePopup } from './SharePopup' import { SharePopup } from './SharePopup'
@ -16,7 +16,7 @@ import { useSession } from '../../context/session'
import VideoPlayer from './VideoPlayer' import VideoPlayer from './VideoPlayer'
import Slider from '../_shared/Slider' import Slider from '../_shared/Slider'
import { getPagePath } from '@nanostores/router' import { getPagePath } from '@nanostores/router'
import { router } from '../../stores/router' import { router, useRouter } from '../../stores/router'
import { useReactions } from '../../context/reactions' import { useReactions } from '../../context/reactions'
import { Title } from '@solidjs/meta' import { Title } from '@solidjs/meta'
import { useLocalize } from '../../context/localize' import { useLocalize } from '../../context/localize'
@ -112,6 +112,12 @@ export const FullArticle = (props: ArticleProps) => {
} }
commentsRef.scrollIntoView({ behavior: 'smooth' }) commentsRef.scrollIntoView({ behavior: 'smooth' })
} }
const { searchParams } = useRouter()
createEffect(() => {
if (searchParams()?.scrollTo === 'comments') {
scrollToComments()
}
})
return ( return (
<> <>

View File

@ -12,7 +12,12 @@ import stylesHeader from '../Nav/Header.module.scss'
import { getDescription } from '../../utils/meta' import { getDescription } from '../../utils/meta'
import { FeedArticlePopup } from './FeedArticlePopup' import { FeedArticlePopup } from './FeedArticlePopup'
import { useLocalize } from '../../context/localize' import { useLocalize } from '../../context/localize'
import { openPage } from '@nanostores/router'
import { router, useRouter } from '../../stores/router'
type ArticleSearchParams = {
scrollTo: 'comments'
}
interface ArticleCardProps { interface ArticleCardProps {
settings?: { settings?: {
noicon?: boolean noicon?: boolean
@ -75,6 +80,12 @@ export const ArticleCard = (props: ArticleCardProps) => {
const { cover, layout, slug, authors, stat, body } = props.article const { cover, layout, slug, authors, stat, body } = props.article
const { changeSearchParam } = useRouter<ArticleSearchParams>()
const scrollToComments = () => {
openPage(router, 'article', { slug: slug })
changeSearchParam('scrollTo', 'comments')
}
return ( return (
<section <section
class={clsx(styles.shoutCard, `${props.settings?.additionalClass || ''}`)} class={clsx(styles.shoutCard, `${props.settings?.additionalClass || ''}`)}
@ -173,10 +184,10 @@ export const ArticleCard = (props: ArticleCardProps) => {
</div> </div>
<div class={clsx(styles.shoutCardDetailsItem, styles.shoutCardComments)}> <div class={clsx(styles.shoutCardDetailsItem, styles.shoutCardComments)}>
<a href={`/${slug + '#comments' || ''}`}> <button type="button" onClick={scrollToComments}>
<Icon name="comment" class={clsx(styles.icon, styles.feedControlIcon)} /> <Icon name="comment" class={clsx(styles.icon, styles.feedControlIcon)} />
{stat?.commented || t('Add comment')} {stat?.commented || t('Add comment')}
</a> </button>
</div> </div>
</div> </div>

View File

@ -2,9 +2,10 @@ import { useSession } from '../../context/session'
import type { PopupProps } from '../_shared/Popup' import type { PopupProps } from '../_shared/Popup'
import { Popup } from '../_shared/Popup' import { Popup } from '../_shared/Popup'
import styles from '../_shared/Popup/Popup.module.scss' import styles from '../_shared/Popup/Popup.module.scss'
import { getPagePath } from '@nanostores/router' import { getPagePath, openPage } from '@nanostores/router'
import { router } from '../../stores/router' import { router, useRouter } from '../../stores/router'
import { useLocalize } from '../../context/localize' import { useLocalize } from '../../context/localize'
import type { AuthorPageSearchParams } from '../Views/Author'
type ProfilePopupProps = Omit<PopupProps, 'children'> type ProfilePopupProps = Omit<PopupProps, 'children'>
@ -15,6 +16,12 @@ export const ProfilePopup = (props: ProfilePopupProps) => {
} = useSession() } = useSession()
const { t } = useLocalize() const { t } = useLocalize()
const { changeSearchParam } = useRouter<AuthorPageSearchParams>()
const openAuthorComments = () => {
openPage(router, 'author', { slug: userSlug() })
changeSearchParam('by', 'commented')
}
return ( return (
<Popup {...props} horizontalAnchor="right" variant="bordered"> <Popup {...props} horizontalAnchor="right" variant="bordered">
@ -29,7 +36,15 @@ export const ProfilePopup = (props: ProfilePopupProps) => {
<a href="#">{t('Subscriptions')}</a> <a href="#">{t('Subscriptions')}</a>
</li> </li>
<li> <li>
<a href="#">{t('Comments')}</a> <a
href="#"
onClick={(event) => {
event.preventDefault()
openAuthorComments()
}}
>
{t('Comments')}
</a>
</li> </li>
<li> <li>
<a href="#">{t('Bookmarks')}</a> <a href="#">{t('Bookmarks')}</a>

View File

@ -26,7 +26,7 @@ type AuthorProps = {
authorSlug: string authorSlug: string
} }
type AuthorPageSearchParams = { export type AuthorPageSearchParams = {
by: '' | 'viewed' | 'rating' | 'commented' | 'recent' | 'followed' | 'about' | 'popular' by: '' | 'viewed' | 'rating' | 'commented' | 'recent' | 'followed' | 'about' | 'popular'
} }
@ -131,7 +131,7 @@ export const AuthorView = (props: AuthorProps) => {
*/} */}
<li classList={{ selected: searchParams().by === 'about' }}> <li classList={{ selected: searchParams().by === 'about' }}>
<button type="button" onClick={() => changeSearchParam('by', 'about')}> <button type="button" onClick={() => changeSearchParam('by', 'about')}>
О себе {t('About myself')}
</button> </button>
</li> </li>
</ul> </ul>

View File

@ -37,6 +37,7 @@ export default gql`
viewed viewed
reacted reacted
rating rating
commented
} }
} }
} }