From 3c8c8048e585e154593f91d3eabcea6ad148a4ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Thu, 6 Oct 2022 00:01:26 +0200 Subject: [PATCH] Minor improvements, add actions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/components/event-preview.tsx | 7 +- app/soapbox/components/quoted-status.tsx | 2 +- .../event/components/event-header.tsx | 237 +++++++++++++++--- .../features/event/event-information.tsx | 24 +- .../features/ui/components/compose-button.tsx | 2 +- .../compose-event-modal.tsx | 232 ++++++++--------- 6 files changed, 338 insertions(+), 166 deletions(-) diff --git a/app/soapbox/components/event-preview.tsx b/app/soapbox/components/event-preview.tsx index 719184be7..a0c2ff7f5 100644 --- a/app/soapbox/components/event-preview.tsx +++ b/app/soapbox/components/event-preview.tsx @@ -21,9 +21,10 @@ const messages = defineMessages({ interface IEventPreview { status: StatusEntity, className?: string, + hideAction?: boolean; } -const EventPreview: React.FC = ({ status, className }) => { +const EventPreview: React.FC = ({ status, className, hideAction }) => { const intl = useIntl(); const me = useAppSelector((state) => state.me); @@ -36,7 +37,7 @@ const EventPreview: React.FC = ({ status, className }) => { return (
- {account.id === me ? ( + {!hideAction && (account.id === me ? ( - ) : } + ) : )}
{banner && {intl.formatMessage(messages.bannerHeader)}} diff --git a/app/soapbox/components/quoted-status.tsx b/app/soapbox/components/quoted-status.tsx index 6b6e87209..a8846f9e8 100644 --- a/app/soapbox/components/quoted-status.tsx +++ b/app/soapbox/components/quoted-status.tsx @@ -147,7 +147,7 @@ const QuotedStatus: React.FC = ({ status, onCancel, compose }) => {renderReplyMentions()} - {status.event ? : ( + {status.event ? : ( <> = ({ status }) => { const intl = useIntl(); const dispatch = useAppDispatch(); + const history = useHistory(); + const features = useFeatures(); const ownAccount = useOwnAccount(); const isStaff = ownAccount ? ownAccount.staff : false; const isAdmin = ownAccount ? ownAccount.admin : false; @@ -62,6 +88,8 @@ const EventHeader: React.FC = ({ status }) => { const event = status.event; const banner = status.media_attachments?.find(({ description }) => description === 'Banner'); + const username = account.username; + const handleHeaderClick: React.MouseEventHandler = (e) => { e.stopPropagation(); @@ -94,6 +122,63 @@ const EventHeader: React.FC = ({ status }) => { } }; + const handleBookmarkClick = () => { + dispatch(toggleBookmark(status)); + }; + + const handleQuoteClick = () => { + dispatch(quoteCompose(status)); + }; + + const handlePinClick = () => { + dispatch(togglePin(status)); + }; + + const handleDeleteClick = () => { + dispatch(openModal('CONFIRM', { + icon: require('@tabler/icons/trash.svg'), + heading: intl.formatMessage(messages.deleteHeading), + message: intl.formatMessage(messages.deleteMessage), + confirm: intl.formatMessage(messages.deleteConfirm), + onConfirm: () => dispatch(deleteStatus(status.id)), + })); + }; + + const handleMentionClick = () => { + dispatch(mentionCompose(account)); + }; + + const handleChatClick = () => { + dispatch(launchChat(account.id, history)); + }; + + const handleDirectClick = () => { + dispatch(directCompose(account)); + }; + + const handleMuteClick = () => { + dispatch(initMuteModal(account)); + }; + + const handleBlockClick = () => { + dispatch(openModal('CONFIRM', { + icon: require('@tabler/icons/ban.svg'), + heading: , + message: @{account.acct} }} />, + confirm: intl.formatMessage(messages.blockConfirm), + onConfirm: () => dispatch(blockAccount(account.id)), + secondary: intl.formatMessage(messages.blockAndReport), + onSecondary: () => { + dispatch(blockAccount(account.id)); + dispatch(initReport(account, status)); + }, + })); + }; + + const handleReport = () => { + dispatch(initReport(account, status)); + }; + const handleModerate = () => { dispatch(openModal('ACCOUNT_MODERATION', { accountId: account.id })); }; @@ -110,51 +195,129 @@ const EventHeader: React.FC = ({ status }) => { dispatch(deleteStatusModal(intl, status.id)); }; - const menu: MenuType = [ - { - text: intl.formatMessage(messages.exportIcs), - action: handleExportClick, - icon: require('@tabler/icons/calendar-plus.svg'), - }, - { - text: intl.formatMessage(messages.copy), - action: handleCopy, - icon: require('@tabler/icons/link.svg'), - }, - ]; + const makeMenu = () => { + const menu: MenuType = [ + { + text: intl.formatMessage(messages.exportIcs), + action: handleExportClick, + icon: require('@tabler/icons/calendar-plus.svg'), + }, + { + text: intl.formatMessage(messages.copy), + action: handleCopy, + icon: require('@tabler/icons/link.svg'), + }, + ]; - if (isStaff) { - menu.push(null); + if (!ownAccount) return menu; - menu.push({ - text: intl.formatMessage(messages.adminAccount, { name: account.username }), - action: handleModerate, - icon: require('@tabler/icons/gavel.svg'), - }); - - if (isAdmin) { + if (features.bookmarks) { menu.push({ - text: intl.formatMessage(messages.adminStatus), - action: handleModerateStatus, - icon: require('@tabler/icons/pencil.svg'), + text: intl.formatMessage(status.bookmarked ? messages.unbookmark : messages.bookmark), + action: handleBookmarkClick, + icon: status.bookmarked ? require('@tabler/icons/bookmark-off.svg') : require('@tabler/icons/bookmark.svg'), }); } - menu.push({ - text: intl.formatMessage(status.sensitive === false ? messages.markStatusSensitive : messages.markStatusNotSensitive), - action: handleToggleStatusSensitivity, - icon: require('@tabler/icons/alert-triangle.svg'), - }); - - if (account.id !== ownAccount?.id) { + if (features.quotePosts) { menu.push({ - text: intl.formatMessage(messages.deleteStatus), - action: handleDeleteStatus, + text: intl.formatMessage(messages.quotePost), + action: handleQuoteClick, + icon: require('@tabler/icons/quote.svg'), + }); + } + + menu.push(null); + + if (ownAccount.id === account.id) { + if (['public', 'unlisted'].includes(status.visibility)) { + menu.push({ + text: intl.formatMessage(status.pinned ? messages.unpin : messages.pin), + action: handlePinClick, + icon: status.pinned ? require('@tabler/icons/pinned-off.svg') : require('@tabler/icons/pin.svg'), + }); + } + + menu.push({ + text: intl.formatMessage(messages.delete), + action: handleDeleteClick, icon: require('@tabler/icons/trash.svg'), destructive: true, }); + } else { + menu.push({ + text: intl.formatMessage(messages.mention, { name: username }), + action: handleMentionClick, + icon: require('@tabler/icons/at.svg'), + }); + + if (status.getIn(['account', 'pleroma', 'accepts_chat_messages']) === true) { + menu.push({ + text: intl.formatMessage(messages.chat, { name: username }), + action: handleChatClick, + icon: require('@tabler/icons/messages.svg'), + }); + } else if (features.privacyScopes) { + menu.push({ + text: intl.formatMessage(messages.direct, { name: username }), + action: handleDirectClick, + icon: require('@tabler/icons/mail.svg'), + }); + } + + menu.push(null); + menu.push({ + text: intl.formatMessage(messages.mute, { name: username }), + action: handleMuteClick, + icon: require('@tabler/icons/circle-x.svg'), + }); + menu.push({ + text: intl.formatMessage(messages.block, { name: username }), + action: handleBlockClick, + icon: require('@tabler/icons/ban.svg'), + }); + menu.push({ + text: intl.formatMessage(messages.report, { name: username }), + action: handleReport, + icon: require('@tabler/icons/flag.svg'), + }); } - } + + if (isStaff) { + menu.push(null); + + menu.push({ + text: intl.formatMessage(messages.adminAccount, { name: account.username }), + action: handleModerate, + icon: require('@tabler/icons/gavel.svg'), + }); + + if (isAdmin) { + menu.push({ + text: intl.formatMessage(messages.adminStatus), + action: handleModerateStatus, + icon: require('@tabler/icons/pencil.svg'), + }); + } + + menu.push({ + text: intl.formatMessage(status.sensitive === false ? messages.markStatusSensitive : messages.markStatusNotSensitive), + action: handleToggleStatusSensitivity, + icon: require('@tabler/icons/alert-triangle.svg'), + }); + + if (account.id !== ownAccount?.id) { + menu.push({ + text: intl.formatMessage(messages.deleteStatus), + action: handleDeleteStatus, + icon: require('@tabler/icons/trash.svg'), + destructive: true, + }); + } + } + + return menu; + }; const handleManageClick: React.MouseEventHandler = e => { e.stopPropagation(); @@ -199,7 +362,7 @@ const EventHeader: React.FC = ({ status }) => { /> - {menu.map((menuItem, idx) => { + {makeMenu().map((menuItem, idx) => { if (typeof menuItem?.text === 'undefined') { return ; } else { diff --git a/app/soapbox/features/event/event-information.tsx b/app/soapbox/features/event/event-information.tsx index 980cbd089..01ae26595 100644 --- a/app/soapbox/features/event/event-information.tsx +++ b/app/soapbox/features/event/event-information.tsx @@ -45,7 +45,7 @@ const EventInformation: React.FC = ({ params }) => { }; const handleShowMap: React.MouseEventHandler = (e) => { - e.stopPropagation(); + e.preventDefault(); dispatch(openModal('EVENT_MAP', { statusId: status.id, @@ -138,16 +138,18 @@ const EventInformation: React.FC = ({ params }) => { return ( - - - - - - + {!!status.contentHtml.trim() && ( + + + + + + + )} { const dispatch = useDispatch(); - const onOpenCompose = () => dispatch(openModal('COMPOSE_EVENT')); + const onOpenCompose = () => dispatch(openModal('COMPOSE')); return (
diff --git a/app/soapbox/features/ui/components/modals/compose-event-modal/compose-event-modal.tsx b/app/soapbox/features/ui/components/modals/compose-event-modal/compose-event-modal.tsx index 0c24d21f1..9569e7306 100644 --- a/app/soapbox/features/ui/components/modals/compose-event-modal/compose-event-modal.tsx +++ b/app/soapbox/features/ui/components/modals/compose-event-modal/compose-event-modal.tsx @@ -185,6 +185,124 @@ const ComposeEventModal: React.FC = ({ onClose }) => { return ; }; + let body; + if (tab === 'edit') body = ( +
+ } + > +
+ {banner ? ( + <> + + + + ) : ( + + )} + +
+
+ } + > + + + } + hintText={} + > +