pwa footer toggles modals

This commit is contained in:
Daniel Shleifman
2022-06-19 19:14:36 +03:00
parent 12ce3299b8
commit acaf80d94e
8 changed files with 57 additions and 31 deletions

View File

@@ -9,6 +9,7 @@ import { useMediaQuery } from '@material-ui/core'
import { echoHost } from 'utils/Hosts' import { echoHost } from 'utils/Hosts'
import { StyledDialog, StyledMenuButtonWrapper } from 'style/CustomMaterialUiStyles' import { StyledDialog, StyledMenuButtonWrapper } from 'style/CustomMaterialUiStyles'
import { isStandaloneApp } from 'utils/Utils' import { isStandaloneApp } from 'utils/Utils'
import useOnStandaloneAppOutsideClick from 'utils/useOnStandaloneAppOutsideClick'
import LinkComponent from './LinkComponent' import LinkComponent from './LinkComponent'
import { DialogWrapper, HeaderSection, ThanksSection, Section, FooterSection } from './style' import { DialogWrapper, HeaderSection, ThanksSection, Section, FooterSection } from './style'
@@ -22,6 +23,9 @@ export default function AboutDialog() {
axios.get(echoHost()).then(({ data }) => setTorrServerVersion(data)) axios.get(echoHost()).then(({ data }) => setTorrServerVersion(data))
}, []) }, [])
const onClose = () => setOpen(false)
const ref = useOnStandaloneAppOutsideClick(onClose)
return ( return (
<> <>
<StyledMenuButtonWrapper button key='Settings' onClick={() => setOpen(true)}> <StyledMenuButtonWrapper button key='Settings' onClick={() => setOpen(true)}>
@@ -43,11 +47,11 @@ export default function AboutDialog() {
<StyledDialog <StyledDialog
open={open} open={open}
onClose={() => setOpen(false)} onClose={onClose}
aria-labelledby='form-dialog-title' aria-labelledby='form-dialog-title'
fullScreen={fullScreen} fullScreen={fullScreen}
maxWidth='xl' maxWidth='xl'
hideBackdrop={isStandaloneApp} ref={ref}
> >
<DialogWrapper> <DialogWrapper>
<HeaderSection> <HeaderSection>
@@ -83,7 +87,7 @@ export default function AboutDialog() {
</div> </div>
<FooterSection> <FooterSection>
<Button onClick={() => setOpen(false)} color='primary' variant='contained'> <Button onClick={onClose} color='primary' variant='contained'>
{t('Close')} {t('Close')}
</Button> </Button>
</FooterSection> </FooterSection>

View File

@@ -9,10 +9,11 @@ import { useMediaQuery } from '@material-ui/core'
import CircularProgress from '@material-ui/core/CircularProgress' import CircularProgress from '@material-ui/core/CircularProgress'
import usePreviousState from 'utils/usePreviousState' import usePreviousState from 'utils/usePreviousState'
import { useQuery } from 'react-query' import { useQuery } from 'react-query'
import { getTorrents, isStandaloneApp } from 'utils/Utils' import { getTorrents } from 'utils/Utils'
import parseTorrent from 'parse-torrent' import parseTorrent from 'parse-torrent'
import { ButtonWrapper } from 'style/DialogStyles' import { ButtonWrapper } from 'style/DialogStyles'
import { StyledDialog, StyledHeader } from 'style/CustomMaterialUiStyles' import { StyledDialog, StyledHeader } from 'style/CustomMaterialUiStyles'
import useOnStandaloneAppOutsideClick from 'utils/useOnStandaloneAppOutsideClick'
import { checkImageURL, getMoviePosters, checkTorrentSource, parseTorrentTitle } from './helpers' import { checkImageURL, getMoviePosters, checkTorrentSource, parseTorrentTitle } from './helpers'
import { Content } from './style' import { Content } from './style'
@@ -46,6 +47,8 @@ export default function AddDialog({
const [isCustomTitleEnabled, setIsCustomTitleEnabled] = useState(false) const [isCustomTitleEnabled, setIsCustomTitleEnabled] = useState(false)
const [currentSourceHash, setCurrentSourceHash] = useState() const [currentSourceHash, setCurrentSourceHash] = useState()
const ref = useOnStandaloneAppOutsideClick(handleClose)
const { data: torrents } = useQuery('torrents', getTorrents, { retry: 1, refetchInterval: 1000 }) const { data: torrents } = useQuery('torrents', getTorrents, { retry: 1, refetchInterval: 1000 })
useEffect(() => { useEffect(() => {
@@ -223,14 +226,7 @@ export default function AddDialog({
} }
return ( return (
<StyledDialog <StyledDialog open onClose={handleClose} fullScreen={fullScreen} fullWidth maxWidth='md' ref={ref}>
open
onClose={handleClose}
fullScreen={fullScreen}
fullWidth
maxWidth='md'
hideBackdrop={isStandaloneApp}
>
<StyledHeader>{t(isEditMode ? 'EditTorrent' : 'AddNewTorrent')}</StyledHeader> <StyledHeader>{t(isEditMode ? 'EditTorrent' : 'AddNewTorrent')}</StyledHeader>
<Content isEditMode={isEditMode}> <Content isEditMode={isEditMode}>

View File

@@ -1,10 +1,11 @@
import { useState } from 'react' import { useState } from 'react'
import { Button, Dialog, DialogActions, DialogTitle, ListItemIcon, ListItemText } from '@material-ui/core' import { Button, DialogActions, DialogTitle, ListItemIcon, ListItemText } from '@material-ui/core'
import { StyledDialog, StyledMenuButtonWrapper } from 'style/CustomMaterialUiStyles'
import { PowerSettingsNew as PowerSettingsNewIcon } from '@material-ui/icons' import { PowerSettingsNew as PowerSettingsNewIcon } from '@material-ui/icons'
import { shutdownHost } from 'utils/Hosts' import { shutdownHost } from 'utils/Hosts'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { isStandaloneApp } from 'utils/Utils' import { isStandaloneApp } from 'utils/Utils'
import { StyledMenuButtonWrapper } from 'style/CustomMaterialUiStyles' import useOnStandaloneAppOutsideClick from 'utils/useOnStandaloneAppOutsideClick'
export default function CloseServer({ isOffline, isLoading }) { export default function CloseServer({ isOffline, isLoading }) {
const { t } = useTranslation() const { t } = useTranslation()
@@ -12,6 +13,8 @@ export default function CloseServer({ isOffline, isLoading }) {
const closeDialog = () => setOpen(false) const closeDialog = () => setOpen(false)
const openDialog = () => setOpen(true) const openDialog = () => setOpen(true)
const ref = useOnStandaloneAppOutsideClick(closeDialog)
return ( return (
<> <>
<StyledMenuButtonWrapper disabled={isOffline || isLoading} button key={t('CloseServer')} onClick={openDialog}> <StyledMenuButtonWrapper disabled={isOffline || isLoading} button key={t('CloseServer')} onClick={openDialog}>
@@ -31,7 +34,7 @@ export default function CloseServer({ isOffline, isLoading }) {
)} )}
</StyledMenuButtonWrapper> </StyledMenuButtonWrapper>
<Dialog open={open} onClose={closeDialog}> <StyledDialog open={open} onClose={closeDialog} ref={ref}>
<DialogTitle>{t('CloseServer?')}</DialogTitle> <DialogTitle>{t('CloseServer?')}</DialogTitle>
<DialogActions> <DialogActions>
<Button variant='outlined' onClick={closeDialog} color='secondary'> <Button variant='outlined' onClick={closeDialog} color='secondary'>
@@ -50,7 +53,7 @@ export default function CloseServer({ isOffline, isLoading }) {
{t('TurnOff')} {t('TurnOff')}
</Button> </Button>
</DialogActions> </DialogActions>
</Dialog> </StyledDialog>
</> </>
) )
} }

View File

@@ -1,5 +1,4 @@
import ListItem from '@material-ui/core/ListItem' import ListItem from '@material-ui/core/ListItem'
import Dialog from '@material-ui/core/Dialog'
import DialogTitle from '@material-ui/core/DialogTitle' import DialogTitle from '@material-ui/core/DialogTitle'
import DialogContent from '@material-ui/core/DialogContent' import DialogContent from '@material-ui/core/DialogContent'
import DialogActions from '@material-ui/core/DialogActions' import DialogActions from '@material-ui/core/DialogActions'
@@ -7,15 +6,18 @@ import List from '@material-ui/core/List'
import ButtonGroup from '@material-ui/core/ButtonGroup' import ButtonGroup from '@material-ui/core/ButtonGroup'
import Button from '@material-ui/core/Button' import Button from '@material-ui/core/Button'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import { StyledDialog } from 'style/CustomMaterialUiStyles'
import useOnStandaloneAppOutsideClick from 'utils/useOnStandaloneAppOutsideClick'
const donateFrame = const donateFrame =
'<iframe src="https://yoomoney.ru/quickpay/shop-widget?writer=seller&targets=TorrServer Donate&targets-hint=&default-sum=200&button-text=14&payment-type-choice=on&mobile-payment-type-choice=on&comment=on&hint=&successURL=&quickpay=shop&account=410013733697114" width="320" height="320" frameborder="0" allowtransparency="true" scrolling="no"></iframe>' '<iframe src="https://yoomoney.ru/quickpay/shop-widget?writer=seller&targets=TorrServer Donate&targets-hint=&default-sum=200&button-text=14&payment-type-choice=on&mobile-payment-type-choice=on&comment=on&hint=&successURL=&quickpay=shop&account=410013733697114" width="320" height="320" frameborder="0" allowtransparency="true" scrolling="no"></iframe>'
export default function DonateDialog({ onClose }) { export default function DonateDialog({ onClose }) {
const { t } = useTranslation() const { t } = useTranslation()
const ref = useOnStandaloneAppOutsideClick(onClose)
return ( return (
<Dialog open onClose={onClose} aria-labelledby='form-dialog-title' fullWidth maxWidth='xs'> <StyledDialog open onClose={onClose} aria-labelledby='form-dialog-title' fullWidth maxWidth='xs' ref={ref}>
<DialogTitle id='form-dialog-title'>{t('Donate')}</DialogTitle> <DialogTitle id='form-dialog-title'>{t('Donate')}</DialogTitle>
<DialogContent> <DialogContent>
<List> <List>
@@ -38,6 +40,6 @@ export default function DonateDialog({ onClose }) {
Ok Ok
</Button> </Button>
</DialogActions> </DialogActions>
</Dialog> </StyledDialog>
) )
} }

View File

@@ -11,7 +11,7 @@ import Tab from '@material-ui/core/Tab'
import SwipeableViews from 'react-swipeable-views' import SwipeableViews from 'react-swipeable-views'
import CircularProgress from '@material-ui/core/CircularProgress' import CircularProgress from '@material-ui/core/CircularProgress'
import { StyledDialog } from 'style/CustomMaterialUiStyles' import { StyledDialog } from 'style/CustomMaterialUiStyles'
import { isStandaloneApp } from 'utils/Utils' import useOnStandaloneAppOutsideClick from 'utils/useOnStandaloneAppOutsideClick'
import { SettingsHeader, FooterSection, Content } from './style' import { SettingsHeader, FooterSection, Content } from './style'
import defaultSettings from './defaultSettings' import defaultSettings from './defaultSettings'
@@ -37,6 +37,8 @@ export default function SettingsDialog({ handleClose }) {
}) })
}, []) }, [])
const ref = useOnStandaloneAppOutsideClick(handleClose)
const handleSave = () => { const handleSave = () => {
handleClose() handleClose()
const sets = JSON.parse(JSON.stringify(settings)) const sets = JSON.parse(JSON.stringify(settings))
@@ -83,14 +85,7 @@ export default function SettingsDialog({ handleClose }) {
const handleChangeIndex = index => setSelectedTab(index) const handleChangeIndex = index => setSelectedTab(index)
return ( return (
<StyledDialog <StyledDialog open onClose={handleClose} fullScreen={fullScreen} fullWidth maxWidth='md' ref={ref}>
open
onClose={handleClose}
fullScreen={fullScreen}
fullWidth
maxWidth='md'
hideBackdrop={isStandaloneApp}
>
<SettingsHeader> <SettingsHeader>
<div>{t('SettingsDialog.Settings')}</div> <div>{t('SettingsDialog.Settings')}</div>
<FormControlLabel <FormControlLabel

View File

@@ -5,7 +5,7 @@ import {
Close as CloseIcon, Close as CloseIcon,
Delete as DeleteIcon, Delete as DeleteIcon,
} from '@material-ui/icons' } from '@material-ui/icons'
import { getPeerString, humanizeSize, humanizeSpeed, isStandaloneApp, removeRedundantCharacters } from 'utils/Utils' import { getPeerString, humanizeSize, humanizeSpeed, removeRedundantCharacters } from 'utils/Utils'
import { playlistTorrHost, torrentsHost } from 'utils/Hosts' import { playlistTorrHost, torrentsHost } from 'utils/Hosts'
import { NoImageIcon } from 'icons' import { NoImageIcon } from 'icons'
import DialogTorrentDetailsContent from 'components/DialogTorrentDetailsContent' import DialogTorrentDetailsContent from 'components/DialogTorrentDetailsContent'
@@ -129,7 +129,6 @@ const Torrent = ({ torrent }) => {
fullWidth fullWidth
maxWidth='xl' maxWidth='xl'
TransitionComponent={Transition} TransitionComponent={Transition}
hideBackdrop={isStandaloneApp}
> >
<DialogTorrentDetailsContent closeDialog={closeDetailedInfo} torrent={torrent} /> <DialogTorrentDetailsContent closeDialog={closeDetailedInfo} torrent={torrent} />
</StyledDialog> </StyledDialog>

View File

@@ -3,6 +3,7 @@ import Dialog from '@material-ui/core/Dialog'
import { pwaFooterHeight } from 'components/App/PWAFooter/style' import { pwaFooterHeight } from 'components/App/PWAFooter/style'
import styled from 'styled-components' import styled from 'styled-components'
import { Header } from 'style/DialogStyles' import { Header } from 'style/DialogStyles'
import { isStandaloneApp } from 'utils/Utils'
export const StyledMenuButtonWrapper = styled(ListItem).attrs({ button: true })` export const StyledMenuButtonWrapper = styled(ListItem).attrs({ button: true })`
@media screen and (display-mode: standalone) { @media screen and (display-mode: standalone) {
@@ -16,7 +17,9 @@ export const StyledMenuButtonWrapper = styled(ListItem).attrs({ button: true })`
} }
` `
export const StyledDialog = styled(Dialog)` export const StyledDialog = styled(Dialog).attrs({
...(isStandaloneApp && { hideBackdrop: true, transitionDuration: 0 }),
})`
@media screen and (display-mode: standalone) { @media screen and (display-mode: standalone) {
margin-bottom: ${pwaFooterHeight}px; margin-bottom: ${pwaFooterHeight}px;

View 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
}