diff --git a/src/pages/options/routes/ScriptList/components.tsx b/src/pages/options/routes/ScriptList/components.tsx index 10884e987..476630fc8 100644 --- a/src/pages/options/routes/ScriptList/components.tsx +++ b/src/pages/options/routes/ScriptList/components.tsx @@ -7,7 +7,7 @@ import { TbWorldWww } from "react-icons/tb"; import { semTime } from "@App/pkg/utils/dayjs"; import { useTranslation } from "react-i18next"; import { ListHomeRender } from "../utils"; -import { IconEdit, IconLink, IconUserAdd } from "@arco-design/web-react/icon"; +import { IconEdit, IconLink, IconSync, IconUserAdd } from "@arco-design/web-react/icon"; import type { SearchType } from "@App/app/service/service_worker/types"; import type { TFunction } from "i18next"; import type { SearchFilterKeyEntry, SearchFilterRequest } from "./SearchFilter"; @@ -133,52 +133,61 @@ HomeCell.displayName = "HomeCell"; export const UpdateTimeCell = React.memo(({ className, script }: { className?: string; script: ScriptLoading }) => { const { t } = useTranslation(); - const { handleClick } = { - handleClick: () => { - if (!script.checkUpdateUrl) { - Message.warning(t("update_not_supported")!); - return; - } - Message.info({ - id: "checkupdate", - content: t("checking_for_updates"), - }); - scriptClient - .requestCheckUpdate(script.uuid) - .then((res) => { - if (res) { - Message.warning({ - id: "checkupdate", - content: t("new_version_available"), - }); - } else { - Message.success({ - id: "checkupdate", - content: t("latest_version"), - }); - } - }) - .catch((e) => { - Message.error({ + const [checking, setChecking] = React.useState(false); + const handleClick = () => { + if (checking) return; + if (!script.checkUpdateUrl) { + Message.warning(t("update_not_supported")!); + return; + } + Message.info({ + id: "checkupdate", + content: t("checking_for_updates"), + }); + setChecking(true); + scriptClient + .requestCheckUpdate(script.uuid) + .then((res) => { + if (res) { + Message.warning({ id: "checkupdate", - content: `${t("update_check_failed")}: ${e.message}`, + content: t("new_version_available"), }); + } else { + Message.success({ + id: "checkupdate", + content: t("latest_version"), + }); + } + }) + .catch((e) => { + Message.error({ + id: "checkupdate", + content: `${t("update_check_failed")}: ${e.message}`, }); - }, + }) + .finally(() => { + setChecking(false); + }); }; return ( - - - {script.updatetime && semTime(new Date(script.updatetime))} - - + + + + {script.updatetime && semTime(new Date(script.updatetime))} + + + {script.checkUpdateUrl && ( + + + + )} + ); }); UpdateTimeCell.displayName = "UpdateTimeCell";