scroll to anchor fixes, profile comments link fix
This commit is contained in:
parent
7c1a51f638
commit
3549e57506
|
@ -108,7 +108,7 @@ export const CommentsTree = (props: Props) => {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div class={styles.commentsHeaderWrapper}>
|
<div class={styles.commentsHeaderWrapper}>
|
||||||
<h2 id="comments" class={styles.commentsHeader}>
|
<h2 class={styles.commentsHeader}>
|
||||||
{t('Comments')} {comments().length.toString() || ''}
|
{t('Comments')} {comments().length.toString() || ''}
|
||||||
<Show when={newReactions().length > 0}>
|
<Show when={newReactions().length > 0}>
|
||||||
<span class={styles.newReactions}> +{newReactions().length}</span>
|
<span class={styles.newReactions}> +{newReactions().length}</span>
|
||||||
|
@ -161,7 +161,7 @@ export const CommentsTree = (props: Props) => {
|
||||||
</ul>
|
</ul>
|
||||||
<ShowIfAuthenticated
|
<ShowIfAuthenticated
|
||||||
fallback={
|
fallback={
|
||||||
<div class={styles.signInMessage} id="comments">
|
<div class={styles.signInMessage}>
|
||||||
{t('To write a comment, you must')}{' '}
|
{t('To write a comment, you must')}{' '}
|
||||||
<a href="?modal=auth&mode=register" class={styles.link}>
|
<a href="?modal=auth&mode=register" class={styles.link}>
|
||||||
{t('sign up')}
|
{t('sign up')}
|
||||||
|
|
|
@ -66,19 +66,6 @@ export const FullArticle = (props: ArticleProps) => {
|
||||||
props.article.topics[0]
|
props.article.topics[0]
|
||||||
)
|
)
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
const windowHash = window.location.hash
|
|
||||||
if (windowHash?.length > 0) {
|
|
||||||
const comments = document.querySelector(windowHash)
|
|
||||||
if (comments) {
|
|
||||||
window.scrollTo({
|
|
||||||
top: comments.getBoundingClientRect().top,
|
|
||||||
behavior: 'smooth'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await loadReactionsBy({
|
await loadReactionsBy({
|
||||||
by: { shout: props.article.slug }
|
by: { shout: props.article.slug }
|
||||||
|
@ -105,20 +92,6 @@ export const FullArticle = (props: ArticleProps) => {
|
||||||
actions: { loadReactionsBy }
|
actions: { loadReactionsBy }
|
||||||
} = useReactions()
|
} = useReactions()
|
||||||
|
|
||||||
let commentsRef: HTMLDivElement | undefined
|
|
||||||
const scrollToComments = () => {
|
|
||||||
if (!isReactionsLoaded()) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
commentsRef.scrollIntoView({ behavior: 'smooth' })
|
|
||||||
}
|
|
||||||
const { searchParams } = useRouter()
|
|
||||||
createEffect(() => {
|
|
||||||
if (searchParams()?.scrollTo === 'comments') {
|
|
||||||
scrollToComments()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Title>{props.article.title}</Title>
|
<Title>{props.article.title}</Title>
|
||||||
|
@ -276,7 +249,7 @@ export const FullArticle = (props: ArticleProps) => {
|
||||||
)}
|
)}
|
||||||
</For>
|
</For>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div id="comments">
|
||||||
<Show when={isReactionsLoaded()}>
|
<Show when={isReactionsLoaded()}>
|
||||||
<CommentsTree
|
<CommentsTree
|
||||||
shoutId={props.article.id}
|
shoutId={props.article.id}
|
||||||
|
|
|
@ -12,12 +12,7 @@ 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
|
||||||
|
@ -80,12 +75,6 @@ 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 || ''}`)}
|
||||||
|
@ -184,10 +173,10 @@ export const ArticleCard = (props: ArticleCardProps) => {
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class={clsx(styles.shoutCardDetailsItem, styles.shoutCardComments)}>
|
<div class={clsx(styles.shoutCardDetailsItem, styles.shoutCardComments)}>
|
||||||
<button type="button" onClick={scrollToComments}>
|
<a href={`/${slug + '#comments'}`}>
|
||||||
<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')}
|
||||||
</button>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,9 @@ 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, openPage } from '@nanostores/router'
|
import { getPagePath } from '@nanostores/router'
|
||||||
import { router, useRouter } from '../../stores/router'
|
import { router } 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'>
|
||||||
|
|
||||||
|
@ -16,12 +15,6 @@ 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">
|
||||||
|
@ -36,13 +29,7 @@ export const ProfilePopup = (props: ProfilePopupProps) => {
|
||||||
<a href="#">{t('Subscriptions')}</a>
|
<a href="#">{t('Subscriptions')}</a>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<a
|
<a href={`${getPagePath(router, 'author', { slug: userSlug() })}/?by=commented`}>
|
||||||
href="#"
|
|
||||||
onClick={(event) => {
|
|
||||||
event.preventDefault()
|
|
||||||
openAuthorComments()
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{t('Comments')}
|
{t('Comments')}
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
@ -54,7 +54,11 @@ export const AuthorView = (props: AuthorProps) => {
|
||||||
|
|
||||||
const { searchParams, changeSearchParam } = useRouter<AuthorPageSearchParams>()
|
const { searchParams, changeSearchParam } = useRouter<AuthorPageSearchParams>()
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
if (!searchParams().by) {
|
||||||
changeSearchParam('by', 'rating')
|
changeSearchParam('by', 'rating')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const loadMore = async () => {
|
const loadMore = async () => {
|
||||||
saveScrollPosition()
|
saveScrollPosition()
|
||||||
|
|
|
@ -40,9 +40,8 @@ const routerStore = createRouter(ROUTES, {
|
||||||
|
|
||||||
export const router = routerStore
|
export const router = routerStore
|
||||||
|
|
||||||
const handleClientRouteLinkClick = (event) => {
|
const checkOpenOnClient = (link: HTMLAnchorElement, event) => {
|
||||||
const link = event.target.closest('a')
|
return (
|
||||||
if (
|
|
||||||
link &&
|
link &&
|
||||||
event.button === 0 &&
|
event.button === 0 &&
|
||||||
link.target !== '_blank' &&
|
link.target !== '_blank' &&
|
||||||
|
@ -52,9 +51,21 @@ const handleClientRouteLinkClick = (event) => {
|
||||||
!event.ctrlKey &&
|
!event.ctrlKey &&
|
||||||
!event.shiftKey &&
|
!event.shiftKey &&
|
||||||
!event.altKey
|
!event.altKey
|
||||||
) {
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleClientRouteLinkClick = (event) => {
|
||||||
|
const link = event.target.closest('a')
|
||||||
|
|
||||||
|
if (!checkOpenOnClient(link, event)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const url = new URL(link.href)
|
const url = new URL(link.href)
|
||||||
if (url.origin === location.origin) {
|
if (url.origin !== location.origin) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
|
|
||||||
if (url.pathname) {
|
if (url.pathname) {
|
||||||
|
@ -93,8 +104,6 @@ const handleClientRouteLinkClick = (event) => {
|
||||||
left: 0
|
left: 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const initRouter = (pathname: string, search: Record<string, string>) => {
|
export const initRouter = (pathname: string, search: Record<string, string>) => {
|
||||||
routerStore.open(pathname)
|
routerStore.open(pathname)
|
||||||
|
@ -134,7 +143,6 @@ export const useRouter = <TSearchParams extends Record<string, string> = Record<
|
||||||
return {
|
return {
|
||||||
page,
|
page,
|
||||||
searchParams,
|
searchParams,
|
||||||
changeSearchParam,
|
changeSearchParam
|
||||||
handleClientRouteLinkClick
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user