From 2828f233d5f663aa8f91517505fdb30008cda090 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 15 Apr 2022 19:14:34 -0500 Subject: [PATCH] Restore ProfileMediaPanel, convert to TSX+FC --- .../ui/components/profile_media_panel.js | Bin 3812 -> 0 bytes .../ui/components/profile_media_panel.tsx | 90 ++++++++++++++++++ app/soapbox/pages/profile_page.js | Bin 5614 -> 5786 bytes .../components/profile-media-panel.scss | 2 - 4 files changed, 90 insertions(+), 2 deletions(-) delete mode 100644 app/soapbox/features/ui/components/profile_media_panel.js create mode 100644 app/soapbox/features/ui/components/profile_media_panel.tsx diff --git a/app/soapbox/features/ui/components/profile_media_panel.js b/app/soapbox/features/ui/components/profile_media_panel.js deleted file mode 100644 index 54482ad79f126c04d8c899f06762471f658bd495..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3812 zcmb7H+iu)85PkPoFhCJW=&rUXkcT>!Tcb{k1?nVl-1eaeHnKG9Wvg3B%2`9$fA0)0 zBBk{OH4MWN=X&PMaK!7b6^eZnZFlp~fn;0J)-3Aqd8z0{^!9`snQO=kWzPlu?~m4X z-K+ezg1H?nx8&}4Np@#uy>2hy=N5f6&`kV<`Y5w3oRAM-V867Y&Xt1l3Z%^MV8M9v zHxz2!sEQrJu$LTPg{no{G$=Wf5>WPg6m#hhtnHw=YRlZ)lWpGJw)+)=!P`czYB~)d zTcc^~+KG!)vH`1EYa7U725(nz9l>c3N|-ptdPG1s&1m&V;lI60XVBhNA|BQ&hQ> z#Jnx9K->D5H&8LyD`-l|o*>3>a>AHYx#9&QIvLt#Y{1uyO| z2Q5ZYJ4C;N4@4(I1m%&rHXN3n+f?|L#r}PY#f~HDohV^hma*ubm(b#aNt`jY<1!^g zWa?s$N6N<0AM49^AEE^tm@dO<;B%qz>=B8%Kf<|}=;V+jZ#8fS29<=-DNAS7-Qwe#-o*Isob3$)ytMgyL;e8m=^$SO zjKjhcZ0_GOZ-NyDbD)T}fCO^2jwmsd2((1&5PcH@zYHCZ&Aq0aAJNl|nH?s1fK(rFuf+N#vpjK`@> zj=g@3)5GexmmzdCOpJ{NzG@pme+5R4--cE+epEkW}85`y<>b#2s5bOxiz3qJvs%N_K>7ESC(ZN6P zkPTnH8J@)s=iTSz@aa- z&=jBDSyP2oh*XmJ!?P8F><(?QXE(_Is|!$BCxtniZ+?uIwwN1T%v9@aYO@zctb}de zSIX{*S@gcO_tzH3Pnkw6$mY@b5pq3-Ov4>_nVG}SbXYJly%b%PU`O^0lV_M3K=F*! zatArihCmo;sh3kJifj;OkBOt7^b#-hW@`3Rxhk+ZM4rm~JLKCF{bKEJHhQHE0YpEz zJ~c1tRrxJclkiaS#lkACDmX5v?zc%9(b$T@a7?7Q}$ z4ULx}`!Sd`rbW-(h95ADP7-!{B&(b5k&zyRhl;+_j#6?*L8iI^k-GS6CN9n}eTm<+ z`tHO*A8Q)Ymgo>Un2|eO0-?W--{d;%hF-YuE;RH7(akjA=~2CTMN_5B^iJAOHXW diff --git a/app/soapbox/features/ui/components/profile_media_panel.tsx b/app/soapbox/features/ui/components/profile_media_panel.tsx new file mode 100644 index 0000000000..29738ec3fc --- /dev/null +++ b/app/soapbox/features/ui/components/profile_media_panel.tsx @@ -0,0 +1,90 @@ +import { List as ImmutableList } from 'immutable'; +import React, { useState, useEffect } from 'react'; +import { FormattedMessage } from 'react-intl'; +import { useDispatch } from 'react-redux'; + +import { openModal } from 'soapbox/actions/modals'; +import { Spinner, Widget } from 'soapbox/components/ui'; +import { useAppSelector } from 'soapbox/hooks'; +import { getAccountGallery } from 'soapbox/selectors'; + +import { expandAccountMediaTimeline } from '../../../actions/timelines'; +import MediaItem from '../../account_gallery/components/media_item'; + +import type { Account, Attachment } from 'soapbox/types/entities'; + +interface IProfileMediaPanel { + account?: Account, +} + +const ProfileMediaPanel: React.FC = ({ account }) => { + const dispatch = useDispatch(); + + const [loading, setLoading] = useState(true); + + const attachments: ImmutableList = useAppSelector((state) => account ? getAccountGallery(state, account?.id) : ImmutableList()); + + const handleOpenMedia = (attachment: Attachment): void => { + if (attachment.type === 'video') { + dispatch(openModal('VIDEO', { media: attachment, status: attachment.status })); + } else { + 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 })); + } + }; + + useEffect(() => { + setLoading(true); + + if (account) { + dispatch(expandAccountMediaTimeline(account.id)) + // @ts-ignore yes it does + .then(() => setLoading(false)) + .catch(() => {}); + } + }, [account?.id]); + + const renderAttachments = () => { + const publicAttachments = attachments.filter(attachment => attachment.getIn(['status', 'visibility']) === 'public'); + const nineAttachments = publicAttachments.slice(0, 9); + + if (!nineAttachments.isEmpty()) { + return ( +
+ {nineAttachments.map((attachment, _index) => ( + + ))} +
+ ); + } else { + return ( +
+ +
+ ); + } + }; + + return ( + }> + {account && ( +
+ {loading ? ( + + ) : ( + renderAttachments() + )} +
+ )} +
+ ); +}; + +export default ProfileMediaPanel; diff --git a/app/soapbox/pages/profile_page.js b/app/soapbox/pages/profile_page.js index 05960b6fee236bb1d83206c5b7f6aed78ea7f55c..b4b3854c2897dfb11d289489154d74d8c12b1d3c 100644 GIT binary patch delta 68 zcmaE-Jxg~(E)!2cQGQxxPO5KeN@n8b6sA7G$uC3{Cm#@G=LHJ|B<7{&)Y@@Pt`}CF VEH0!l*;+_=a)T(>=1;