diff --git a/app/soapbox/components/__tests__/status.test.tsx b/app/soapbox/components/__tests__/status.test.tsx new file mode 100644 index 000000000..ea9d04d98 --- /dev/null +++ b/app/soapbox/components/__tests__/status.test.tsx @@ -0,0 +1,42 @@ +import React from 'react'; + +import { render, screen, rootState } from '../../jest/test-helpers'; +import { normalizeStatus, normalizeAccount } from '../../normalizers'; +import Status from '../status'; + +import type { ReducerStatus } from 'soapbox/reducers/statuses'; + +const account = normalizeAccount({ + id: '1', + acct: 'alex', +}); + +const status = normalizeStatus({ + id: '1', + account, + content: 'hello world', + contentHtml: 'hello world', +}) as ReducerStatus; + +describe('', () => { + const state = rootState.setIn(['accounts', '1'], account); + + it('renders content', () => { + render(, undefined, state); + screen.getByText(/hello world/i); + expect(screen.getByTestId('status')).toHaveTextContent(/hello world/i); + }); + + describe('the Status Action Bar', () => { + it('is rendered', () => { + render(, undefined, state); + expect(screen.getByTestId('status-action-bar')).toBeInTheDocument(); + }); + + it('is not rendered if status is under review', () => { + const inReviewStatus = normalizeStatus({ ...status, visibility: 'self' }); + render(, undefined, state); + expect(screen.queryAllByTestId('status-action-bar')).toHaveLength(0); + }); + }); +}); diff --git a/app/soapbox/components/account.tsx b/app/soapbox/components/account.tsx index 9f2d17a0c..e981e66ae 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 a0543ce7e..5bf0612c7 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/modal_root.tsx b/app/soapbox/components/modal_root.tsx index a75c82f9d..ae0888da1 100644 --- a/app/soapbox/components/modal_root.tsx +++ b/app/soapbox/components/modal_root.tsx @@ -49,12 +49,13 @@ const ModalRoot: React.FC = ({ children, onCancel, onClose, type }) const isEditing = useAppSelector(state => state.compose.get('compose-modal')?.id !== null); - const handleKeyUp = useCallback((e) => { - if ((e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27) - && !!children) { + const visible = !!children; + + const handleKeyUp = (e: KeyboardEvent) => { + if (e.key === 'Escape' || e.key === 'Esc' || e.keyCode === 27) { handleOnClose(); } - }, []); + }; const handleOnClose = () => { dispatch((_, getState) => { @@ -147,6 +148,8 @@ const ModalRoot: React.FC = ({ children, onCancel, onClose, type }) }; useEffect(() => { + if (!visible) return; + window.addEventListener('keyup', handleKeyUp, false); window.addEventListener('keydown', handleKeyDown, false); @@ -154,7 +157,7 @@ const ModalRoot: React.FC = ({ children, onCancel, onClose, type }) window.removeEventListener('keyup', handleKeyUp); window.removeEventListener('keydown', handleKeyDown); }; - }, []); + }, [visible]); useEffect(() => { if (!!children && !prevChildren) { @@ -183,8 +186,6 @@ const ModalRoot: React.FC = ({ children, onCancel, onClose, type }) } }); - const visible = !!children; - if (!visible) { return (
diff --git a/app/soapbox/components/quoted-status.tsx b/app/soapbox/components/quoted-status.tsx index b521c1172..863a5d3af 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 75bdda735..c427612ec 100644 --- a/app/soapbox/components/status-action-bar.tsx +++ b/app/soapbox/components/status-action-bar.tsx @@ -279,12 +279,12 @@ const StatusActionBar: React.FC = ({ }; const handleCopy: React.EventHandler = (e) => { - const { uri } = status; + const { uri } = status; const textarea = document.createElement('textarea'); e.stopPropagation(); - textarea.textContent = uri; + textarea.textContent = uri; textarea.style.position = 'fixed'; document.body.appendChild(textarea); @@ -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(), }); } @@ -552,6 +551,7 @@ const StatusActionBar: React.FC = ({ return (
= ({ 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 961ca5fbe..f01ded300 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,11 +300,9 @@ 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'; + const isUnderReview = actualStatus.visibility === 'self'; const isSensitive = actualStatus.hidden; return ( @@ -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 && ( @@ -354,11 +360,11 @@ const Status: React.FC = (props) => { - {(inReview || isSensitive) && ( + {(isUnderReview || isSensitive) && ( = (props) => { - {!hideActionBar && ( + {(!hideActionBar && !isUnderReview) && (
diff --git a/app/soapbox/components/status_content.tsx b/app/soapbox/components/status_content.tsx index 70ee87a15..b3592c62d 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 d39cba1a6..07c778fd2 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/status/index.tsx b/app/soapbox/features/status/index.tsx index dbcc373ee..2d419ca84 100644 --- a/app/soapbox/features/status/index.tsx +++ b/app/soapbox/features/status/index.tsx @@ -134,6 +134,7 @@ const Thread: React.FC = (props) => { const me = useAppSelector(state => state.me); const status = useAppSelector(state => getStatus(state, { id: props.params.statusId })); const displayMedia = settings.get('displayMedia') as DisplayMedia; + const isUnderReview = status?.visibility === 'self'; const { ancestorsIds, descendantsIds } = useAppSelector(state => { let ancestorsIds = ImmutableOrderedSet(); @@ -412,7 +413,7 @@ const Thread: React.FC = (props) => { if (next && status) { dispatch(fetchNext(status.id, next)).then(({ next }) => { setNext(next); - }).catch(() => {}); + }).catch(() => { }); } }, 300, { leading: true }), [next, status]); @@ -475,14 +476,18 @@ const Thread: React.FC = (props) => { onOpenCompareHistoryModal={handleOpenCompareHistoryModal} /> -
- - + {!isUnderReview ? ( + <> +
+ + + + ) : null}
diff --git a/app/soapbox/features/ui/components/actions_modal.tsx b/app/soapbox/features/ui/components/actions_modal.tsx index 27faaf909..cc00126f6 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 f663c26ff..0ac611f91 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;