add refresh btn

This commit is contained in:
2026-03-17 16:50:45 +08:00
parent 9fddc9836e
commit d01d7636c8
5 changed files with 57 additions and 33 deletions

View File

@@ -15,6 +15,7 @@ import {
Monitor, Monitor,
Smartphone, Smartphone,
ArrowLeft, ArrowLeft,
RefreshCw,
} from "lucide-react"; } from "lucide-react";
import { createStyles, useTheme } from "antd-style"; import { createStyles, useTheme } from "antd-style";
import { import {
@@ -101,9 +102,12 @@ const AppDetail: React.FC = () => {
const fileChangeStore = useFileChangeStore(); const fileChangeStore = useFileChangeStore();
const { message } = AntApp.useApp(); const { message } = AntApp.useApp();
const [downloadingKey, setDownloadingKey] = React.useState<string | null>(null); const [downloadingKey, setDownloadingKey] = React.useState<string | null>(
null,
);
const [downloadingAll, setDownloadingAll] = React.useState(false); const [downloadingAll, setDownloadingAll] = React.useState(false);
const [deploying, setDeploying] = React.useState(false); const [deploying, setDeploying] = React.useState(false);
const [refreshing, setRefreshing] = React.useState(false);
// Reset view mode when app changes // Reset view mode when app changes
useEffect(() => { useEffect(() => {
@@ -131,7 +135,9 @@ const AppDetail: React.FC = () => {
fileName: getDisplayName(file, "js", index), fileName: getDisplayName(file, "js", index),
fileType: "js" as const, fileType: "js" as const,
platform: "desktop" 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), fileKey: getFileKey(file),
url: isUrlResource(file) ? file.url : undefined, url: isUrlResource(file) ? file.url : undefined,
})), })),
@@ -140,7 +146,9 @@ const AppDetail: React.FC = () => {
fileName: getDisplayName(file, "css", index), fileName: getDisplayName(file, "css", index),
fileType: "css" as const, fileType: "css" as const,
platform: "desktop" 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), fileKey: getFileKey(file),
url: isUrlResource(file) ? file.url : undefined, url: isUrlResource(file) ? file.url : undefined,
})), })),
@@ -149,7 +157,9 @@ const AppDetail: React.FC = () => {
fileName: getDisplayName(file, "js", index), fileName: getDisplayName(file, "js", index),
fileType: "js" as const, fileType: "js" as const,
platform: "mobile" 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), fileKey: getFileKey(file),
url: isUrlResource(file) ? file.url : undefined, url: isUrlResource(file) ? file.url : undefined,
})), })),
@@ -158,7 +168,9 @@ const AppDetail: React.FC = () => {
fileName: getDisplayName(file, "css", index), fileName: getDisplayName(file, "css", index),
fileType: "css" as const, fileType: "css" as const,
platform: "mobile" 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), fileKey: getFileKey(file),
url: isUrlResource(file) ? file.url : undefined, url: isUrlResource(file) ? file.url : undefined,
})), })),
@@ -168,7 +180,7 @@ const AppDetail: React.FC = () => {
}, [currentApp?.appId]); }, [currentApp?.appId]);
const loadAppDetail = async () => { const loadAppDetail = async () => {
if (!currentDomain || !selectedAppId) return; if (!currentDomain || !selectedAppId) return undefined;
setLoading(true); setLoading(true);
try { try {
@@ -180,23 +192,23 @@ const AppDetail: React.FC = () => {
// Check if we're still on the same app and component is mounted before updating // Check if we're still on the same app and component is mounted before updating
if (result.success) { if (result.success) {
setCurrentApp(result.data); setCurrentApp(result.data);
return result.data;
} }
return undefined;
} catch (error) { } catch (error) {
console.error("Failed to load app detail:", error); console.error("Failed to load app detail:", error);
return undefined;
} finally { } finally {
setLoading(false); setLoading(false);
} }
}; };
const handleFileClick = useCallback( const handleFileClick = useCallback((fileKey: string, name: string) => {
(fileKey: string, name: string) => { const ext = name.split(".").pop()?.toLowerCase();
const ext = name.split(".").pop()?.toLowerCase(); const type = ext === "css" ? "css" : "js";
const type = ext === "css" ? "css" : "js"; setSelectedFile({ type, fileKey, name });
setSelectedFile({ type, fileKey, name }); setViewMode("code");
setViewMode("code"); }, []);
},
[],
);
const handleBackToList = useCallback(() => { const handleBackToList = useCallback(() => {
setViewMode("list"); setViewMode("list");
@@ -244,7 +256,9 @@ const AppDetail: React.FC = () => {
if (saveResult.success) { if (saveResult.success) {
message.success(t("downloadSuccess", { ns: "common" })); message.success(t("downloadSuccess", { ns: "common" }));
} else { } else {
message.error(saveResult.error || t("downloadFailed", { ns: "common" })); message.error(
saveResult.error || t("downloadFailed", { ns: "common" }),
);
} }
} catch { } catch {
message.error(t("downloadFailed", { ns: "common" })); message.error(t("downloadFailed", { ns: "common" }));
@@ -256,7 +270,8 @@ const AppDetail: React.FC = () => {
); );
const handleDownloadAll = useCallback(async () => { const handleDownloadAll = useCallback(async () => {
if (!currentDomain || !selectedAppId || downloadingAll || !currentApp) return; if (!currentDomain || !selectedAppId || downloadingAll || !currentApp)
return;
const appName = currentApp.name || "app"; const appName = currentApp.name || "app";
const sanitizedAppName = appName.replace(/[:*?"<>|]/g, "_"); const sanitizedAppName = appName.replace(/[:*?"<>|]/g, "_");
@@ -280,7 +295,9 @@ const AppDetail: React.FC = () => {
}); });
if (result.success) { if (result.success) {
message.success(t("downloadAllSuccess", { path: result.data?.path, ns: "common" })); message.success(
t("downloadAllSuccess", { path: result.data?.path, ns: "common" }),
);
} else { } else {
message.error(result.error || t("downloadFailed", { ns: "common" })); message.error(result.error || t("downloadFailed", { ns: "common" }));
} }
@@ -323,9 +340,7 @@ const AppDetail: React.FC = () => {
message.error(result.error || t("deployFailed")); message.error(result.error || t("deployFailed"));
} }
} catch (error) { } catch (error) {
message.error( message.error(error instanceof Error ? error.message : t("deployFailed"));
error instanceof Error ? error.message : t("deployFailed"),
);
} finally { } finally {
setDeploying(false); setDeploying(false);
} }
@@ -359,9 +374,10 @@ const AppDetail: React.FC = () => {
); );
} }
const changeCount = currentDomain && selectedAppId const changeCount =
? fileChangeStore.getChangeCount(currentDomain.id, selectedAppId) currentDomain && selectedAppId
: { added: 0, deleted: 0 }; ? fileChangeStore.getChangeCount(currentDomain.id, selectedAppId)
: { added: 0, deleted: 0 };
const hasChanges = changeCount.added > 0 || changeCount.deleted > 0; const hasChanges = changeCount.added > 0 || changeCount.deleted > 0;
return ( return (
@@ -373,6 +389,13 @@ const AppDetail: React.FC = () => {
<Tag>ID: {currentApp.appId}</Tag> <Tag>ID: {currentApp.appId}</Tag>
</div> </div>
<Space> <Space>
<Button
icon={<RefreshCw size={16} />}
loading={refreshing}
onClick={handleRefresh}
>
{t("refresh", { ns: "common" })}
</Button>
<Button icon={<History size={16} />}> <Button icon={<History size={16} />}>
{t("versionHistory", { ns: "common" })} {t("versionHistory", { ns: "common" })}
</Button> </Button>

View File

@@ -7,12 +7,7 @@ import React from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { Upload, List, Space, Tag, message, Popconfirm } from "antd"; import { Upload, List, Space, Tag, message, Popconfirm } from "antd";
import { Button } from "@lobehub/ui"; import { Button } from "@lobehub/ui";
import { import { Inbox, Trash2, File, Code } from "lucide-react";
Inbox,
Trash2,
File,
Code,
} from "lucide-react";
import { createStyles } from "antd-style"; import { createStyles } from "antd-style";
import type { DeployFile } from "@shared/types/ipc"; import type { DeployFile } from "@shared/types/ipc";

View File

@@ -35,5 +35,7 @@
"settings": "Settings", "settings": "Settings",
"downloadSuccess": "Download successful", "downloadSuccess": "Download successful",
"downloadFailed": "Download failed", "downloadFailed": "Download failed",
"downloadAllSuccess": "Downloaded to: {{path}}" "downloadAllSuccess": "Downloaded to: {{path}}",
"refreshSuccess": "Refreshed successfully",
"refreshFailed": "Refresh failed"
} }

View File

@@ -35,5 +35,7 @@
"settings": "設定", "settings": "設定",
"downloadSuccess": "ダウンロード成功", "downloadSuccess": "ダウンロード成功",
"downloadFailed": "ダウンロード失敗", "downloadFailed": "ダウンロード失敗",
"downloadAllSuccess": "ダウンロード先: {{path}}" "downloadAllSuccess": "ダウンロード先: {{path}}",
"refreshSuccess": "更新しました",
"refreshFailed": "更新に失敗しました"
} }

View File

@@ -35,5 +35,7 @@
"settings": "设置", "settings": "设置",
"downloadSuccess": "下载成功", "downloadSuccess": "下载成功",
"downloadFailed": "下载失败", "downloadFailed": "下载失败",
"downloadAllSuccess": "已下载到: {{path}}" "downloadAllSuccess": "已下载到: {{path}}",
"refreshSuccess": "刷新成功",
"refreshFailed": "刷新失败"
} }