import { capitalize, formatDate } from '../../utils' import { Icon } from '../_shared/Icon' import { AuthorCard } from '../Author/AuthorCard' 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' 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 Slider from '../_shared/Slider' 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' interface ArticleProps { article: Shout scrollToComments?: boolean } interface MediaItem { url?: string title?: string body?: string } const MediaView = (props: { media: MediaItem; kind: Shout['layout'] }) => { const { t } = useLocalize() return ( <> {t('Cannot show this media type')}}>
{props.media.title}

) } export const FullArticle = (props: ArticleProps) => { const { t } = useLocalize() const { user, isAuthenticated } = 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) // eslint-disable-next-line unicorn/consistent-function-scoping const handleBookmarkButtonClick = (ev) => { // TODO: implement bookmark clicked ev.preventDefault() } const body = createMemo(() => props.article.body) const media = createMemo(() => { const mi = JSON.parse(props.article.media || '[]') console.debug('!!! media items', mi) return mi }) 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}

{props.article.title}

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

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

{t('Authors')}

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