webapp/src/components/Article/CommentDate.tsx
Kosta 85e8533931
dates in notifications, lots of minor fixes (#271)
* dates in notifications, lots of minor fixes
Co-authored-by: Igor Lobanov <igor.lobanov@onetwotrip.com>
2023-10-18 13:56:41 +03:00

37 lines
1.1 KiB
TypeScript

import { Show } from 'solid-js'
import { Icon } from '../_shared/Icon'
import type { Reaction } from '../../graphql/types.gen'
import { useLocalize } from '../../context/localize'
import { clsx } from 'clsx'
import styles from './CommentDate.module.scss'
type Props = {
comment: Reaction
isShort?: boolean
isLastInRow?: boolean
}
export const CommentDate = (props: Props) => {
const { t, formatDate } = useLocalize()
const formattedDate = (date: number) => {
const formatDateOptions: Intl.DateTimeFormatOptions = props.isShort
? { month: 'long', day: 'numeric', year: 'numeric' }
: { hour: 'numeric', minute: 'numeric' }
return formatDate(new Date(date), formatDateOptions)
}
return (
<div class={clsx(styles.commentDates, { [styles.commentDatesLastInRow]: props.isLastInRow })}>
<time class={styles.date}>{formattedDate(props.comment.createdAt)}</time>
<Show when={props.comment.updatedAt}>
<time class={styles.date}>
<Icon name="edit" class={styles.icon} />
{t('Edited')} {formattedDate(props.comment.updatedAt)}
</time>
</Show>
</div>
)
}