This commit is contained in:
刘嘉伟 committed 2026-03-11 16:48:21 +08:00
1 parent 80525f1e4e
commit be760a327e
5 files changed
+58 -4

No files matched your search

+2
View File
@@ -314,6 +314,8 @@
"saveChanges": "Save Changes",
"enabled": "Enabled",
"disabled": "Disabled",
"clickToEnable": "Click to enable",
"clickToDisable": "Click to disable",
"errorInvalidName": "Invalid name (use alphanumeric, - or _)",
"errorInvalidIP": "Invalid IP or hostname",
"errorInvalidPort": "Invalid port (1-65535)",
+2
View File
@@ -314,6 +314,8 @@
"saveChanges": "保存更改",
"enabled": "已启用",
"disabled": "已禁用",
"clickToEnable": "点击启用",
"clickToDisable": "点击停用",
"errorInvalidName": "无效的名称(使用字母数字、- 或 _)",
"errorInvalidIP": "无效的 IP 或主机名",
"errorInvalidPort": "无效的端口(1-65535)",
+34 -3
View File
@@ -19,6 +19,7 @@ interface ProxiesViewProps {
offline: number;
};
onDeleteProxy: (id: string) => Promise<void>;
onToggleStatus: (proxy: Proxy) => Promise<void>;
refreshProxies: () => void;
}
@@ -28,6 +29,7 @@ export function ProxiesView({
refreshing,
stats,
onDeleteProxy,
onToggleStatus,
refreshProxies,
}: ProxiesViewProps) {
const { t } = useTranslation();
@@ -35,6 +37,7 @@ export function ProxiesView({
const [deleteId, setDeleteId] = useState<string | null>(null);
const [mounted, setMounted] = useState(false);
const [copiedId, setCopiedId] = useState<string | null>(null);
const [togglingId, setTogglingId] = useState<string | null>(null);
const handleCopy = (text: string, id: string) => {
navigator.clipboard.writeText(text).then(() => {
@@ -318,9 +321,37 @@ export function ProxiesView({
</Badge>
</Table.Cell>
<Table.Cell>
<Badge color={proxy.status === "enabled" ? "green" : "red"}>
{proxy.status === "enabled" ? t("proxy.enabled") : t("proxy.disabled")}
</Badge>
<button
onClick={async () => {
if (togglingId === proxy.id) return;
setTogglingId(proxy.id);
await onToggleStatus(proxy);
setTogglingId(null);
}}
disabled={togglingId === proxy.id}
style={{
cursor: togglingId === proxy.id ? "not-allowed" : "pointer",
background: "none",
border: "none",
padding: 0,
opacity: togglingId === proxy.id ? 0.6 : 1,
transition: "opacity 0.2s",
}}
title={proxy.status === "enabled" ? t("proxy.clickToDisable") : t("proxy.clickToEnable")}
>
<Badge color={proxy.status === "enabled" ? "green" : "gray"} style={{ cursor: "inherit" }}>
{togglingId === proxy.id ? (
<Icon icon="lucide:loader-2" width="12" height="12" className="animate-spin" />
) : (
<Icon
icon={proxy.status === "enabled" ? "lucide:power" : "lucide:power-off"}
width="12"
height="12"
/>
)}
{proxy.status === "enabled" ? t("proxy.enabled") : t("proxy.disabled")}
</Badge>
</button>
</Table.Cell>
<Table.Cell>
<Flex gap="2">
+2 -1
View File
@@ -2,7 +2,7 @@ import { useProxies } from "./useProxies";
import { ProxiesView } from "./ProxiesPage.view";
export function ProxiesPage() {
const { proxies, loading, refreshing, stats, deleteProxy, refreshProxies } = useProxies();
const { proxies, loading, refreshing, stats, deleteProxy, toggleStatus, refreshProxies } = useProxies();
return (
<ProxiesView
@@ -11,6 +11,7 @@ export function ProxiesPage() {
refreshing={refreshing}
stats={stats}
onDeleteProxy={deleteProxy}
onToggleStatus={toggleStatus}
refreshProxies={refreshProxies}
/>
);
+18
View File
@@ -76,6 +76,23 @@ export function useProxies() {
}
};
const toggleStatus = async (proxy: Proxy) => {
const newStatus = proxy.status === "enabled" ? "disabled" : "enabled";
// Optimistic update
setProxies((prev) =>
prev.map((p) => (p.id === proxy.id ? { ...p, status: newStatus } : p))
);
try {
await pb.collection("fh_proxies").update(proxy.id, { status: newStatus });
} catch (err) {
// Rollback on failure
setProxies((prev) =>
prev.map((p) => (p.id === proxy.id ? { ...p, status: proxy.status } : p))
);
toast.error(err instanceof Error ? err.message : "Failed to update proxy status");
}
};
const stats = {
total: proxies.length,
online: proxies.filter((p) => p.bootStatus === "online").length,
@@ -90,6 +107,7 @@ export function useProxies() {
refreshing,
isEmpty,
deleteProxy,
toggleStatus,
page,
setPage,
totalPages,