From d01d7636c8d86ff9019ec13a8849a24d82645a33 Mon Sep 17 00:00:00 2001 From: xue jiahao Date: Tue, 17 Mar 2026 16:50:45 +0800 Subject: [PATCH] add refresh btn --- .../src/components/AppDetail/AppDetail.tsx | 71 ++++++++++++------- .../components/FileUploader/FileUploader.tsx | 7 +- src/renderer/src/locales/en-US/common.json | 4 +- src/renderer/src/locales/ja-JP/common.json | 4 +- src/renderer/src/locales/zh-CN/common.json | 4 +- 5 files changed, 57 insertions(+), 33 deletions(-) diff --git a/src/renderer/src/components/AppDetail/AppDetail.tsx b/src/renderer/src/components/AppDetail/AppDetail.tsx index 622168e..6561c55 100644 --- a/src/renderer/src/components/AppDetail/AppDetail.tsx +++ b/src/renderer/src/components/AppDetail/AppDetail.tsx @@ -15,6 +15,7 @@ import { Monitor, Smartphone, ArrowLeft, + RefreshCw, } from "lucide-react"; import { createStyles, useTheme } from "antd-style"; import { @@ -101,9 +102,12 @@ const AppDetail: React.FC = () => { const fileChangeStore = useFileChangeStore(); const { message } = AntApp.useApp(); - const [downloadingKey, setDownloadingKey] = React.useState(null); + const [downloadingKey, setDownloadingKey] = React.useState( + null, + ); const [downloadingAll, setDownloadingAll] = React.useState(false); const [deploying, setDeploying] = React.useState(false); + const [refreshing, setRefreshing] = React.useState(false); // Reset view mode when app changes useEffect(() => { @@ -131,7 +135,9 @@ const AppDetail: React.FC = () => { fileName: getDisplayName(file, "js", index), fileType: "js" as const, platform: "desktop" as const, - size: isFileResource(file) ? parseInt(file.file.size ?? "0", 10) || undefined : undefined, + size: isFileResource(file) + ? parseInt(file.file.size ?? "0", 10) || undefined + : undefined, fileKey: getFileKey(file), url: isUrlResource(file) ? file.url : undefined, })), @@ -140,7 +146,9 @@ const AppDetail: React.FC = () => { fileName: getDisplayName(file, "css", index), fileType: "css" as const, platform: "desktop" as const, - size: isFileResource(file) ? parseInt(file.file.size ?? "0", 10) || undefined : undefined, + size: isFileResource(file) + ? parseInt(file.file.size ?? "0", 10) || undefined + : undefined, fileKey: getFileKey(file), url: isUrlResource(file) ? file.url : undefined, })), @@ -149,7 +157,9 @@ const AppDetail: React.FC = () => { fileName: getDisplayName(file, "js", index), fileType: "js" as const, platform: "mobile" as const, - size: isFileResource(file) ? parseInt(file.file.size ?? "0", 10) || undefined : undefined, + size: isFileResource(file) + ? parseInt(file.file.size ?? "0", 10) || undefined + : undefined, fileKey: getFileKey(file), url: isUrlResource(file) ? file.url : undefined, })), @@ -158,7 +168,9 @@ const AppDetail: React.FC = () => { fileName: getDisplayName(file, "css", index), fileType: "css" as const, platform: "mobile" as const, - size: isFileResource(file) ? parseInt(file.file.size ?? "0", 10) || undefined : undefined, + size: isFileResource(file) + ? parseInt(file.file.size ?? "0", 10) || undefined + : undefined, fileKey: getFileKey(file), url: isUrlResource(file) ? file.url : undefined, })), @@ -168,7 +180,7 @@ const AppDetail: React.FC = () => { }, [currentApp?.appId]); const loadAppDetail = async () => { - if (!currentDomain || !selectedAppId) return; + if (!currentDomain || !selectedAppId) return undefined; setLoading(true); try { @@ -180,23 +192,23 @@ const AppDetail: React.FC = () => { // Check if we're still on the same app and component is mounted before updating if (result.success) { setCurrentApp(result.data); + return result.data; } + return undefined; } catch (error) { console.error("Failed to load app detail:", error); + return undefined; } finally { setLoading(false); } }; - const handleFileClick = useCallback( - (fileKey: string, name: string) => { - const ext = name.split(".").pop()?.toLowerCase(); - const type = ext === "css" ? "css" : "js"; - setSelectedFile({ type, fileKey, name }); - setViewMode("code"); - }, - [], - ); + const handleFileClick = useCallback((fileKey: string, name: string) => { + const ext = name.split(".").pop()?.toLowerCase(); + const type = ext === "css" ? "css" : "js"; + setSelectedFile({ type, fileKey, name }); + setViewMode("code"); + }, []); const handleBackToList = useCallback(() => { setViewMode("list"); @@ -244,7 +256,9 @@ const AppDetail: React.FC = () => { if (saveResult.success) { message.success(t("downloadSuccess", { ns: "common" })); } else { - message.error(saveResult.error || t("downloadFailed", { ns: "common" })); + message.error( + saveResult.error || t("downloadFailed", { ns: "common" }), + ); } } catch { message.error(t("downloadFailed", { ns: "common" })); @@ -256,7 +270,8 @@ const AppDetail: React.FC = () => { ); const handleDownloadAll = useCallback(async () => { - if (!currentDomain || !selectedAppId || downloadingAll || !currentApp) return; + if (!currentDomain || !selectedAppId || downloadingAll || !currentApp) + return; const appName = currentApp.name || "app"; const sanitizedAppName = appName.replace(/[:*?"<>|]/g, "_"); @@ -280,7 +295,9 @@ const AppDetail: React.FC = () => { }); if (result.success) { - message.success(t("downloadAllSuccess", { path: result.data?.path, ns: "common" })); + message.success( + t("downloadAllSuccess", { path: result.data?.path, ns: "common" }), + ); } else { message.error(result.error || t("downloadFailed", { ns: "common" })); } @@ -323,9 +340,7 @@ const AppDetail: React.FC = () => { message.error(result.error || t("deployFailed")); } } catch (error) { - message.error( - error instanceof Error ? error.message : t("deployFailed"), - ); + message.error(error instanceof Error ? error.message : t("deployFailed")); } finally { setDeploying(false); } @@ -359,9 +374,10 @@ const AppDetail: React.FC = () => { ); } - const changeCount = currentDomain && selectedAppId - ? fileChangeStore.getChangeCount(currentDomain.id, selectedAppId) - : { added: 0, deleted: 0 }; + const changeCount = + currentDomain && selectedAppId + ? fileChangeStore.getChangeCount(currentDomain.id, selectedAppId) + : { added: 0, deleted: 0 }; const hasChanges = changeCount.added > 0 || changeCount.deleted > 0; return ( @@ -373,6 +389,13 @@ const AppDetail: React.FC = () => { ID: {currentApp.appId} + diff --git a/src/renderer/src/components/FileUploader/FileUploader.tsx b/src/renderer/src/components/FileUploader/FileUploader.tsx index 76e13b2..f4f03a1 100644 --- a/src/renderer/src/components/FileUploader/FileUploader.tsx +++ b/src/renderer/src/components/FileUploader/FileUploader.tsx @@ -7,12 +7,7 @@ import React from "react"; import { useTranslation } from "react-i18next"; import { Upload, List, Space, Tag, message, Popconfirm } from "antd"; import { Button } from "@lobehub/ui"; -import { - Inbox, - Trash2, - File, - Code, -} from "lucide-react"; +import { Inbox, Trash2, File, Code } from "lucide-react"; import { createStyles } from "antd-style"; import type { DeployFile } from "@shared/types/ipc"; diff --git a/src/renderer/src/locales/en-US/common.json b/src/renderer/src/locales/en-US/common.json index ab5af54..32d7500 100644 --- a/src/renderer/src/locales/en-US/common.json +++ b/src/renderer/src/locales/en-US/common.json @@ -35,5 +35,7 @@ "settings": "Settings", "downloadSuccess": "Download successful", "downloadFailed": "Download failed", - "downloadAllSuccess": "Downloaded to: {{path}}" + "downloadAllSuccess": "Downloaded to: {{path}}", + "refreshSuccess": "Refreshed successfully", + "refreshFailed": "Refresh failed" } diff --git a/src/renderer/src/locales/ja-JP/common.json b/src/renderer/src/locales/ja-JP/common.json index a828102..5b3bc79 100644 --- a/src/renderer/src/locales/ja-JP/common.json +++ b/src/renderer/src/locales/ja-JP/common.json @@ -35,5 +35,7 @@ "settings": "設定", "downloadSuccess": "ダウンロード成功", "downloadFailed": "ダウンロード失敗", - "downloadAllSuccess": "ダウンロード先: {{path}}" + "downloadAllSuccess": "ダウンロード先: {{path}}", + "refreshSuccess": "更新しました", + "refreshFailed": "更新に失敗しました" } diff --git a/src/renderer/src/locales/zh-CN/common.json b/src/renderer/src/locales/zh-CN/common.json index add38d0..e51d968 100644 --- a/src/renderer/src/locales/zh-CN/common.json +++ b/src/renderer/src/locales/zh-CN/common.json @@ -35,5 +35,7 @@ "settings": "设置", "downloadSuccess": "下载成功", "downloadFailed": "下载失败", - "downloadAllSuccess": "已下载到: {{path}}" + "downloadAllSuccess": "已下载到: {{path}}", + "refreshSuccess": "刷新成功", + "refreshFailed": "刷新失败" }