Files
OpenList-Frontend/src/pages/home/toolbar/Aria2.tsx
2022-11-29 12:42:07 +08:00

38 lines
1.0 KiB
TypeScript

import { createDisclosure } from "@hope-ui/solid"
import { ModalInput } from "~/components"
import { useFetch, useRouter, useT } from "~/hooks"
import { addAria2, bus, handleRespWithNotifySuccess } from "~/utils"
import { onCleanup } from "solid-js"
export const Aria2 = () => {
const t = useT()
const { isOpen, onOpen, onClose } = createDisclosure()
const [loading, ok] = useFetch(addAria2)
const { pathname } = useRouter()
const handler = (name: string) => {
if (name === "offline_download") {
onOpen()
}
}
bus.on("tool", handler)
onCleanup(() => {
bus.off("tool", handler)
})
return (
<ModalInput
title="home.toolbar.offline_download"
type="text"
opened={isOpen()}
onClose={onClose}
loading={loading()}
tips={t("home.toolbar.offline_download-tips")}
onSubmit={async (urls) => {
const resp = await ok(pathname(), urls.split("\n"))
handleRespWithNotifySuccess(resp, () => {
onClose()
})
}}
/>
)
}