diff --git a/src/pages/status.jsx b/src/pages/status.jsx index ce0e7a5d..3c4df0ea 100644 --- a/src/pages/status.jsx +++ b/src/pages/status.jsx @@ -110,6 +110,23 @@ function StatusPage(params) { ? mediaStatus?.mediaAttachments : heroStatus?.mediaAttachments; + const handleMediaClose = useCallback(() => { + if ( + !window.matchMedia('(min-width: calc(40em + 350px))').matches && + snapStates.prevLocation + ) { + history.back(); + } else { + if (showMediaOnly) { + location.hash = closeLink; + } else { + searchParams.delete('media'); + searchParams.delete('mediaStatusID'); + setSearchParams(searchParams); + } + } + }, [showMediaOnly, closeLink, snapStates.prevLocation]); + return (
{showMedia ? ( @@ -119,22 +136,7 @@ function StatusPage(params) { statusID={mediaStatusID || id} instance={instance} index={mediaIndex - 1} - onClose={() => { - if ( - !window.matchMedia('(min-width: calc(40em + 350px))').matches && - snapStates.prevLocation - ) { - history.back(); - } else { - if (showMediaOnly) { - location.hash = closeLink; - } else { - searchParams.delete('media'); - searchParams.delete('mediaStatusID'); - setSearchParams(searchParams); - } - } - }} + onClose={handleMediaClose} /> ) : (