From 3ce20394a6dbb75fa9e748642b1f9708cdd08e1e Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Thu, 5 Dec 2024 23:48:14 -0300 Subject: [PATCH] refactor: create PureEventPreview component, used in PureStatus component --- src/components/pure-event-preview.tsx | 97 +++++++++++++++++++++++++++ src/components/pure-status.tsx | 4 +- 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 src/components/pure-event-preview.tsx diff --git a/src/components/pure-event-preview.tsx b/src/components/pure-event-preview.tsx new file mode 100644 index 000000000..1c06724ec --- /dev/null +++ b/src/components/pure-event-preview.tsx @@ -0,0 +1,97 @@ +import mapPinIcon from '@tabler/icons/outline/map-pin.svg'; +import userIcon from '@tabler/icons/outline/user.svg'; +import clsx from 'clsx'; +import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; + +import Button from 'soapbox/components/ui/button.tsx'; +import HStack from 'soapbox/components/ui/hstack.tsx'; +import Stack from 'soapbox/components/ui/stack.tsx'; +import Text from 'soapbox/components/ui/text.tsx'; +import { EntityTypes, Entities } from 'soapbox/entity-store/entities.ts'; +import PureEventActionButton from 'soapbox/features/event/components/pure-event-action-button.tsx'; +import PureEventDate from 'soapbox/features/event/components/pure-event-date.tsx'; +import { useAppSelector } from 'soapbox/hooks/useAppSelector.ts'; + +import Icon from './icon.tsx'; +import VerificationBadge from './verification-badge.tsx'; + + +const messages = defineMessages({ + eventBanner: { id: 'event.banner', defaultMessage: 'Event banner' }, + leaveConfirm: { id: 'confirmations.leave_event.confirm', defaultMessage: 'Leave event' }, + leaveMessage: { id: 'confirmations.leave_event.message', defaultMessage: 'If you want to rejoin the event, the request will be manually reviewed again. Are you sure you want to proceed?' }, +}); + +interface IPureEventPreview { + status: EntityTypes[Entities.STATUSES]; + className?: string; + hideAction?: boolean; + floatingAction?: boolean; +} + +const PureEventPreview: React.FC = ({ status, className, hideAction, floatingAction = true }) => { + const intl = useIntl(); + + const me = useAppSelector((state) => state.me); + + const account = status.account; + const event = status.event!; + + const banner = event.banner; + + const action = !hideAction && (account.id === me ? ( + + ) : ( + + )); + + return ( +
+
+ {floatingAction && action} +
+
+ {banner && {intl.formatMessage(messages.eventBanner)}} +
+ + + {event.name} + + {!floatingAction && action} + + +
+ + + + {account.display_name} + {account.verified && } + + + + + + {event.location && ( + + + + {event.location?.name} + + + )} +
+
+
+ ); +}; + +export default PureEventPreview; diff --git a/src/components/pure-status.tsx b/src/components/pure-status.tsx index 9cd85ce71..496858585 100644 --- a/src/components/pure-status.tsx +++ b/src/components/pure-status.tsx @@ -8,6 +8,7 @@ import { Link, useHistory } from 'react-router-dom'; import { openModal } from 'soapbox/actions/modals.ts'; import { unfilterStatus } from 'soapbox/actions/statuses.ts'; +import PureEventPreview from 'soapbox/components/pure-event-preview.tsx'; import PureStatusReplyMentions from 'soapbox/components/pure-status-reply-mentions.tsx'; import PureSensitiveContentOverlay from 'soapbox/components/statuses/pure-sensitive-content-overlay.tsx'; import TranslateButton from 'soapbox/components/translate-button.tsx'; @@ -31,7 +32,6 @@ import { makeGetStatus } from 'soapbox/selectors/index.ts'; import { emojifyText } from 'soapbox/utils/emojify.tsx'; import { defaultMediaVisibility, textForScreenReader, getActualStatus } from 'soapbox/utils/status.ts'; -import EventPreview from './event-preview.tsx'; import StatusActionBar from './status-action-bar.tsx'; import StatusContent from './status-content.tsx'; import StatusMedia from './status-media.tsx'; @@ -466,7 +466,7 @@ const PureStatus: React.FC = (props) => { /> )} - {actualStatus.event ? : ( // fix later + {actualStatus.event ? : (