code refactoring
This commit is contained in:
@@ -153,7 +153,7 @@ export const serverAddressAndPortState = selector({
|
|||||||
export const serverURL = selector({
|
export const serverURL = selector({
|
||||||
key: 'serverURL',
|
key: 'serverURL',
|
||||||
get: ({ get }) =>
|
get: ({ get }) =>
|
||||||
`${window.location.protocol}//${get(serverAddressState)}:${get(serverPortState)}`
|
`${window.location.protocol}//${get(serverAddressAndPortState)}`
|
||||||
})
|
})
|
||||||
|
|
||||||
export const rpcWebSocketEndpoint = selector({
|
export const rpcWebSocketEndpoint = selector({
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { AlertColor } from '@mui/material'
|
import { AlertColor } from '@mui/material'
|
||||||
import { atom } from 'recoil'
|
import { atom } from 'recoil'
|
||||||
|
|
||||||
type Toast = {
|
export type Toast = {
|
||||||
open: boolean,
|
open: boolean,
|
||||||
message: string
|
message: string
|
||||||
autoClose: boolean
|
autoClose: boolean
|
||||||
|
|||||||
@@ -149,12 +149,10 @@ export default function DownloadDialog({
|
|||||||
|
|
||||||
const handleFilenameTemplateChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleFilenameTemplateChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setFilenameTemplate(e.target.value)
|
setFilenameTemplate(e.target.value)
|
||||||
localStorage.setItem('last-filename-override', e.target.value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleCustomArgsChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleCustomArgsChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setCustomArgs(e.target.value)
|
setCustomArgs(e.target.value)
|
||||||
localStorage.setItem("last-input-args", e.target.value)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseUrlListFile = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
const parseUrlListFile = async (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
@@ -173,9 +171,7 @@ export default function DownloadDialog({
|
|||||||
|
|
||||||
const resetInput = () => {
|
const resetInput = () => {
|
||||||
urlInputRef.current!.value = ''
|
urlInputRef.current!.value = ''
|
||||||
if (customFilenameInputRef.current) {
|
customFilenameInputRef.current!.value = ''
|
||||||
customFilenameInputRef.current!.value = ''
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,20 +1,23 @@
|
|||||||
import { Alert, Snackbar } from "@mui/material"
|
import { Alert, Snackbar } from "@mui/material"
|
||||||
import { useRecoilState } from 'recoil'
|
import { useRecoilState } from 'recoil'
|
||||||
import { toastListState } from '../atoms/toast'
|
import { Toast, toastListState } from '../atoms/toast'
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
|
|
||||||
const Toaster: React.FC = () => {
|
const Toaster: React.FC = () => {
|
||||||
const [toasts, setToasts] = useRecoilState(toastListState)
|
const [toasts, setToasts] = useRecoilState(toastListState)
|
||||||
|
|
||||||
|
const deletePredicate = (t: Toast) => (Date.now() - t.createdAt) < 2000
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (toasts.length > 0) {
|
if (toasts.length > 0) {
|
||||||
|
|
||||||
const closer = setInterval(() => {
|
const closer = setInterval(() => {
|
||||||
setToasts(t => t.map(t => ({ ...t, open: false })))
|
setToasts(t => t.map(t => ({ ...t, open: deletePredicate(t) })))
|
||||||
}, 2000)
|
}, 2000)
|
||||||
|
|
||||||
const cleaner = setInterval(() => {
|
const cleaner = setInterval(() => {
|
||||||
setToasts(t => t.filter((x) => (Date.now() - x.createdAt) < 2000))
|
setToasts(t => t.filter(deletePredicate))
|
||||||
}, 2250)
|
}, 1000)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(closer)
|
clearInterval(closer)
|
||||||
@@ -29,7 +32,7 @@ const Toaster: React.FC = () => {
|
|||||||
<Snackbar
|
<Snackbar
|
||||||
key={index}
|
key={index}
|
||||||
open={toast.open}
|
open={toast.open}
|
||||||
sx={index > 0 ? { marginBottom: index * 6.5 } : {}}
|
sx={index > 0 ? { marginBottom: index * 6.5 } : null}
|
||||||
>
|
>
|
||||||
<Alert variant="filled" severity={toast.severity}>
|
<Alert variant="filled" severity={toast.severity}>
|
||||||
{toast.message}
|
{toast.message}
|
||||||
|
|||||||
Reference in New Issue
Block a user