From 60489cb123ad1f4b9728bff857ade7210bca347f Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Tue, 10 Dec 2024 22:37:38 -0300 Subject: [PATCH] refactor: dispatch openModal() 'MEDIA' with raw objects --- src/components/status.tsx | 2 +- src/components/upload.tsx | 2 +- src/features/account-gallery/index.tsx | 2 +- src/features/account/components/header.tsx | 4 ++-- src/features/chats/components/chat-upload.tsx | 2 +- src/features/event/components/event-header.tsx | 2 +- src/features/group/components/group-header.tsx | 4 ++-- src/features/group/group-gallery.tsx | 2 +- src/features/status/components/thread.tsx | 2 +- src/features/ui/components/group-media-panel.tsx | 2 +- src/features/ui/components/profile-media-panel.tsx | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/components/status.tsx b/src/components/status.tsx index 1b189d5d1..228dc224e 100644 --- a/src/components/status.tsx +++ b/src/components/status.tsx @@ -151,7 +151,7 @@ const Status: React.FC = (props) => { if (firstAttachment.type === 'video') { dispatch(openModal('VIDEO', { status, media: firstAttachment, time: 0 })); } else { - dispatch(openModal('MEDIA', { status, media: status.media_attachments, index: 0 })); + dispatch(openModal('MEDIA', { status: status.toJS(), media: status.media_attachments.toJS(), index: 0 })); } } }; diff --git a/src/components/upload.tsx b/src/components/upload.tsx index 53aa79d91..299075375 100644 --- a/src/components/upload.tsx +++ b/src/components/upload.tsx @@ -140,7 +140,7 @@ const Upload: React.FC = ({ }; const handleOpenModal = () => { - dispatch(openModal('MEDIA', { media: ImmutableList.of(media), index: 0 })); + dispatch(openModal('MEDIA', { media: ImmutableList.of(media).toJS(), index: 0 })); }; const active = hovered || focused; diff --git a/src/features/account-gallery/index.tsx b/src/features/account-gallery/index.tsx index 9d163bc46..ddc7fe962 100644 --- a/src/features/account-gallery/index.tsx +++ b/src/features/account-gallery/index.tsx @@ -74,7 +74,7 @@ const AccountGallery = () => { const media = (attachment.status as Status).media_attachments; const index = media.findIndex((x) => x.id === attachment.id); - dispatch(openModal('MEDIA', { media, index, status: attachment.status })); + dispatch(openModal('MEDIA', { media: media.toJS(), index, status: attachment?.status?.toJS() ?? attachment.status })); } }; diff --git a/src/features/account/components/header.tsx b/src/features/account/components/header.tsx index 76f8919a4..952a02146 100644 --- a/src/features/account/components/header.tsx +++ b/src/features/account/components/header.tsx @@ -266,7 +266,7 @@ const Header: React.FC = ({ account }) => { type: 'image', url: account.avatar, }); - dispatch(openModal('MEDIA', { media: ImmutableList.of(avatar), index: 0 })); + dispatch(openModal('MEDIA', { media: ImmutableList.of(avatar).toJS(), index: 0 })); }; const handleAvatarClick: React.MouseEventHandler = (e) => { @@ -281,7 +281,7 @@ const Header: React.FC = ({ account }) => { type: 'image', url: account.header, }); - dispatch(openModal('MEDIA', { media: ImmutableList.of(header), index: 0 })); + dispatch(openModal('MEDIA', { media: ImmutableList.of(header).toJS(), index: 0 })); }; const handleHeaderClick: React.MouseEventHandler = (e) => { diff --git a/src/features/chats/components/chat-upload.tsx b/src/features/chats/components/chat-upload.tsx index 4caf51998..b701966cd 100644 --- a/src/features/chats/components/chat-upload.tsx +++ b/src/features/chats/components/chat-upload.tsx @@ -22,7 +22,7 @@ const ChatUpload: React.FC = ({ attachment, onDelete }) => { const clickable = attachment.type !== 'unknown'; const handleOpenModal = () => { - dispatch(openModal('MEDIA', { media: ImmutableList.of(attachment), index: 0 })); + dispatch(openModal('MEDIA', { media: ImmutableList.of(attachment).toJS(), index: 0 })); }; return ( diff --git a/src/features/event/components/event-header.tsx b/src/features/event/components/event-header.tsx index 4c191a5c9..1a3d382d2 100644 --- a/src/features/event/components/event-header.tsx +++ b/src/features/event/components/event-header.tsx @@ -128,7 +128,7 @@ const EventHeader: React.FC = ({ status }) => { e.preventDefault(); e.stopPropagation(); - dispatch(openModal('MEDIA', { media: ImmutableList([event.banner]) })); + dispatch(openModal('MEDIA', { media: ImmutableList([event.banner]).toJS() })); }; const handleExportClick = () => { diff --git a/src/features/group/components/group-header.tsx b/src/features/group/components/group-header.tsx index 71fdc2dcc..714cc25e6 100644 --- a/src/features/group/components/group-header.tsx +++ b/src/features/group/components/group-header.tsx @@ -63,7 +63,7 @@ const GroupHeader: React.FC = ({ group }) => { type: 'image', url: group.avatar, }); - dispatch(openModal('MEDIA', { media: ImmutableList.of(avatar), index: 0 })); + dispatch(openModal('MEDIA', { media: ImmutableList.of(avatar).toJS(), index: 0 })); }; const handleAvatarClick: React.MouseEventHandler = (e) => { @@ -78,7 +78,7 @@ const GroupHeader: React.FC = ({ group }) => { type: 'image', url: group.header, }); - dispatch(openModal('MEDIA', { media: ImmutableList.of(header), index: 0 })); + dispatch(openModal('MEDIA', { media: ImmutableList.of(header).toJS(), index: 0 })); }; const handleHeaderClick: React.MouseEventHandler = (e) => { diff --git a/src/features/group/group-gallery.tsx b/src/features/group/group-gallery.tsx index 4adeaec0f..28b2d2e0f 100644 --- a/src/features/group/group-gallery.tsx +++ b/src/features/group/group-gallery.tsx @@ -43,7 +43,7 @@ const GroupGallery: React.FC = (props) => { const media = (attachment.status as Status).media_attachments; const index = media.findIndex((x) => x.id === attachment.id); - dispatch(openModal('MEDIA', { media, index, status: attachment.status })); + dispatch(openModal('MEDIA', { media: media.toJS(), index, status: attachment?.status?.toJS() ?? attachment.status })); } }; diff --git a/src/features/status/components/thread.tsx b/src/features/status/components/thread.tsx index 3d307b1cd..bd0734098 100644 --- a/src/features/status/components/thread.tsx +++ b/src/features/status/components/thread.tsx @@ -179,7 +179,7 @@ const Thread = (props: IThread) => { if (media.size === 1 && firstAttachment.type === 'video') { dispatch(openModal('VIDEO', { media: firstAttachment, status: status })); } else { - dispatch(openModal('MEDIA', { media, index: 0, status: status })); + dispatch(openModal('MEDIA', { media: media.toJS(), index: 0, status: status.toJS() })); } } }; diff --git a/src/features/ui/components/group-media-panel.tsx b/src/features/ui/components/group-media-panel.tsx index 801bb403e..fc4147b2f 100644 --- a/src/features/ui/components/group-media-panel.tsx +++ b/src/features/ui/components/group-media-panel.tsx @@ -36,7 +36,7 @@ const GroupMediaPanel: React.FC = ({ group }) => { const media = attachment.getIn(['status', 'media_attachments']) as ImmutableList; const index = media.findIndex(x => x.id === attachment.id); - dispatch(openModal('MEDIA', { media, index, status: attachment.status, account: attachment.account })); + dispatch(openModal('MEDIA', { media: media.toJS(), index, status: attachment?.status?.toJS() ?? attachment.status, account: attachment.account })); // NOTE: why 'account' field is here? it doesn't exist in MediaModal component } }; diff --git a/src/features/ui/components/profile-media-panel.tsx b/src/features/ui/components/profile-media-panel.tsx index d155c2ece..a13f8a45e 100644 --- a/src/features/ui/components/profile-media-panel.tsx +++ b/src/features/ui/components/profile-media-panel.tsx @@ -34,7 +34,7 @@ const ProfileMediaPanel: React.FC = ({ account }) => { const media = attachment.getIn(['status', 'media_attachments']) as ImmutableList; const index = media.findIndex(x => x.id === attachment.id); - dispatch(openModal('MEDIA', { media, index, status: attachment.status })); + dispatch(openModal('MEDIA', { media: media.toJS(), index, status: attachment?.status?.toJS() ?? attachment.status })); } };