import React from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { Link } from 'react-router-dom'; import { fetchEventIcs } from 'soapbox/actions/events'; import { openModal } from 'soapbox/actions/modals'; import Icon from 'soapbox/components/icon'; import StillImage from 'soapbox/components/still_image'; import { HStack, IconButton, Menu, MenuButton, MenuDivider, MenuItem, MenuLink, MenuList, Stack, Text } from 'soapbox/components/ui'; import SvgIcon from 'soapbox/components/ui/icon/svg-icon'; import VerificationBadge from 'soapbox/components/verification_badge'; import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; import { download } from 'soapbox/utils/download'; import PlaceholderEventHeader from '../../placeholder/components/placeholder_event_header'; import EventActionButton from '../components/event-action-button'; import EventDate from '../components/event-date'; import type { Menu as MenuType } from 'soapbox/components/dropdown_menu'; import type { Account as AccountEntity, Status as StatusEntity } from 'soapbox/types/entities'; const messages = defineMessages({ bannerHeader: { id: 'event.banner', defaultMessage: 'Event banner' }, exportIcs: { id: 'event.export_ics', defaultMessage: 'Export to your calendar' }, copy: { id: 'event.copy', defaultMessage: 'Copy link to event' }, }); interface IEventHeader { status?: StatusEntity, } const EventHeader: React.FC = ({ status }) => { const intl = useIntl(); const dispatch = useAppDispatch(); const me = useAppSelector(state => state.me); if (!status || !status.event) { return ( <>
); } const account = status.account as AccountEntity; const event = status.event; const banner = status.media_attachments?.find(({ description }) => description === 'Banner'); const handleHeaderClick: React.MouseEventHandler = (e) => { e.preventDefault(); const index = status.media_attachments!.findIndex(({ description }) => description === 'Banner'); dispatch(openModal('MEDIA', { media: status.media_attachments, index })); }; const handleExportClick: React.MouseEventHandler = e => { dispatch(fetchEventIcs(status.id)).then((response) => { download(response, 'calendar.ics'); }).catch(() => {}); e.preventDefault(); }; const menu: MenuType = [ { text: intl.formatMessage(messages.exportIcs), action: handleExportClick, icon: require('@tabler/icons/calendar-plus.svg'), }, ]; return ( <>
{banner && ( )}
{event.name} {menu.map((menuItem, idx) => { if (typeof menuItem?.text === 'undefined') { return ; } else { const Comp = (menuItem.action ? MenuItem : MenuLink) as any; const itemProps = menuItem.action ? { onSelect: menuItem.action } : { to: menuItem.to, as: Link, target: menuItem.newTab ? '_blank' : '_self' }; return (
{menuItem.icon && ( )}
{menuItem.text}
); } })}
{account.id !== me && }
{account.verified && } ), }} /> {event.location && ( {event.location.get('name')} )}
); }; export default EventHeader;