Skip to content

Commit df6a539

Browse files
CodFrmcyfung1031
andauthored
✨ 脚本列表最后更新列添加检查更新图标 (#1304)
* ✨ 脚本列表最后更新列添加检查更新图标 closes #1143 * 由 React重绘 改成 CSS * ♻️ 使用 TailwindCSS 替代 inline style 和 React state 处理视觉效果 * 🔥 删除 linter 自动生成的 CSS 文件,已用 TailwindCSS 替代 * 🐛 防止检查更新时重复点击触发并发请求 --------- Co-authored-by: cyfung1031 <44498510+cyfung1031@users.noreply.github.com>
1 parent c59c603 commit df6a539

1 file changed

Lines changed: 50 additions & 41 deletions

File tree

src/pages/options/routes/ScriptList/components.tsx

Lines changed: 50 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { TbWorldWww } from "react-icons/tb";
77
import { semTime } from "@App/pkg/utils/dayjs";
88
import { useTranslation } from "react-i18next";
99
import { ListHomeRender } from "../utils";
10-
import { IconEdit, IconLink, IconUserAdd } from "@arco-design/web-react/icon";
10+
import { IconEdit, IconLink, IconSync, IconUserAdd } from "@arco-design/web-react/icon";
1111
import type { SearchType } from "@App/app/service/service_worker/types";
1212
import type { TFunction } from "i18next";
1313
import type { SearchFilterKeyEntry, SearchFilterRequest } from "./SearchFilter";
@@ -133,52 +133,61 @@ HomeCell.displayName = "HomeCell";
133133

134134
export const UpdateTimeCell = React.memo(({ className, script }: { className?: string; script: ScriptLoading }) => {
135135
const { t } = useTranslation();
136-
const { handleClick } = {
137-
handleClick: () => {
138-
if (!script.checkUpdateUrl) {
139-
Message.warning(t("update_not_supported")!);
140-
return;
141-
}
142-
Message.info({
143-
id: "checkupdate",
144-
content: t("checking_for_updates"),
145-
});
146-
scriptClient
147-
.requestCheckUpdate(script.uuid)
148-
.then((res) => {
149-
if (res) {
150-
Message.warning({
151-
id: "checkupdate",
152-
content: t("new_version_available"),
153-
});
154-
} else {
155-
Message.success({
156-
id: "checkupdate",
157-
content: t("latest_version"),
158-
});
159-
}
160-
})
161-
.catch((e) => {
162-
Message.error({
136+
const [checking, setChecking] = React.useState(false);
137+
const handleClick = () => {
138+
if (checking) return;
139+
if (!script.checkUpdateUrl) {
140+
Message.warning(t("update_not_supported")!);
141+
return;
142+
}
143+
Message.info({
144+
id: "checkupdate",
145+
content: t("checking_for_updates"),
146+
});
147+
setChecking(true);
148+
scriptClient
149+
.requestCheckUpdate(script.uuid)
150+
.then((res) => {
151+
if (res) {
152+
Message.warning({
163153
id: "checkupdate",
164-
content: `${t("update_check_failed")}: ${e.message}`,
154+
content: t("new_version_available"),
165155
});
156+
} else {
157+
Message.success({
158+
id: "checkupdate",
159+
content: t("latest_version"),
160+
});
161+
}
162+
})
163+
.catch((e) => {
164+
Message.error({
165+
id: "checkupdate",
166+
content: `${t("update_check_failed")}: ${e.message}`,
166167
});
167-
},
168+
})
169+
.finally(() => {
170+
setChecking(false);
171+
});
168172
};
169173

170174
return (
171-
<Tooltip content={t("check_update")} position="tl">
172-
<Typography.Text
173-
className={className}
174-
style={{
175-
cursor: "pointer",
176-
}}
177-
onClick={handleClick}
178-
>
179-
{script.updatetime && semTime(new Date(script.updatetime))}
180-
</Typography.Text>
181-
</Tooltip>
175+
<Space size={4}>
176+
<Tooltip content={t("check_update")} position="tl">
177+
<Typography.Text className={`tw-cursor-pointer ${className ?? ""}`} onClick={handleClick}>
178+
{script.updatetime && semTime(new Date(script.updatetime))}
179+
</Typography.Text>
180+
</Tooltip>
181+
{script.checkUpdateUrl && (
182+
<Tooltip content={t("check_update")} position="tl">
183+
<IconSync
184+
className={`tw-cursor-pointer tw-opacity-45 hover:tw-opacity-100 tw-transition-opacity ${checking ? "arco-icon-loading tw-opacity-100" : ""}`}
185+
spin={checking}
186+
onClick={handleClick}
187+
/>
188+
</Tooltip>
189+
)}
190+
</Space>
182191
);
183192
});
184193
UpdateTimeCell.displayName = "UpdateTimeCell";

0 commit comments

Comments
 (0)