import { capitalize } from '../../utils' import './Full.scss' import Icon from '../Nav/Icon' import ArticleComment from './Comment' import { AuthorCard } from '../Author/Card' import { 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 { renderMarkdown } from '@astrojs/markdown-remark' import { markdownOptions } from '../../../mdx.config' import { useStore } from '@nanostores/solid' import { session } from '../../stores/auth' import { incrementView, loadArticle } from '../../stores/zine/articles' 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('') const auth = useStore(session) onMount(() => { if (!props.article.body) { loadArticle({ slug: props.article.slug }) } }) // onMount(() => { // const b: string = props.article?.body // if (b?.toString().startsWith('<')) { // setBody(b) // } else { // renderMarkdown(b, markdownOptions).then(({ code }) => setBody(code)) // } // }) 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 (