From ec6ec529651e39a4b59137c902865bca2ebdeed8 Mon Sep 17 00:00:00 2001 From: Denozordec Date: Tue, 29 Sep 2026 08:22:58 +0700 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=D0=B7=D0=B0=D1=89=D0=B8=D1=82=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D1=84=D0=BE=D1=80=D0=BC=D1=83=20=D0=B8=D0=BC?= =?UTF-8?q?=D0=BF=D0=BE=D1=80=D1=82=D0=B0=20WireGuard=20=D0=B2=D0=BE=20?= =?UTF-8?q?=D0=B2=D1=80=D0=B5=D0=BC=D1=8F=20=D0=B7=D0=B0=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/(main)/wireguard/page.tsx | 13 +++++-- components/wireguard/wg-import-sheet.tsx | 28 ++++++++++----- docs/ux-ui-plan.md | 4 +-- docs/ux-ui-progress.md | 10 +++++- docs/ux-ui-stage-9.md | 6 +++- tests/e2e/wireguard-links.spec.ts | 44 ++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 16 deletions(-) diff --git a/app/(main)/wireguard/page.tsx b/app/(main)/wireguard/page.tsx index df497d5e..60e8a3ec 100644 --- a/app/(main)/wireguard/page.tsx +++ b/app/(main)/wireguard/page.tsx @@ -192,6 +192,8 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf const [search, setSearch] = useState("") const [createOpen, setCreateOpen] = useState(false) const [importOpen, setImportOpen] = useState(false) + const importLock = useRef(false) + const [importError, setImportError] = useState(null) const [exportIface, setExportIface] = useState(null) const [exportInitialTab, setExportInitialTab] = useState<"rsc" | "conf" | "peer">("rsc") const [exportPeerId, setExportPeerId] = useState(null) @@ -443,10 +445,13 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf format: "auto" | "rsc" | "conf" dryRun: boolean }) { + if (importLock.current) return if (!isLive) { toast.info("Импорт на роутер доступен только в live-режиме") return } + importLock.current = true + setImportError(null) setBusy(true) try { const res = await importWireGuard(backendUrl, { @@ -467,8 +472,9 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf setImportOpen(false) await loadLive() } catch (e) { - toast.error(e instanceof Error ? e.message : "Ошибка импорта") + setImportError(e instanceof Error ? e.message : "Ошибка импорта") } finally { + importLock.current = false setBusy(false) } } @@ -647,7 +653,7 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf )} - @@ -874,7 +880,8 @@ function WireGuardPageContent({ selectedServerId, selectedInterfaceId, allInterf /> { if (!importLock.current) setImportOpen(v) }} + error={importError} servers={serverOptions} defaultServerId={sheetServerId} busy={busy} diff --git a/components/wireguard/wg-import-sheet.tsx b/components/wireguard/wg-import-sheet.tsx index 5601f74a..ccbf1692 100644 --- a/components/wireguard/wg-import-sheet.tsx +++ b/components/wireguard/wg-import-sheet.tsx @@ -1,6 +1,6 @@ "use client" -import { useEffect, useMemo, useState } from "react" +import { useMemo, useState } from "react" import { FormField, SectionTitle } from "@/components/form-kit" import { Button } from "@/components/ui/button" import { @@ -17,6 +17,7 @@ function WgImportSheet({ onOpenChange, servers, busy, + error, defaultServerId, onImport, }: { @@ -24,6 +25,7 @@ function WgImportSheet({ onOpenChange: (v: boolean) => void servers: ServerOption[] busy?: boolean + error?: string | null defaultServerId?: string onImport: (args: { serverId: string @@ -43,10 +45,11 @@ function WgImportSheet({ [content], ) - useEffect(() => { - if (!open) return - setServerId(defaultServerId ?? "") - }, [open, defaultServerId]) + const [context, setContext] = useState({ open: false, defaultServerId }) + if (context.open !== open || context.defaultServerId !== defaultServerId) { + setContext({ open, defaultServerId }) + if (open) setServerId(defaultServerId ?? "") + } function runPreview() { setParseError(null) @@ -73,6 +76,7 @@ function WgImportSheet({ { + if (busy) return if (v) { setServerId(defaultServerId ?? "") } else { @@ -84,7 +88,7 @@ function WgImportSheet({ onOpenChange(v) }} > - + Импорт конфига WireGuard @@ -92,10 +96,11 @@ function WgImportSheet({ -
+
setFormat(e.target.value as "auto" | "rsc" | "conf")} > @@ -135,6 +141,7 @@ function WgImportSheet({