From 4c37afa34fd3b52778563f42da99c117a1beb901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Thu, 10 Nov 2022 17:01:41 +0100 Subject: [PATCH] Improve click handling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/components/account.tsx | 10 +++++++-- app/soapbox/components/dropdown_menu.tsx | 11 ++++++---- app/soapbox/components/quoted-status.tsx | 7 +++++- app/soapbox/components/status-action-bar.tsx | 1 - .../components/status-reply-mentions.tsx | 2 +- app/soapbox/components/status.tsx | 22 ++++++++++++------- app/soapbox/components/status_content.tsx | 2 +- app/soapbox/components/translate-button.tsx | 2 +- .../features/ui/components/actions_modal.tsx | 2 +- app/styles/components/modal.scss | 2 +- 10 files changed, 40 insertions(+), 21 deletions(-) diff --git a/app/soapbox/components/account.tsx b/app/soapbox/components/account.tsx index 9f2d17a0c0..e981e66aee 100644 --- a/app/soapbox/components/account.tsx +++ b/app/soapbox/components/account.tsx @@ -22,7 +22,13 @@ const InstanceFavicon: React.FC = ({ account }) => { const handleClick: React.MouseEventHandler = (e) => { e.stopPropagation(); - history.push(`/timeline/${account.domain}`); + + const timelineUrl = `/timeline/${account.domain}`; + if (!(e.ctrlKey || e.metaKey)) { + history.push(timelineUrl); + } else { + window.open(timelineUrl, '_blank'); + } }; return ( @@ -219,7 +225,7 @@ const Account = ({ · {timestampUrl ? ( - + event.stopPropagation()}> ) : ( diff --git a/app/soapbox/components/dropdown_menu.tsx b/app/soapbox/components/dropdown_menu.tsx index bb20c86226..01d69483dd 100644 --- a/app/soapbox/components/dropdown_menu.tsx +++ b/app/soapbox/components/dropdown_menu.tsx @@ -143,12 +143,14 @@ class DropdownMenu extends React.PureComponent {icon && } diff --git a/app/soapbox/components/quoted-status.tsx b/app/soapbox/components/quoted-status.tsx index b521c1172b..863a5d3afe 100644 --- a/app/soapbox/components/quoted-status.tsx +++ b/app/soapbox/components/quoted-status.tsx @@ -44,7 +44,12 @@ const QuotedStatus: React.FC = ({ status, onCancel, compose }) => const account = status.account as AccountEntity; if (!compose && e.button === 0) { - history.push(`/@${account.acct}/posts/${status.id}`); + const statusUrl = `/@${account.acct}/posts/${status.id}`; + if (!(e.ctrlKey || e.metaKey)) { + history.push(statusUrl); + } else { + window.open(statusUrl, '_blank'); + } e.stopPropagation(); e.preventDefault(); } diff --git a/app/soapbox/components/status-action-bar.tsx b/app/soapbox/components/status-action-bar.tsx index a5bd99d71a..df737d7fca 100644 --- a/app/soapbox/components/status-action-bar.tsx +++ b/app/soapbox/components/status-action-bar.tsx @@ -459,7 +459,6 @@ const StatusActionBar: React.FC = ({ text: intl.formatMessage(messages.admin_status), href: `/pleroma/admin/#/statuses/${status.id}/`, icon: require('@tabler/icons/pencil.svg'), - action: (event) => event.stopPropagation(), }); } diff --git a/app/soapbox/components/status-reply-mentions.tsx b/app/soapbox/components/status-reply-mentions.tsx index ce0451fda9..4d65abd11e 100644 --- a/app/soapbox/components/status-reply-mentions.tsx +++ b/app/soapbox/components/status-reply-mentions.tsx @@ -50,7 +50,7 @@ const StatusReplyMentions: React.FC = ({ status, hoverable // The typical case with a reply-to and a list of mentions. const accounts = to.slice(0, 2).map(account => { const link = ( - @{account.username} + e.stopPropagation()}>@{account.username} ); if (hoverable) { diff --git a/app/soapbox/components/status.tsx b/app/soapbox/components/status.tsx index 961ca5fbe7..1a2179df82 100644 --- a/app/soapbox/components/status.tsx +++ b/app/soapbox/components/status.tsx @@ -84,6 +84,8 @@ const Status: React.FC = (props) => { const actualStatus = getActualStatus(status); + const statusUrl = `/@${actualStatus.getIn(['account', 'acct'])}/posts/${actualStatus.id}`; + // Track height changes we know about to compensate scrolling. useEffect(() => { didShowCard.current = Boolean(!muted && !hidden && status?.card); @@ -97,11 +99,17 @@ const Status: React.FC = (props) => { setShowMedia(!showMedia); }; - const handleClick = (): void => { - if (onClick) { - onClick(); + const handleClick = (e?: React.MouseEvent): void => { + e?.stopPropagation(); + + if (!e || !(e.ctrlKey || e.metaKey)) { + if (onClick) { + onClick(); + } else { + history.push(statusUrl); + } } else { - history.push(`/@${actualStatus.getIn(['account', 'acct'])}/posts/${actualStatus.id}`); + window.open(statusUrl, '_blank'); } }; @@ -145,7 +153,7 @@ const Status: React.FC = (props) => { }; const handleHotkeyOpen = (): void => { - history.push(`/@${actualStatus.getIn(['account', 'acct'])}/posts/${actualStatus.id}`); + history.push(statusUrl); }; const handleHotkeyOpenProfile = (): void => { @@ -292,8 +300,6 @@ const Status: React.FC = (props) => { react: handleHotkeyReact, }; - const statusUrl = `/@${actualStatus.getIn(['account', 'acct'])}/posts/${actualStatus.id}`; - const accountAction = props.accountAction || reblogElement; const inReview = actualStatus.visibility === 'self'; @@ -307,7 +313,7 @@ const Status: React.FC = (props) => { data-featured={featured ? 'true' : null} aria-label={textForScreenReader(intl, actualStatus, rebloggedByText)} ref={node} - onClick={() => history.push(statusUrl)} + onClick={handleClick} role='link' > {featured && ( diff --git a/app/soapbox/components/status_content.tsx b/app/soapbox/components/status_content.tsx index 70ee87a15e..b3592c62d4 100644 --- a/app/soapbox/components/status_content.tsx +++ b/app/soapbox/components/status_content.tsx @@ -147,7 +147,7 @@ const StatusContent: React.FC = ({ status, onClick, collapsable return; } - if (deltaX + deltaY < 5 && e.button === 0 && onClick) { + if (deltaX + deltaY < 5 && e.button === 0 && !(e.ctrlKey || e.metaKey) && onClick) { onClick(); } diff --git a/app/soapbox/components/translate-button.tsx b/app/soapbox/components/translate-button.tsx index d39cba1a64..07c778fd22 100644 --- a/app/soapbox/components/translate-button.tsx +++ b/app/soapbox/components/translate-button.tsx @@ -19,7 +19,7 @@ const TranslateButton: React.FC = ({ status }) => { const me = useAppSelector((state) => state.me); - const renderTranslate = /* translationEnabled && */ me && ['public', 'unlisted'].includes(status.visibility) && status.contentHtml.length > 0 && status.language !== null && intl.locale !== status.language; + const renderTranslate = me && ['public', 'unlisted'].includes(status.visibility) && status.contentHtml.length > 0 && status.language !== null && intl.locale !== status.language; const handleTranslate: React.MouseEventHandler = (e) => { e.stopPropagation(); diff --git a/app/soapbox/features/ui/components/actions_modal.tsx b/app/soapbox/features/ui/components/actions_modal.tsx index 27faaf9093..cc00126f63 100644 --- a/app/soapbox/features/ui/components/actions_modal.tsx +++ b/app/soapbox/features/ui/components/actions_modal.tsx @@ -40,7 +40,7 @@ const ActionsModal: React.FC = ({ status, actions, onClick, onClo className={classNames('w-full', { active, destructive })} data-method={isLogout ? 'delete' : null} > - {icon && } + {icon && }
{text}
{meta}
diff --git a/app/styles/components/modal.scss b/app/styles/components/modal.scss index f663c26ffd..0ac611f91b 100644 --- a/app/styles/components/modal.scss +++ b/app/styles/components/modal.scss @@ -311,7 +311,7 @@ } .svg-icon:first-child { - @apply w-5 h-5 mr-2.5; + @apply min-w-[1.25rem] w-5 h-5 mr-2.5; svg { stroke-width: 1.5;