2023-05-16 19:17:47 +00:00
|
|
|
import { createMemo, createSignal, For, Show } from 'solid-js'
|
2023-05-07 13:47:10 +00:00
|
|
|
import type { Shout } from '../../graphql/types.gen'
|
2023-06-12 17:58:02 +00:00
|
|
|
import { capitalize, formatDate } from '../../utils'
|
2022-11-14 17:41:05 +00:00
|
|
|
import { Icon } from '../_shared/Icon'
|
2023-05-01 18:32:32 +00:00
|
|
|
import styles from './ArticleCard.module.scss'
|
2022-10-19 14:26:49 +00:00
|
|
|
import { clsx } from 'clsx'
|
2022-12-01 18:45:35 +00:00
|
|
|
import { CardTopic } from './CardTopic'
|
2023-03-03 18:26:26 +00:00
|
|
|
import { ShoutRatingControl } from '../Article/ShoutRatingControl'
|
2023-01-31 13:58:28 +00:00
|
|
|
import { getShareUrl, SharePopup } from '../Article/SharePopup'
|
2023-01-25 22:13:01 +00:00
|
|
|
import stylesHeader from '../Nav/Header.module.scss'
|
2023-01-30 10:39:36 +00:00
|
|
|
import { getDescription } from '../../utils/meta'
|
2023-02-06 21:35:08 +00:00
|
|
|
import { FeedArticlePopup } from './FeedArticlePopup'
|
2023-02-17 09:21:02 +00:00
|
|
|
import { useLocalize } from '../../context/localize'
|
2023-05-08 17:21:06 +00:00
|
|
|
import { getPagePath, openPage } from '@nanostores/router'
|
2023-04-20 14:01:15 +00:00
|
|
|
import { router, useRouter } from '../../stores/router'
|
2023-05-11 14:38:20 +00:00
|
|
|
import { imageProxy } from '../../utils/imageProxy'
|
2023-05-17 04:04:38 +00:00
|
|
|
import { Popover } from '../_shared/Popover'
|
2023-06-21 20:32:16 +00:00
|
|
|
import { AuthorCard } from '../Author/AuthorCard'
|
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-19 14:26:49 +00:00
|
|
|
isFloorImportant?: boolean
|
|
|
|
isWithCover?: boolean
|
|
|
|
isBigTitle?: boolean
|
|
|
|
isVertical?: boolean
|
|
|
|
isShort?: boolean
|
|
|
|
withBorder?: boolean
|
|
|
|
isCompact?: boolean
|
|
|
|
isSingle?: boolean
|
2022-11-16 21:08:04 +00:00
|
|
|
isBeside?: boolean
|
2023-07-09 18:34:59 +00:00
|
|
|
withViewed?: 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]
|
2022-11-21 13:02:04 +00:00
|
|
|
title = tt[0] + (sep === '.' || sep === ':' ? '' : sep)
|
2022-09-22 09:37:49 +00:00
|
|
|
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) => {
|
2023-02-17 09:21:02 +00:00
|
|
|
const { t, lang } = useLocalize()
|
|
|
|
|
2022-12-07 18:38:05 +00:00
|
|
|
const mainTopic =
|
|
|
|
props.article.topics.find((articleTopic) => articleTopic.slug === props.article.mainTopic) ||
|
|
|
|
props.article.topics[0]
|
2022-09-22 09:37:49 +00:00
|
|
|
|
|
|
|
const formattedDate = createMemo<string>(() => {
|
2023-06-12 17:58:02 +00:00
|
|
|
return formatDate(new Date(props.article.createdAt), { month: 'long', day: 'numeric', year: 'numeric' })
|
2022-09-22 09:37:49 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const { title, subtitle } = getTitleAndSubtitle(props.article)
|
|
|
|
|
2023-05-08 17:21:06 +00:00
|
|
|
const { id, cover, layout, slug, authors, stat, body } = props.article
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2023-04-20 14:01:15 +00:00
|
|
|
const { changeSearchParam } = useRouter()
|
|
|
|
const scrollToComments = (event) => {
|
|
|
|
event.preventDefault()
|
2023-05-04 19:57:02 +00:00
|
|
|
openPage(router, 'article', { slug })
|
2023-04-20 14:01:15 +00:00
|
|
|
changeSearchParam('scrollTo', 'comments')
|
|
|
|
}
|
|
|
|
|
2023-05-26 02:32:20 +00:00
|
|
|
const [isActionPopupActive, setIsActionPopupActive] = createSignal(false)
|
2023-05-16 19:17:47 +00:00
|
|
|
|
2022-09-09 11:53:35 +00:00
|
|
|
return (
|
|
|
|
<section
|
2022-10-25 21:45:37 +00:00
|
|
|
class={clsx(styles.shoutCard, `${props.settings?.additionalClass || ''}`)}
|
2022-09-09 11:53:35 +00:00
|
|
|
classList={{
|
2022-10-25 21:45:37 +00:00
|
|
|
[styles.shoutCardShort]: props.settings?.isShort,
|
|
|
|
[styles.shoutCardPhotoBottom]: props.settings?.noimage && props.settings?.photoBottom,
|
|
|
|
[styles.shoutCardFeed]: props.settings?.isFeedMode,
|
|
|
|
[styles.shoutCardFloorImportant]: props.settings?.isFloorImportant,
|
|
|
|
[styles.shoutCardWithCover]: props.settings?.isWithCover,
|
|
|
|
[styles.shoutCardBigTitle]: props.settings?.isBigTitle,
|
|
|
|
[styles.shoutCardVertical]: props.settings?.isVertical,
|
|
|
|
[styles.shoutCardWithBorder]: props.settings?.withBorder,
|
|
|
|
[styles.shoutCardCompact]: props.settings?.isCompact,
|
2022-11-16 21:08:04 +00:00
|
|
|
[styles.shoutCardSingle]: props.settings?.isSingle,
|
2023-07-26 20:38:51 +00:00
|
|
|
[styles.shoutCardBeside]: props.settings?.isBeside,
|
|
|
|
[styles.shoutCardNoImage]: !cover
|
2022-09-09 11:53:35 +00:00
|
|
|
}}
|
|
|
|
>
|
2023-06-21 20:32:16 +00:00
|
|
|
<Show when={!props.settings?.noimage && cover && !props.settings?.isFeedMode}>
|
2022-10-25 21:45:37 +00:00
|
|
|
<div class={styles.shoutCardCoverContainer}>
|
|
|
|
<div class={styles.shoutCardCover}>
|
2023-05-11 14:38:20 +00:00
|
|
|
<img src={imageProxy(cover)} alt={title || ''} loading="lazy" />
|
2022-09-28 10:34:21 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
|
2022-10-25 21:45:37 +00:00
|
|
|
<div class={styles.shoutCardContent}>
|
2023-06-21 20:32:16 +00:00
|
|
|
<Show
|
|
|
|
when={
|
|
|
|
layout &&
|
|
|
|
layout !== 'article' &&
|
|
|
|
!(props.settings?.noicon || props.settings?.noimage) &&
|
|
|
|
!props.settings?.isFeedMode
|
|
|
|
}
|
|
|
|
>
|
2022-10-25 21:45:37 +00:00
|
|
|
<div class={styles.shoutCardType}>
|
2022-11-14 06:52:08 +00:00
|
|
|
<a href={`/expo/${layout}`}>
|
2022-10-25 21:45:37 +00:00
|
|
|
<Icon name={layout} class={styles.icon} />
|
2023-07-09 18:34:59 +00:00
|
|
|
{/*<Icon name={`${layout}-hover`} class={clsx(styles.icon, styles.iconHover)} />*/}
|
2022-09-28 10:34:21 +00:00
|
|
|
</a>
|
2022-09-09 11:53:35 +00:00
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
|
2023-05-04 19:57:02 +00:00
|
|
|
<Show when={!props.settings?.isGroup && mainTopic}>
|
2022-10-19 14:26:49 +00:00
|
|
|
<CardTopic
|
|
|
|
title={
|
2023-02-17 09:21:02 +00:00
|
|
|
lang() === 'ru' && mainTopic.title ? mainTopic.title : mainTopic?.slug?.replace('-', ' ')
|
2022-10-19 14:26:49 +00:00
|
|
|
}
|
|
|
|
slug={mainTopic.slug}
|
|
|
|
isFloorImportant={props.settings?.isFloorImportant}
|
2023-06-21 20:32:16 +00:00
|
|
|
isFeedMode={true}
|
2023-06-05 21:56:36 +00:00
|
|
|
class={clsx(styles.shoutTopic, { [styles.shoutTopicTop]: props.settings.isShort })}
|
2022-10-19 14:26:49 +00:00
|
|
|
/>
|
2022-09-28 10:34:21 +00:00
|
|
|
</Show>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2023-06-21 20:32:16 +00:00
|
|
|
<div
|
|
|
|
class={clsx(styles.shoutCardTitlesContainer, {
|
|
|
|
[styles.shoutCardTitlesContainerFeedMode]: props.settings?.isFeedMode
|
|
|
|
})}
|
|
|
|
>
|
2022-11-15 16:16:31 +00:00
|
|
|
<a href={`/${slug || ''}`}>
|
2022-10-25 21:45:37 +00:00
|
|
|
<div class={styles.shoutCardTitle}>
|
2023-07-09 18:34:59 +00:00
|
|
|
<span class={styles.shoutCardLinkWrapper}>
|
|
|
|
<span class={styles.shoutCardLinkContainer}>{title}</span>
|
|
|
|
</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-25 21:45:37 +00:00
|
|
|
<div class={styles.shoutCardSubtitle}>
|
|
|
|
<span class={styles.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}>
|
2023-06-21 20:32:16 +00:00
|
|
|
<div
|
|
|
|
class={clsx(styles.shoutDetails, { [styles.shoutDetailsFeedMode]: props.settings?.isFeedMode })}
|
|
|
|
>
|
2022-09-28 10:34:21 +00:00
|
|
|
<Show when={!props.settings?.noauthor}>
|
2022-10-25 21:45:37 +00:00
|
|
|
<div class={styles.shoutAuthor}>
|
2022-09-28 10:34:21 +00:00
|
|
|
<For each={authors}>
|
2023-06-21 20:32:16 +00:00
|
|
|
{(author) => {
|
2022-09-28 10:34:21 +00:00
|
|
|
return (
|
2023-06-21 20:32:16 +00:00
|
|
|
<AuthorCard
|
|
|
|
author={author}
|
|
|
|
hideWriteButton={true}
|
|
|
|
hideFollow={true}
|
|
|
|
isFeedMode={true}
|
|
|
|
hasLink={props.settings?.isFeedMode}
|
|
|
|
/>
|
2022-09-28 10:34:21 +00:00
|
|
|
)
|
|
|
|
}}
|
|
|
|
</For>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
<Show when={!props.settings?.nodate}>
|
2023-06-12 17:58:02 +00:00
|
|
|
<time class={styles.shoutDate}>{formattedDate()}</time>
|
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}>
|
2023-06-21 20:32:16 +00:00
|
|
|
<Show when={!props.settings?.noimage && cover}>
|
|
|
|
<div class={styles.shoutCardCoverContainer}>
|
|
|
|
<Show
|
|
|
|
when={
|
|
|
|
layout && layout !== 'article' && !(props.settings?.noicon || props.settings?.noimage)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<div class={styles.shoutCardType}>
|
|
|
|
<a href={`/expo/${layout}`}>
|
2023-07-09 18:34:59 +00:00
|
|
|
<Icon name={layout} class={styles.icon} />
|
|
|
|
{/*<Icon name={`${layout}-hover`} class={clsx(styles.icon, styles.iconHover)} />*/}
|
2023-06-21 20:32:16 +00:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
<div class={styles.shoutCardCover}>
|
|
|
|
<img src={imageProxy(cover)} alt={title || ''} loading="lazy" />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Show>
|
|
|
|
|
2023-05-16 19:17:47 +00:00
|
|
|
<section
|
|
|
|
class={styles.shoutCardDetails}
|
2023-05-26 02:32:20 +00:00
|
|
|
classList={{ [styles.shoutCardDetailsActive]: isActionPopupActive() }}
|
2023-05-16 19:17:47 +00:00
|
|
|
>
|
2022-10-25 21:45:37 +00:00
|
|
|
<div class={styles.shoutCardDetailsContent}>
|
2023-03-03 18:26:26 +00:00
|
|
|
<ShoutRatingControl shout={props.article} class={styles.shoutCardDetailsItem} />
|
2023-01-25 22:13:01 +00:00
|
|
|
|
2022-10-25 21:45:37 +00:00
|
|
|
<div class={clsx(styles.shoutCardDetailsItem, styles.shoutCardComments)}>
|
2023-04-20 14:01:15 +00:00
|
|
|
<a href="#" onClick={(event) => scrollToComments(event)}>
|
2023-01-25 22:13:01 +00:00
|
|
|
<Icon name="comment" class={clsx(styles.icon, styles.feedControlIcon)} />
|
2023-07-02 05:08:42 +00:00
|
|
|
<Icon
|
|
|
|
name="comment-hover"
|
|
|
|
class={clsx(styles.icon, styles.iconHover, styles.feedControlIcon)}
|
|
|
|
/>
|
2023-06-27 22:47:47 +00:00
|
|
|
<span class={styles.shoutCardLinkContainer}>{stat?.commented || t('Add comment')}</span>
|
2023-04-03 12:55:00 +00:00
|
|
|
</a>
|
2022-09-09 11:53:35 +00:00
|
|
|
</div>
|
2023-07-09 18:34:59 +00:00
|
|
|
|
|
|
|
<Show when={props.settings?.withViewed}>
|
|
|
|
<div class={clsx(styles.shoutCardDetailsItem, styles.shoutCardDetailsViewed)}>
|
|
|
|
<Icon name="eye" class={clsx(styles.icon, styles.feedControlIcon)} />
|
|
|
|
{stat?.viewed}
|
|
|
|
</div>
|
|
|
|
</Show>
|
2023-01-25 22:13:01 +00:00
|
|
|
</div>
|
2022-09-09 11:53:35 +00:00
|
|
|
|
2023-01-25 22:13:01 +00:00
|
|
|
<div class={styles.shoutCardDetailsContent}>
|
2023-05-17 04:04:38 +00:00
|
|
|
<Popover content={t('Edit')}>
|
|
|
|
{(triggerRef: (el) => void) => (
|
|
|
|
<div class={styles.shoutCardDetailsItem} ref={triggerRef}>
|
|
|
|
<a href={getPagePath(router, 'edit', { shoutId: id.toString() })}>
|
|
|
|
<Icon name="pencil-outline" class={clsx(styles.icon, styles.feedControlIcon)} />
|
2023-07-02 05:08:42 +00:00
|
|
|
<Icon
|
|
|
|
name="pencil-outline-hover"
|
|
|
|
class={clsx(styles.icon, styles.iconHover, styles.feedControlIcon)}
|
|
|
|
/>
|
2023-05-17 04:04:38 +00:00
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Popover>
|
2022-09-28 10:34:21 +00:00
|
|
|
|
2023-05-17 04:04:38 +00:00
|
|
|
<Popover content={t('Add to bookmarks')}>
|
|
|
|
{(triggerRef: (el) => void) => (
|
|
|
|
<div class={styles.shoutCardDetailsItem} ref={triggerRef}>
|
2023-01-25 22:13:01 +00:00
|
|
|
<button>
|
2023-05-17 04:04:38 +00:00
|
|
|
<Icon name="bookmark" class={clsx(styles.icon, styles.feedControlIcon)} />
|
2023-07-02 05:08:42 +00:00
|
|
|
<Icon
|
|
|
|
name="bookmark-hover"
|
|
|
|
class={clsx(styles.icon, styles.iconHover, styles.feedControlIcon)}
|
|
|
|
/>
|
2023-01-25 22:13:01 +00:00
|
|
|
</button>
|
2023-05-17 04:04:38 +00:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Popover>
|
|
|
|
|
2023-05-26 02:32:20 +00:00
|
|
|
<Popover content={t('Share')} disabled={isActionPopupActive()}>
|
2023-05-17 04:04:38 +00:00
|
|
|
{(triggerRef: (el) => void) => (
|
|
|
|
<div class={styles.shoutCardDetailsItem} ref={triggerRef}>
|
|
|
|
<SharePopup
|
|
|
|
containerCssClass={stylesHeader.control}
|
|
|
|
title={title}
|
|
|
|
description={getDescription(body)}
|
|
|
|
imageUrl={cover}
|
|
|
|
shareUrl={getShareUrl({ pathname: `/${slug}` })}
|
2023-05-26 02:32:20 +00:00
|
|
|
isVisible={(value) => setIsActionPopupActive(value)}
|
2023-05-17 04:04:38 +00:00
|
|
|
trigger={
|
|
|
|
<button>
|
|
|
|
<Icon name="share-outline" class={clsx(styles.icon, styles.feedControlIcon)} />
|
2023-07-02 05:08:42 +00:00
|
|
|
<Icon
|
|
|
|
name="share-outline-hover"
|
|
|
|
class={clsx(styles.icon, styles.iconHover, styles.feedControlIcon)}
|
|
|
|
/>
|
2023-05-17 04:04:38 +00:00
|
|
|
</button>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</Popover>
|
2023-01-25 22:13:01 +00:00
|
|
|
|
|
|
|
<div class={styles.shoutCardDetailsItem}>
|
2023-02-06 21:35:08 +00:00
|
|
|
<FeedArticlePopup
|
|
|
|
containerCssClass={stylesHeader.control}
|
2023-02-07 13:20:07 +00:00
|
|
|
title={title}
|
|
|
|
description={getDescription(body)}
|
|
|
|
imageUrl={cover}
|
2023-02-06 21:35:08 +00:00
|
|
|
shareUrl={getShareUrl({ pathname: `/${slug}` })}
|
2023-05-26 02:32:20 +00:00
|
|
|
isVisible={(value) => setIsActionPopupActive(value)}
|
2023-02-06 21:35:08 +00:00
|
|
|
trigger={
|
|
|
|
<button>
|
|
|
|
<Icon name="ellipsis" class={clsx(styles.icon, styles.feedControlIcon)} />
|
2023-07-02 05:08:42 +00:00
|
|
|
<Icon
|
|
|
|
name="ellipsis"
|
|
|
|
class={clsx(styles.icon, styles.iconHover, styles.feedControlIcon)}
|
|
|
|
/>
|
2023-02-06 21:35:08 +00:00
|
|
|
</button>
|
|
|
|
}
|
|
|
|
/>
|
2023-01-25 22:13:01 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-09-28 10:34:21 +00:00
|
|
|
</section>
|
|
|
|
</Show>
|
|
|
|
</div>
|
2022-09-09 11:53:35 +00:00
|
|
|
</section>
|
|
|
|
)
|
|
|
|
}
|