From 7eb7647484afedf9e995561c73104c3f1c60e76c Mon Sep 17 00:00:00 2001 From: eafonyang Date: Mon, 15 Jun 2026 18:39:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BD=93=E9=AA=8C=EF=BC=8C?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/locales/data-en.json | 8 ++- client/src/locales/data-zh-HK.json | 3 + client/src/locales/data-zh.json | 3 + client/src/pages/EQPage.tsx | 12 +--- .../src/pages/eq/components/ShareDialog.tsx | 58 ++++++++++++------- client/src/pages/eq/shareMessages.ts | 40 +++++++++++++ 6 files changed, 89 insertions(+), 35 deletions(-) create mode 100644 client/src/pages/eq/shareMessages.ts diff --git a/client/src/locales/data-en.json b/client/src/locales/data-en.json index 8ebe519..b0bd685 100644 --- a/client/src/locales/data-en.json +++ b/client/src/locales/data-en.json @@ -365,12 +365,15 @@ "shareCopied": "Code copied", "shareGenerating": "Generating…", "shareCreateFail": "Failed to generate share code", + "shareActiveExists": "You already have an active share code. Please try again later.", + "shareInvalidParams": "Invalid request. Please check and try again.", + "shareSystemError": "System error. Please try again later.", "shareExpireAt": "Expires at", "importTab": "Import EQ", "importCodeHint": "Enter or paste the 5-character share code", "importQuery": "Query", "importQuerying": "Querying…", - "importCodeNotFound": "Share code not found", + "importCodeNotFound": "Share code not found or expired", "importEqName": "EQ Name", "importButton": "Import", "importSaving": "Importing…", @@ -381,8 +384,7 @@ "mySharesEmpty": "No shared EQ yet", "mySharesCode": "Code", "mySharesName": "EQ Name", - "mySharesLoadFail": "Failed to load share list", - "importCodeNotFound": "Share code not found or expired" + "mySharesLoadFail": "Failed to load share list" } }, "dac": { diff --git a/client/src/locales/data-zh-HK.json b/client/src/locales/data-zh-HK.json index 1b5a249..8fe7198 100644 --- a/client/src/locales/data-zh-HK.json +++ b/client/src/locales/data-zh-HK.json @@ -301,6 +301,9 @@ "shareCopied": "已複製分享碼", "shareGenerating": "產生中…", "shareCreateFail": "產生分享碼失敗", + "shareActiveExists": "已有未過期的分享碼,請稍後再試", + "shareInvalidParams": "請求參數無效,請檢查後重試", + "shareSystemError": "系統錯誤,請稍後重試", "shareExpireAt": "有效期至", "importTab": "匯入 EQ", "importCodeHint": "輸入或貼上 5 位分享碼", diff --git a/client/src/locales/data-zh.json b/client/src/locales/data-zh.json index cd1d700..523a7b8 100644 --- a/client/src/locales/data-zh.json +++ b/client/src/locales/data-zh.json @@ -301,6 +301,9 @@ "shareCopied": "已复制分享码", "shareGenerating": "生成中…", "shareCreateFail": "生成分享码失败", + "shareActiveExists": "已有未过期的分享码,请稍后再试", + "shareInvalidParams": "请求参数无效,请检查后重试", + "shareSystemError": "系统错误,请稍后重试", "shareExpireAt": "有效期至", "importTab": "导入 EQ", "importCodeHint": "输入或粘贴 5 位分享码", diff --git a/client/src/pages/EQPage.tsx b/client/src/pages/EQPage.tsx index 1156db8..b2af808 100644 --- a/client/src/pages/EQPage.tsx +++ b/client/src/pages/EQPage.tsx @@ -25,7 +25,6 @@ import { type PeqChangePayload, type PeqState, buildPeqPresetBody, - acceptShareCode, } from "@/lib/luxsinApi"; import { getFilterType, @@ -719,16 +718,6 @@ export default function EQPage() { skipPeqAutoSyncRef.current = true; try { - const mac = deviceState?.mac ?? ""; - if (!isDemoMode && mac) { - const acceptRes = await acceptShareCode(mac, shareCode.trim()); - if (acceptRes.code !== 200) { - toast.error(eqUi.importFail ?? eqUi.importCodeNotFound); - skipPeqAutoSyncRef.current = false; - return; - } - } - await upgradePeqChange(payload); if (api && !isDemoMode) { const latest = await fetchEqSyncPeq(api, "importSharedEq"); @@ -1850,6 +1839,7 @@ export default function EQPage() { eqUi={eqUi} peqCardLabels={peqCardLabels} mac={deviceState?.mac ?? ""} + isDemoMode={isDemoMode} onImportEq={handleImportSharedEq} /> diff --git a/client/src/pages/eq/components/ShareDialog.tsx b/client/src/pages/eq/components/ShareDialog.tsx index 376135c..f96e678 100644 --- a/client/src/pages/eq/components/ShareDialog.tsx +++ b/client/src/pages/eq/components/ShareDialog.tsx @@ -2,8 +2,9 @@ import { useState } from "react"; import { X, Copy, Loader2 } from "lucide-react"; import { cn } from "@/lib/utils"; import { toast } from "sonner"; -import { createShareCode, listShareCodes, queryShareCode } from "@/lib/luxsinApi"; +import { acceptShareCode, createShareCode, listShareCodes, queryShareCode } from "@/lib/luxsinApi"; import type { PeqEqUi } from "../constants"; +import { resolveShareApiMessage } from "../shareMessages"; type PeqItem = { name: string; @@ -39,6 +40,7 @@ export function ShareDialog({ eqUi, peqCardLabels, mac, + isDemoMode, onImportEq, }: { open: boolean; @@ -48,6 +50,7 @@ export function ShareDialog({ eqUi: PeqEqUi; peqCardLabels: PeqCardLabels; mac: string; + isDemoMode: boolean; onImportEq: (data: ImportedEqData, shareCode: string) => void | Promise; }) { const [shareDialogTab, setShareDialogTab] = useState<"share" | "import" | "myShares">("share"); @@ -64,6 +67,26 @@ export function ShareDialog({ const [mySharesList, setMySharesList] = useState }>>([]); const [mySharesLoading, setMySharesLoading] = useState(false); + const handleImportClick = async () => { + if (importSaving || !importedEqData || !queriedShareCode) return; + const nextName = importPresetName.trim(); + if (!nextName) return; + + setImportSaving(true); + try { + if (!isDemoMode && mac) { + const acceptRes = await acceptShareCode(mac, queriedShareCode); + if (acceptRes.code !== 200) { + toast.error(resolveShareApiMessage("accept", acceptRes, eqUi)); + return; + } + } + await onImportEq({ ...importedEqData, name: nextName }, queriedShareCode); + } finally { + setImportSaving(false); + } + }; + if (!open) return null; /* ── clipboard helper ── */ @@ -87,7 +110,9 @@ export function ShareDialog({ return (
{ + if (!importSaving) onClose(); + }} >