import type { FC, ReactElement, ReactNode } from 'react'; import { useIntl } from 'react-intl'; import type { PageLink } from '../../../../types'; import { getReadingTimeFrom } from '../../../../utils/helpers'; import { Link, Time, VisuallyHidden } from '../../../atoms'; import { CardMeta, type CardMetaProps, MetaItem, type MetaItemProps, } from '../../../molecules'; const a11y = (chunks: ReactNode) => {chunks}; export type PostPreviewMetaComment = { /** * The number of comments. */ count: number; /** * The post heading (used to generate an accessible label). */ postHeading: string; /** * An url to the comments section. */ url?: string; }; export type PostPreviewMetaData = { /** * The author name. */ author?: string; /** * The number of comments on the post and eventually an url to read them. */ comments?: PostPreviewMetaComment; /** * The publication date of the post. */ publicationDate?: string; /** * The thematics attached to the post. */ thematics?: PageLink[]; /** * The topics attached to the post. */ topics?: PageLink[]; /** * The last modification date of the post. */ updateDate?: string; /** * The number of words in the post. */ wordsCount?: number; }; export type PostPreviewMetaProps = Omit & { /** * The post meta. */ meta: PostPreviewMetaData; }; export const PostPreviewMeta: FC = ({ meta, ...props }) => { const intl = useIntl(); const getAuthor = (author: string): ReactElement => ( ); const getComments = ( comments: PostPreviewMetaComment ): ReactElement => { const commentsLabel = intl.formatMessage( { defaultMessage: '{commentsCount, plural, =0 {No comments} one {# comment} other {# comments}} about {title}', description: 'PostPreviewMeta: comments count', id: 'NfAn9N', }, { a11y, commentsCount: comments.count, title: comments.postHeading, } ); return ( {commentsLabel} ) : ( <>{commentsLabel} ) } /> ); }; const getPublicationDate = (date: string): ReactElement => ( } /> ); const getThematics = (thematics: PageLink[]): ReactElement => ( { return { id: `thematic-${thematic.id}`, value: {thematic.name}, }; })} /> ); const getTopics = (topics: PageLink[]): ReactElement => ( { return { id: `topic-${topic.id}`, value: {topic.name}, }; })} /> ); const getUpdateDate = (date: string): ReactElement => ( } /> ); const getReadingTime = (wordsCount: number): ReactElement => ( ); return ( {meta.author ? getAuthor(meta.author) : null} {meta.publicationDate ? getPublicationDate(meta.publicationDate) : null} {meta.updateDate && meta.updateDate !== meta.publicationDate ? getUpdateDate(meta.updateDate) : null} {meta.wordsCount ? getReadingTime(meta.wordsCount) : null} {meta.thematics ? getThematics(meta.thematics) : null} {meta.topics ? getTopics(meta.topics) : null} {meta.comments ? getComments(meta.comments) : null} ); };