Move wipe to server side. Add UI unsafe buttons (#355)

* move 'remove all' function to server side ('wipe')

* add UnsafeButton to RemoveAll and CloseServer webui
This commit is contained in:
Alexey D. Filimonov
2024-02-15 09:14:58 +03:00
committed by GitHub
parent d1b29bd848
commit 5e71af9751
4 changed files with 55 additions and 19 deletions

View File

@@ -0,0 +1,26 @@
import { Button } from '@material-ui/core';
import { useEffect, useRef, useState } from 'react';
export default function UnsafeButton({ timeout, children, disabled, ...props }) {
const [timeLeft, setTimeLeft] = useState(timeout || 7)
const [buttonDisabled, setButtonDisabled] = useState(disabled || timeLeft > 0)
const handleTimerTick = () => {
const newTimeLeft = timeLeft - 1
setTimeLeft(newTimeLeft)
if (newTimeLeft <= 0) {
setButtonDisabled(disabled)
}
}
const getTimerText = () => !disabled && timeLeft > 0 ? ` (${timeLeft})` : ''
useEffect(() => {
if (disabled || !timeLeft) { return }
const intervalId = setInterval(handleTimerTick, 1000)
return () => clearInterval(intervalId)
}, [timeLeft])
return (
<Button disabled={buttonDisabled} {...props}>
{children} {getTimerText()}
</Button>
)
}