From cc3e8ebd3be5bdf647613e6e8de35952b5062168 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Fri, 30 Sep 2022 18:11:05 -0500 Subject: [PATCH] MediaGallery: clean up unused code, rearrange useEffect --- app/soapbox/components/media_gallery.tsx | 47 ++++++++---------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/app/soapbox/components/media_gallery.tsx b/app/soapbox/components/media_gallery.tsx index 0744361a4..5d5db8753 100644 --- a/app/soapbox/components/media_gallery.tsx +++ b/app/soapbox/components/media_gallery.tsx @@ -80,8 +80,6 @@ const Item: React.FC = ({ const settings = useSettings(); const autoPlayGif = settings.get('autoPlayGif') === true; - const [loaded, setLoaded] = useState(false); - const handleMouseEnter: React.MouseEventHandler = ({ currentTarget: video }) => { if (hoverToPlay()) { video.play(); @@ -118,10 +116,6 @@ const Item: React.FC = ({ e.stopPropagation(); }; - const handleImageLoad = () => { - setLoaded(true); - }; - const handleVideoHover: React.MouseEventHandler = ({ currentTarget: video }) => { video.playbackRate = 3.0; video.play(); @@ -166,7 +160,7 @@ const Item: React.FC = ({ return (
- + {attachmentIcon} {filename} @@ -258,10 +252,8 @@ const Item: React.FC = ({
)} {visible && thumbnail} @@ -304,15 +296,6 @@ const MediaGallery: React.FC = (props) => { const node = useRef(null); - // const componentDidUpdate = (prevProps) => { - // const { visible } = props; - // if (!is(media, prevProps.media) && visible === undefined) { - // this.setState({ visible: prevProps.displayMedia !== 'hide_all' && !sensitive || prevProps.displayMedia === 'show_all' }); - // } else if (!is(visible, prevProps.visible) && visible !== undefined) { - // setVisible(visible); - // } - // }; - const handleOpen: React.MouseEventHandler = (e) => { e.stopPropagation(); @@ -327,18 +310,6 @@ const MediaGallery: React.FC = (props) => { onOpenMedia(media, index); }; - useEffect(() => { - if (node.current) { - const { offsetWidth } = node.current; - - if (cacheWidth) { - cacheWidth(offsetWidth); - } - - setWidth(offsetWidth); - } - }, [node.current]); - const getSizeDataSingle = (): SizeData => { const w = width || defaultWidth; const aspectRatio = media.getIn([0, 'meta', 'original', 'aspect']) as number | undefined; @@ -590,6 +561,18 @@ const MediaGallery: React.FC = (props) => { warning = ; } + useEffect(() => { + if (node.current) { + const { offsetWidth } = node.current; + + if (cacheWidth) { + cacheWidth(offsetWidth); + } + + setWidth(offsetWidth); + } + }, [node.current]); + return (