code refactoring

This commit is contained in:
2023-10-24 14:45:55 +02:00
parent ba23485b33
commit 38d8bb8e40
4 changed files with 11 additions and 12 deletions

View File

@@ -153,7 +153,7 @@ export const serverAddressAndPortState = selector({
export const serverURL = selector({
key: 'serverURL',
get: ({ get }) =>
`${window.location.protocol}//${get(serverAddressState)}:${get(serverPortState)}`
`${window.location.protocol}//${get(serverAddressAndPortState)}`
})
export const rpcWebSocketEndpoint = selector({

View File

@@ -1,7 +1,7 @@
import { AlertColor } from '@mui/material'
import { atom } from 'recoil'
type Toast = {
export type Toast = {
open: boolean,
message: string
autoClose: boolean

View File

@@ -149,12 +149,10 @@ export default function DownloadDialog({
const handleFilenameTemplateChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setFilenameTemplate(e.target.value)
localStorage.setItem('last-filename-override', e.target.value)
}
const handleCustomArgsChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setCustomArgs(e.target.value)
localStorage.setItem("last-input-args", e.target.value)
}
const parseUrlListFile = async (e: React.ChangeEvent<HTMLInputElement>) => {
@@ -173,9 +171,7 @@ export default function DownloadDialog({
const resetInput = () => {
urlInputRef.current!.value = ''
if (customFilenameInputRef.current) {
customFilenameInputRef.current!.value = ''
}
customFilenameInputRef.current!.value = ''
}
return (

View File

@@ -1,20 +1,23 @@
import { Alert, Snackbar } from "@mui/material"
import { useRecoilState } from 'recoil'
import { toastListState } from '../atoms/toast'
import { Toast, toastListState } from '../atoms/toast'
import { useEffect } from 'react'
const Toaster: React.FC = () => {
const [toasts, setToasts] = useRecoilState(toastListState)
const deletePredicate = (t: Toast) => (Date.now() - t.createdAt) < 2000
useEffect(() => {
if (toasts.length > 0) {
const closer = setInterval(() => {
setToasts(t => t.map(t => ({ ...t, open: false })))
setToasts(t => t.map(t => ({ ...t, open: deletePredicate(t) })))
}, 2000)
const cleaner = setInterval(() => {
setToasts(t => t.filter((x) => (Date.now() - x.createdAt) < 2000))
}, 2250)
setToasts(t => t.filter(deletePredicate))
}, 1000)
return () => {
clearInterval(closer)
@@ -29,7 +32,7 @@ const Toaster: React.FC = () => {
<Snackbar
key={index}
open={toast.open}
sx={index > 0 ? { marginBottom: index * 6.5 } : {}}
sx={index > 0 ? { marginBottom: index * 6.5 } : null}
>
<Alert variant="filled" severity={toast.severity}>
{toast.message}