Merge branch 'fix-open-media-hotkey' into 'develop'

Fix open media hotkey

See merge request soapbox-pub/soapbox!2530
This commit is contained in:
marcin mikołajczak 2023-05-26 23:26:56 +00:00
commit 027c25d446

View file

@ -43,11 +43,7 @@ import ThreadStatus from './components/thread-status';
import type { VirtuosoHandle } from 'react-virtuoso'; import type { VirtuosoHandle } from 'react-virtuoso';
import type { RootState } from 'soapbox/store'; import type { RootState } from 'soapbox/store';
import type { import type { Account as AccountEntity, Status as StatusEntity } from 'soapbox/types/entities';
Account as AccountEntity,
Attachment as AttachmentEntity,
Status as StatusEntity,
} from 'soapbox/types/entities';
const messages = defineMessages({ const messages = defineMessages({
title: { id: 'status.title', defaultMessage: 'Post Details' }, title: { id: 'status.title', defaultMessage: 'Post Details' },
@ -123,8 +119,6 @@ type RouteParams = {
interface IThread { interface IThread {
params: RouteParams params: RouteParams
onOpenMedia: (media: ImmutableList<AttachmentEntity>, index: number) => void
onOpenVideo: (video: AttachmentEntity, time: number) => void
} }
const Thread: React.FC<IThread> = (props) => { const Thread: React.FC<IThread> = (props) => {
@ -231,16 +225,17 @@ const Thread: React.FC<IThread> = (props) => {
}; };
const handleHotkeyOpenMedia = (e?: KeyboardEvent) => { const handleHotkeyOpenMedia = (e?: KeyboardEvent) => {
const { onOpenMedia, onOpenVideo } = props; const media = status?.media_attachments;
const firstAttachment = status?.media_attachments.get(0);
e?.preventDefault(); e?.preventDefault();
if (status && firstAttachment) { if (media && media.size) {
if (firstAttachment.type === 'video') { const firstAttachment = media.first()!;
onOpenVideo(firstAttachment, 0);
if (media.size === 1 && firstAttachment.type === 'video') {
dispatch(openModal('VIDEO', { media: firstAttachment, status: status }));
} else { } else {
onOpenMedia(status.media_attachments, 0); dispatch(openModal('MEDIA', { media, index: 0, status: status }));
} }
} }
}; };