mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
make prettier happy
This commit is contained in:
@@ -6,6 +6,7 @@ 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 useOnStandaloneAppOutsideClick from 'utils/useOnStandaloneAppOutsideClick'
|
import useOnStandaloneAppOutsideClick from 'utils/useOnStandaloneAppOutsideClick'
|
||||||
|
|
||||||
import UnsafeButton from './UnsafeButton'
|
import UnsafeButton from './UnsafeButton'
|
||||||
|
|
||||||
export default function CloseServer({ isOffline, isLoading }) {
|
export default function CloseServer({ isOffline, isLoading }) {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import DeleteIcon from '@material-ui/icons/Delete'
|
|||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
import { torrentsHost } from 'utils/Hosts'
|
import { torrentsHost } from 'utils/Hosts'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
|
|
||||||
import UnsafeButton from './UnsafeButton'
|
import UnsafeButton from './UnsafeButton'
|
||||||
|
|
||||||
const fnRemoveAll = () => {
|
const fnRemoveAll = () => {
|
||||||
|
|||||||
@@ -1,26 +1,29 @@
|
|||||||
import { Button } from '@material-ui/core';
|
import { Button } from '@material-ui/core'
|
||||||
import { useEffect, useRef, useState } from 'react';
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
export default function UnsafeButton({ timeout, children, disabled, ...props }) {
|
export default function UnsafeButton({ timeout, children, disabled, ...props }) {
|
||||||
const [timeLeft, setTimeLeft] = useState(timeout || 7)
|
const [timeLeft, setTimeLeft] = useState(timeout || 7)
|
||||||
const [buttonDisabled, setButtonDisabled] = useState(disabled || timeLeft > 0)
|
const [buttonDisabled, setButtonDisabled] = useState(disabled || timeLeft > 0)
|
||||||
const handleTimerTick = () => {
|
const handleTimerTick = () => {
|
||||||
const newTimeLeft = timeLeft - 1
|
const newTimeLeft = timeLeft - 1
|
||||||
setTimeLeft(newTimeLeft)
|
setTimeLeft(newTimeLeft)
|
||||||
if (newTimeLeft <= 0) {
|
if (newTimeLeft <= 0) {
|
||||||
setButtonDisabled(disabled)
|
setButtonDisabled(disabled)
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const getTimerText = () => !disabled && timeLeft > 0 ? ` (${timeLeft})` : ''
|
}
|
||||||
useEffect(() => {
|
const getTimerText = () => (!disabled && timeLeft > 0 ? ` (${timeLeft})` : '')
|
||||||
if (disabled || !timeLeft) { return }
|
useEffect(() => {
|
||||||
const intervalId = setInterval(handleTimerTick, 1000)
|
if (disabled || !timeLeft) {
|
||||||
return () => clearInterval(intervalId)
|
return
|
||||||
}, [timeLeft])
|
}
|
||||||
|
const intervalId = setInterval(handleTimerTick, 1000)
|
||||||
|
return () => clearInterval(intervalId)
|
||||||
|
// eslint-disable-next-line
|
||||||
|
}, [timeLeft])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button disabled={buttonDisabled} {...props}>
|
<Button disabled={buttonDisabled} {...props}>
|
||||||
{children} {getTimerText()}
|
{children} {getTimerText()}
|
||||||
</Button>
|
</Button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user