import { t } from '../../utils/intl' import { createEffect, createMemo, createSignal, onMount } from 'solid-js' import { For, Show } from 'solid-js/web' import type { Author, Shout, Topic } from '../../graphql/types.gen' import { capitalize } from '../../utils' import { translit } from '../../utils/ru2en' import Icon from '../Nav/Icon' import './Card.scss' import { locale as localestore } from '../../stores/ui' import { useStore } from '@nanostores/solid' interface ArticleCardProps { settings?: { noicon?: boolean noimage?: boolean nosubtitle?: boolean noauthor?: boolean nodate?: boolean isGroup?: boolean photoBottom?: boolean additionalClass?: string isFeedMode?: boolean } article: Shout } export const ArticleCard = (props: ArticleCardProps) => { const locale = useStore(localestore) const [title, setTitle] = createSignal('') const [subtitle, setSubtitle] = createSignal('') const article = createMemo(() => props.article) const authors = createMemo(() => article().authors) const mainTopic = createMemo(() => props.article.topics.find((articleTopic) => articleTopic.slug === props.article.mainTopic) ) const detectSubtitle = () => { const a = article() setTitle(a.title || '') if (!a.subtitle) { let tt: string[] = a.title?.split('. ') || [] if (tt?.length === 1) tt = a.title?.split(/{!|\?|:|;}\s/) || [] if (tt && tt.length > 1) { const sep = a.title?.replace(tt[0], '').split(' ', 1)[0] setTitle(tt[0] + (!(sep === '.' || sep === ':') ? sep : '')) setSubtitle(capitalize(a.title?.replace(tt[0] + sep, ''), true)) } } else { setSubtitle(a.subtitle || '') } } // FIXME: move this to store action const translateAuthors = () => { const aaa = new Set(article().authors) aaa.forEach((a) => { a.name = a.name === 'Дискурс' && locale() !== 'ru' ? 'Discours' : translit(a.name || '', locale() || 'ru') }) return [...aaa] } createEffect(translateAuthors, [article(), locale()]) onMount(detectSubtitle) return (
{props.article.title
{(a: Author) => ( <> 0}>, {a.name} )}
{new Date(props.article.createdAt) .toLocaleDateString(locale(), { month: 'long', day: 'numeric', year: 'numeric' }) .replace(' г.', '')}
{props.article.stat?.rating || ''}
{props.article.stat?.viewed}
) }