mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-20 14:06:09 +05:00
pwa footer toggles modals
This commit is contained in:
24
web/src/utils/useOnStandaloneAppOutsideClick.jsx
Normal file
24
web/src/utils/useOnStandaloneAppOutsideClick.jsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import { useEffect, useRef } from 'react'
|
||||
import { isStandaloneApp } from 'utils/Utils'
|
||||
|
||||
export default function useOnStandaloneAppOutsideClick(onClickOutside) {
|
||||
const ref = useRef()
|
||||
|
||||
useEffect(() => {
|
||||
if (!isStandaloneApp) return
|
||||
|
||||
const handleClickOutside = event => {
|
||||
if (ref.current && !ref.current.contains(event.target)) {
|
||||
onClickOutside && onClickOutside()
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('click', handleClickOutside, true)
|
||||
|
||||
return () => {
|
||||
document.removeEventListener('click', handleClickOutside, true)
|
||||
}
|
||||
})
|
||||
|
||||
return ref
|
||||
}
|
||||
Reference in New Issue
Block a user