2022-09-09 11:53:35 +00:00
|
|
|
|
import { t } from '../../utils/intl'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
import { createMemo } from 'solid-js'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
import { For, Show } from 'solid-js/web'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
import type { Shout } from '../../graphql/types.gen'
|
2022-09-09 11:53:35 +00:00
|
|
|
|
import { capitalize } from '../../utils'
|
|
|
|
|
import { translit } from '../../utils/ru2en'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
import { Icon } from '../Nav/Icon'
|
2022-10-14 18:33:06 +00:00
|
|
|
|
import style from './Card.module.scss'
|
2022-09-23 23:42:19 +00:00
|
|
|
|
import { locale } from '../../stores/ui'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
import { handleClientRouteLinkClick } from '../../stores/router'
|
|
|
|
|
import { getLogger } from '../../utils/logger'
|
2022-10-14 18:33:06 +00:00
|
|
|
|
import { clsx } from 'clsx'
|
|
|
|
|
import CardTopic from './CardTopic'
|
2022-09-22 09:37:49 +00:00
|
|
|
|
|
|
|
|
|
const log = getLogger('card component')
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
|
|
interface ArticleCardProps {
|
|
|
|
|
settings?: {
|
|
|
|
|
noicon?: boolean
|
|
|
|
|
noimage?: boolean
|
|
|
|
|
nosubtitle?: boolean
|
|
|
|
|
noauthor?: boolean
|
|
|
|
|
nodate?: boolean
|
|
|
|
|
isGroup?: boolean
|
|
|
|
|
photoBottom?: boolean
|
|
|
|
|
additionalClass?: string
|
|
|
|
|
isFeedMode?: boolean
|
2022-10-14 18:33:06 +00:00
|
|
|
|
isFloorImportant?: boolean
|
|
|
|
|
isWithCover?: boolean
|
|
|
|
|
isBigTitle?: boolean
|
|
|
|
|
isVertical?: boolean
|
|
|
|
|
isShort?: boolean
|
|
|
|
|
withBorder?: boolean
|
|
|
|
|
isCompact?: boolean
|
2022-10-17 16:24:16 +00:00
|
|
|
|
isSingle?: boolean
|
2022-09-09 11:53:35 +00:00
|
|
|
|
}
|
|
|
|
|
article: Shout
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
|
const getTitleAndSubtitle = (article: Shout): { title: string; subtitle: string } => {
|
|
|
|
|
let title = article.title
|
|
|
|
|
let subtitle = article.subtitle
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
|
if (!subtitle) {
|
|
|
|
|
let tt = article.title?.split('. ') || []
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
|
if (tt?.length === 1) {
|
|
|
|
|
tt = article.title?.split(/{!|\?|:|;}\s/) || []
|
|
|
|
|
}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
|
if (tt && tt.length > 1) {
|
|
|
|
|
const sep = article.title?.replace(tt[0], '').split(' ', 1)[0]
|
|
|
|
|
title = tt[0] + (!(sep === '.' || sep === ':') ? sep : '')
|
|
|
|
|
subtitle = capitalize(article.title?.replace(tt[0] + sep, ''), true)
|
2022-09-09 11:53:35 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-22 09:37:49 +00:00
|
|
|
|
return { title, subtitle }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const ArticleCard = (props: ArticleCardProps) => {
|
|
|
|
|
const mainTopic = props.article.topics.find(
|
|
|
|
|
(articleTopic) => articleTopic.slug === props.article.mainTopic
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const formattedDate = createMemo<string>(() => {
|
|
|
|
|
return new Date(props.article.createdAt)
|
|
|
|
|
.toLocaleDateString(locale(), { month: 'long', day: 'numeric', year: 'numeric' })
|
|
|
|
|
.replace(' г.', '')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const { title, subtitle } = getTitleAndSubtitle(props.article)
|
|
|
|
|
|
|
|
|
|
const { cover, layout, slug, authors, stat } = props.article
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<section
|
2022-10-14 18:33:06 +00:00
|
|
|
|
class={clsx(style.shoutCard, `${props.settings?.additionalClass || ''}`)}
|
2022-09-09 11:53:35 +00:00
|
|
|
|
classList={{
|
2022-10-14 18:33:06 +00:00
|
|
|
|
[style.shoutCardShort]: props.settings?.isShort,
|
|
|
|
|
[style.shoutCardPhotoBottom]: props.settings?.noimage && props.settings?.photoBottom,
|
|
|
|
|
[style.shoutCardFeed]: props.settings?.isFeedMode,
|
|
|
|
|
[style.shoutCardFloorImportant]: props.settings?.isFloorImportant,
|
|
|
|
|
[style.shoutCardWithCover]: props.settings?.isWithCover,
|
|
|
|
|
[style.shoutCardBigTitle]: props.settings?.isBigTitle,
|
|
|
|
|
[style.shoutCardVertical]: props.settings?.isVertical,
|
|
|
|
|
[style.shoutCardWithBorder]: props.settings?.withBorder,
|
2022-10-17 16:24:16 +00:00
|
|
|
|
[style.shoutCardCompact]: props.settings?.isCompact,
|
|
|
|
|
[style.shoutCardSingle]: props.settings?.isSingle
|
2022-09-09 11:53:35 +00:00
|
|
|
|
}}
|
|
|
|
|
>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<Show when={!props.settings?.noimage && cover}>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<div class={style.shoutCardCoverContainer}>
|
|
|
|
|
<div class={style.shoutCardCover}>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<img src={cover || ''} alt={title || ''} loading="lazy" />
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</Show>
|
|
|
|
|
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<div class={style.shoutCardContent}>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<Show when={layout && layout !== 'article' && !(props.settings?.noicon || props.settings?.noimage)}>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<div class={style.shoutCardType}>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<a href={`/topic/${mainTopic.slug}`}>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<Icon name={layout} class={style.icon} />
|
2022-09-28 10:34:21 +00:00
|
|
|
|
</a>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</div>
|
|
|
|
|
</Show>
|
|
|
|
|
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<Show when={!props.settings?.isGroup}>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<CardTopic
|
|
|
|
|
title={
|
|
|
|
|
locale() === 'ru' && mainTopic.title ? mainTopic.title : mainTopic.slug.replace('-', ' ')
|
|
|
|
|
}
|
|
|
|
|
slug={mainTopic.slug}
|
|
|
|
|
isFloorImportant={props.settings?.isFloorImportant}
|
|
|
|
|
/>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<div class={style.shoutCardTitlesContainer}>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<a href={`/${slug || ''}`} onClick={handleClientRouteLinkClick}>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<div class={style.shoutCardTitle}>
|
|
|
|
|
<span class={style.shoutCardLinkContainer}>{title}</span>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<Show when={!props.settings?.nosubtitle && subtitle}>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<div class={style.shoutCardSubtitle}>
|
|
|
|
|
<span class={style.shoutCardLinkContainer}>{subtitle}</span>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</div>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
</Show>
|
|
|
|
|
</a>
|
|
|
|
|
</div>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<Show when={!props.settings?.noauthor || !props.settings?.nodate}>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<div class={style.shoutDetails}>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<Show when={!props.settings?.noauthor}>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<div class={style.shoutAuthor}>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<For each={authors}>
|
|
|
|
|
{(author, index) => {
|
|
|
|
|
const name =
|
|
|
|
|
author.name === 'Дискурс' && locale() !== 'ru'
|
|
|
|
|
? 'Discours'
|
|
|
|
|
: translit(author.name || '', locale() || 'ru')
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Show when={index() > 0}>, </Show>
|
|
|
|
|
<a href={`/author/${author.slug}`}>{name}</a>
|
|
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}}
|
|
|
|
|
</For>
|
|
|
|
|
</div>
|
|
|
|
|
</Show>
|
|
|
|
|
|
|
|
|
|
<Show when={!props.settings?.nodate}>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<div class={style.shoutDate}>{formattedDate()}</div>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</div>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<Show when={props.settings?.isFeedMode}>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<section class={style.shoutCardDetails}>
|
|
|
|
|
<div class={style.shoutCardDetailsContent}>
|
|
|
|
|
<div class={clsx(style.shoutCardDetailsItem, 'rating')}>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<button class="rating__control">−</button>
|
|
|
|
|
<span class="rating__value">{stat?.rating || ''}</span>
|
|
|
|
|
<button class="rating__control">+</button>
|
|
|
|
|
</div>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<div class={clsx(style.shoutCardDetailsItem, style.shoutCardComments)}>
|
|
|
|
|
<Icon name="eye" class={style.icon} />
|
2022-09-28 10:34:21 +00:00
|
|
|
|
{stat?.viewed}
|
|
|
|
|
</div>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<div class={clsx(style.shoutCardDetailsTtem, style.shoutCardComments)}>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<a href={`/${slug + '#comments' || ''}`}>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<Icon name="comment" class={style.icon} />
|
2022-09-28 10:34:21 +00:00
|
|
|
|
{stat?.commented || ''}
|
|
|
|
|
</a>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</div>
|
|
|
|
|
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<div class={style.shoutCardDetailsItem}>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<button>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<Icon name="bookmark" class={style.icon} />
|
2022-09-28 10:34:21 +00:00
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<div class={style.shoutCardDetailsItem}>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
<button>
|
2022-10-14 18:33:06 +00:00
|
|
|
|
<Icon name="ellipsis" class={style.icon} />
|
2022-09-28 10:34:21 +00:00
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<button class="button--light shout-card__edit-control">{t('Collaborate')}</button>
|
|
|
|
|
</section>
|
|
|
|
|
</Show>
|
|
|
|
|
</div>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
</section>
|
|
|
|
|
)
|
|
|
|
|
}
|