diff --git a/src/pages/manage/tasks/Tasks.tsx b/src/pages/manage/tasks/Tasks.tsx index 4dae65265..d17283904 100644 --- a/src/pages/manage/tasks/Tasks.tsx +++ b/src/pages/manage/tasks/Tasks.tsx @@ -17,7 +17,6 @@ import { For, JSX, onCleanup, - Setter, Show, } from "solid-js" import { Paginator } from "~/components" @@ -180,52 +179,22 @@ export const Tasks = (props: TasksProps) => { }), ) } - const doWithSelected = ( - loadingSetter: Setter, - fetchFunc: (task: TaskInfo) => PEmptyResp, - successCallback?: () => void, - ) => { - return async () => { - loadingSetter(true) - const promises = filteredTask() - .filter((task) => task.selected) - .map(fetchFunc) - let success = true - for (const p of promises) { - const resp = await p - if (resp.code !== 200) { - success = false - handleResp(resp) - if (resp.code === 401) return - } - } - loadingSetter(false) - if (success) successCallback?.() - } - } - const [retrySelectedLoading, setRetrySelectedLoading] = createSignal(false) - const retrySelected = doWithSelected( - setRetrySelectedLoading, - (task) => { - return r.post(`/task/${props.type}/retry?tid=${task.id}`) - }, - () => { - notify.info(t("tasks.retry")) - refresh() - }, + const getSelectedId = () => + filteredTask() + .filter((task) => task.selected) + .map((task) => task.id) + const [retrySelectedLoading, retrySelected] = useFetch( + (): PEmptyResp => r.post(`/task/${props.type}/retry_some`, getSelectedId()), ) - const [operateSelectedLoading, setOperateSelectedLoading] = - createSignal(false) - const operateSelected = doWithSelected( - setOperateSelectedLoading, - (task) => { - return r.post(`/task/${props.type}/${operateName}?tid=${task.id}`) - }, - () => { - notify.success(t("global.delete_success")) - refresh() - }, + const [operateSelectedLoading, operateSelected] = useFetch( + (): PEmptyResp => + r.post(`/task/${props.type}/${operateName}_some`, getSelectedId()), ) + const notifyIndividualError = (msg: Record) => { + Object.entries(msg).forEach(([key, value]) => { + notify.error(`${key}: ${value}`) + }) + } const [page, setPage] = createSignal(1) const pageSize = 20 const operateName = props.done === "undone" ? "cancel" : "delete" @@ -300,7 +269,13 @@ export const Tasks = (props: TasksProps) => { @@ -308,7 +283,13 @@ export const Tasks = (props: TasksProps) => {