import React, { useCallback } from 'react'; import { FormattedDate, FormattedMessage } from 'react-intl'; import { useAppSelector } from 'soapbox/hooks'; import Icon from './icon'; import { Button, HStack, Stack, Text } from './ui'; import VerificationBadge from './verification_badge'; import type { Account as AccountEntity, Status as StatusEntity } from 'soapbox/types/entities'; interface IEventPreview { status: StatusEntity, } const EventPreview: React.FC = ({ status }) => { const me = useAppSelector((state) => state.me); const account = status.account as AccountEntity; const event = status.event!; const banner = status.media_attachments?.find(({ description }) => description === 'Banner'); const renderDate = useCallback(() => { if (!event.start_time) return null; const startDate = new Date(event.start_time); let date; if (event.end_time) { const endDate = new Date(event.end_time); const sameDay = startDate.getDate() === endDate.getDate() && startDate.getMonth() === endDate.getMonth() && startDate.getFullYear() === endDate.getFullYear(); if (sameDay) { date = ( <> {' - '} ); } else { date = ( <> {' - '} ); } } else { date = ( ); } return ( {date} ); }, [event.start_time, event.end_time]); return (
{account.id === me ? ( ) : event.join_state === 'accept' ? ( ) : ( )}
{banner && {banner.url}}
{event.name}
{account.verified && } {renderDate()} {event.location && ( {event.location.get('name')} )}
); }; export default EventPreview;