fix(ui): различать ошибки и пустую историю WireGuard

This commit is contained in:
Denozordec committed 2026-09-29 13:42:00 +07:00
1 parent 1d1de12c58
commit d0f5649725
7 files changed
+116 -14

No files matched your search

+16 -10
View File
@@ -46,6 +46,7 @@ import {
exportWireGuard,
importWireGuard,
listWireGuard,
listWireGuardRevisions,
patchWireGuardInterface,
} from "@/shared/api/wireguard"
import type { WgIfaceDto } from "@mmapp/contracts/wireguard"
@@ -211,6 +212,9 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
const [historyOpen, setHistoryOpen] = useState(false)
const [revisions, setRevisions] = useState<ConfigRevisionDto[]>([])
const [historyLoading, setHistoryLoading] = useState(false)
const [historyError, setHistoryError] = useState<string | null>(null)
const historyEpoch = useRef(0)
useEffect(() => () => { historyEpoch.current += 1 }, [])
const restoreLock = useRef(false)
const [historyRestoring, setHistoryRestoring] = useState(false)
const [liveExport, setLiveExport] = useState<{
@@ -272,18 +276,18 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
const loadRevisions = useCallback(async () => {
if (!isLive || !historyServerId) return
const epoch = ++historyEpoch.current
setHistoryLoading(true)
setHistoryError(null)
try {
const res = await requestJson<{ revisions: ConfigRevisionDto[] }>(
backendUrl,
`/api/wireguard/revisions?serverId=${encodeURIComponent(historyServerId)}`,
)
setRevisions(res.revisions)
} catch (err) {
toast.error("Не удалось загрузить историю", { description: String(err) })
setRevisions([])
const revisions = await listWireGuardRevisions(backendUrl, historyServerId)
if (epoch !== historyEpoch.current) return
setRevisions(revisions)
} catch (error) {
if (epoch !== historyEpoch.current) return
setHistoryError(error instanceof Error ? error.message : "Не удалось загрузить историю")
} finally {
setHistoryLoading(false)
if (epoch === historyEpoch.current) setHistoryLoading(false)
}
}, [isLive, historyServerId, backendUrl])
@@ -990,7 +994,9 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf
<ConfigHistorySheet
open={historyOpen}
onOpenChange={setHistoryOpen}
onOpenChange={v => { if (!v) historyEpoch.current += 1; setHistoryOpen(v) }}
loadError={historyError}
onRetry={() => void loadRevisions()}
title="История WireGuard"
itemLabel="интерфейсов"
revisions={revisions}