diff --git a/CHANGELOG.md b/CHANGELOG.md index 1255b07f2..12038a0b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Chats: don't display "copy" button for messages without text. - Posts: don't have to click the play button twice for embedded videos. - index.html: remove `referrer` meta tag so it doesn't conflict with backend's `Referrer-Policy` header. +- Modals: fix media modal automatically switching to video. ### Removed - Admin: single user mode. Now the homepage can be redirected to any URL. diff --git a/app/soapbox/features/ui/components/modals/media-modal.tsx b/app/soapbox/features/ui/components/modals/media-modal.tsx index 5b5ff0dc9..94bb3f70f 100644 --- a/app/soapbox/features/ui/components/modals/media-modal.tsx +++ b/app/soapbox/features/ui/components/modals/media-modal.tsx @@ -85,9 +85,7 @@ const MediaModal: React.FC = (props) => { }; }, [index]); - const getIndex = () => { - return index !== null ? index : props.index; - }; + const getIndex = () => index !== null ? index : props.index; const toggleNavigation = () => { setNavigationHidden(!navigationHidden); @@ -164,15 +162,9 @@ const MediaModal: React.FC = (props) => { }); } - const isMultiMedia = media.map((image) => { - if (image.type !== 'image') { - return true; - } + const isMultiMedia = media.map((image) => image.type !== 'image').toArray(); - return false; - }).toArray(); - - const content = media.map(attachment => { + const content = media.map((attachment, i) => { const width = (attachment.meta.getIn(['original', 'width']) || undefined) as number | undefined; const height = (attachment.meta.getIn(['original', 'height']) || undefined) as number | undefined; @@ -204,6 +196,7 @@ const MediaModal: React.FC = (props) => { height={height} startTime={time} detailed + autoFocus={i === getIndex()} link={link} alt={attachment.description} key={attachment.url} diff --git a/app/soapbox/features/ui/components/modals/video-modal.tsx b/app/soapbox/features/ui/components/modals/video-modal.tsx index f323a397e..13bef9638 100644 --- a/app/soapbox/features/ui/components/modals/video-modal.tsx +++ b/app/soapbox/features/ui/components/modals/video-modal.tsx @@ -39,6 +39,7 @@ const VideoModal: React.FC = ({ status, account, media, time, onClo startTime={time} link={link} detailed + autoFocus alt={media.description} visible /> diff --git a/app/soapbox/features/video/index.tsx b/app/soapbox/features/video/index.tsx index bd63528e4..c06c73eca 100644 --- a/app/soapbox/features/video/index.tsx +++ b/app/soapbox/features/video/index.tsx @@ -106,6 +106,7 @@ interface IVideo { height?: number, startTime?: number, detailed?: boolean, + autoFocus?: boolean, inline?: boolean, cacheWidth?: (width: number) => void, visible?: boolean, @@ -119,6 +120,7 @@ const Video: React.FC = ({ width, visible = false, detailed = false, + autoFocus = false, cacheWidth, startTime, src, @@ -518,7 +520,7 @@ const Video: React.FC = ({ aria-label={intl.formatMessage(paused ? messages.play : messages.pause)} className='player-button' onClick={togglePlay} - autoFocus={detailed} + autoFocus={autoFocus} >