import { capitalize } from '../../utils' import './Full.scss' import { Icon } from '../Nav/Icon' import ArticleComment from './Comment' import { AuthorCard } from '../Author/Card' import { createEffect, createMemo, createSignal, For, onMount, Show } from 'solid-js' import type { Author, Reaction, Shout } from '../../graphql/types.gen' import { t } from '../../utils/intl' import { showModal } from '../../stores/ui' import { useAuthStore } from '../../stores/auth' import { incrementView } from '../../stores/zine/articles' import { renderMarkdown } from '@astrojs/markdown-remark' import { markdownOptions } from '../../../mdx.config' const MAX_COMMENT_LEVEL = 6 const getCommentLevel = (comment: Reaction, level = 0) => { if (comment && comment.replyTo && level < MAX_COMMENT_LEVEL) { return 0 // FIXME: getCommentLevel(commentsById[c.replyTo], level + 1) } return level } interface ArticleProps { article: Shout reactions: Reaction[] isCommentsLoading: boolean } const formatDate = (date: Date) => { return date .toLocaleDateString('ru', { month: 'long', day: 'numeric', year: 'numeric' }) .replace(' г.', '') } export const FullArticle = (props: ArticleProps) => { const [body, setBody] = createSignal(props.article.body?.startsWith('<') ? props.article.body : '') const { session } = useAuthStore() createEffect(() => { if (body() || !props.article.body) { return } if (props.article.body.startsWith('<')) { setBody(props.article.body) } else { renderMarkdown(props.article.body, markdownOptions) .then(({ code }) => setBody(code)) .catch(console.error) } }) onMount(() => { incrementView({ articleSlug: props.article.slug }) }) const formattedDate = createMemo(() => formatDate(new Date(props.article.createdAt))) const mainTopic = () => (props.article.topics?.find((topic) => topic?.slug === props.article.mainTopic)?.title || '').replace( ' ', ' ' ) 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' }) } } }) return (