import { capitalize, formatDate } from '../../utils' import { Icon } from '../_shared/Icon' import { AuthorCard } from '../Author/AuthorCard' import AudioPlayer from './AudioPlayer/AudioPlayer' import type { Author, Shout } from '../../graphql/types.gen' import MD from './MD' import { SharePopup } from './SharePopup' import { getDescription } from '../../utils/meta' import { ShoutRatingControl } from './ShoutRatingControl' import { clsx } from 'clsx' import { CommentsTree } from './CommentsTree' import { useSession } from '../../context/session' import { VideoPlayer } from '../_shared/VideoPlayer' import { getPagePath } from '@nanostores/router' import { router, useRouter } from '../../stores/router' import { useReactions } from '../../context/reactions' import { Title } from '@solidjs/meta' import { useLocalize } from '../../context/localize' import stylesHeader from '../Nav/Header.module.scss' import styles from './Article.module.scss' import { imageProxy } from '../../utils/imageProxy' import { Popover } from '../_shared/Popover' import article from '../Editor/extensions/Article' import { SolidSwiper } from '../_shared/SolidSwiper' import { createEffect, For, createMemo, Match, onMount, Show, Switch, createSignal } from 'solid-js' interface ArticleProps { article: Shout scrollToComments?: boolean } interface MediaItem { url?: string title?: string body?: string } export const FullArticle = (props: ArticleProps) => { const { t } = useLocalize() const { user, isAuthenticated, actions: { requireAuthentication } } = useSession() const [isReactionsLoaded, setIsReactionsLoaded] = createSignal(false) const formattedDate = createMemo(() => formatDate(new Date(props.article.createdAt))) const mainTopic = createMemo( () => props.article.topics?.find((topic) => topic?.slug === props.article.mainTopic) || props.article.topics[0] ) onMount(async () => { await loadReactionsBy({ by: { shout: props.article.slug } }) setIsReactionsLoaded(true) }) const canEdit = () => props.article.authors?.some((a) => a.slug === user()?.slug) const handleBookmarkButtonClick = (ev) => { requireAuthentication(() => { // TODO: implement bookmark clicked ev.preventDefault() }, 'bookmark') } const body = createMemo(() => props.article.body) const media = createMemo(() => { return JSON.parse(props.article.media || '[]') }) const commentsRef: { current: HTMLDivElement } = { current: null } const scrollToComments = () => { window.scrollTo({ top: commentsRef.current.offsetTop - 96, left: 0, behavior: 'smooth' }) } const { searchParams, changeSearchParam } = useRouter() createEffect(() => { if (props.scrollToComments) { scrollToComments() } }) createEffect(() => { if (searchParams()?.scrollTo === 'comments' && commentsRef.current) { scrollToComments() changeSearchParam('scrollTo', null) } }) createEffect(() => { if (searchParams().commentId && isReactionsLoaded()) { const commentElement = document.querySelector(`[id='comment_${searchParams().commentId}']`) if (commentElement) { commentElement.scrollIntoView({ behavior: 'smooth' }) } } }) const { actions: { loadReactionsBy } } = useReactions() return ( <> {props.article.title}
{/*TODO: Check styles.shoutTopic*/}

{props.article.title}

{capitalize(props.article.subtitle, false)}

{(a: Author, index) => ( <> 0}>, {a.name} )}
{(m: MediaItem) => (
)}
0 && props.article.layout !== 'image'}>
}>
{(triggerRef: (el) => void) => (
{props.article.stat?.commented ?? ''}
)}
{props.article.stat?.viewed}
{(triggerRef: (el) => void) => (
} />
)} {(triggerRef: (el) => void) => (
)}
{(triggerRef: (el) => void) => ( )}
{formattedDate()}
{(topic) => ( )}
1}>

{t('Authors')}

{(a) => (
)}
(commentsRef.current = el)}>
) }