修复bug
This commit is contained in:
@@ -14,7 +14,24 @@ import { useLocation } from "wouter";
|
||||
import { ChevronLeft, Check } from "lucide-react";
|
||||
import { useDevice } from "@/contexts/DeviceContext";
|
||||
import { cn } from "@/lib/utils";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import localeZh from "@/locales/data-zh.json";
|
||||
import localeZhHK from "@/locales/data-zh-HK.json";
|
||||
import localeEn from "@/locales/data-en.json";
|
||||
|
||||
type DacVolumeDirectConfirmLocale = NonNullable<
|
||||
NonNullable<(typeof localeZh)["dac"]>["dacVolumeDirectConfirm"]
|
||||
>;
|
||||
|
||||
const iisModeImageUrl = (index: number) =>
|
||||
`${import.meta.env.BASE_URL}IIS/iis_app${index + 1}.png`;
|
||||
@@ -33,6 +50,7 @@ const KEY_TO_SETTING: Record<string, string> = {
|
||||
xlr: "xlr",
|
||||
dacGain: "dacGain",
|
||||
dacImpedance: "dacImpedance",
|
||||
dacVolumeDirect: "dacVolumeDirect",
|
||||
vu: "vu",
|
||||
input: "input",
|
||||
output: "output",
|
||||
@@ -69,7 +87,7 @@ export function navigateToSelect(title: string, options: string[], selected: num
|
||||
|
||||
export default function SelectPage() {
|
||||
const [location, setLocation] = useLocation();
|
||||
const { updateSetting } = useDevice();
|
||||
const { updateSetting, deviceState } = useDevice();
|
||||
const [state, setState] = useState<{
|
||||
title: string;
|
||||
options: string[];
|
||||
@@ -78,6 +96,13 @@ export default function SelectPage() {
|
||||
key: string;
|
||||
} | null>(() => selectPageState);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [volumeDirectConfirmIdx, setVolumeDirectConfirmIdx] = useState<1 | 2 | null>(null);
|
||||
|
||||
const volumeDirectConfirmText = useMemo((): DacVolumeDirectConfirmLocale => {
|
||||
const lang = deviceState?.language;
|
||||
const pack = lang === 0 ? localeEn : lang === 1 ? localeZhHK : localeZh;
|
||||
return (pack.dac?.dacVolumeDirectConfirm ?? localeZh.dac!.dacVolumeDirectConfirm) as DacVolumeDirectConfirmLocale;
|
||||
}, [deviceState?.language]);
|
||||
|
||||
// Re-read global state whenever we enter /select (avoids stale key/options after remount)
|
||||
useEffect(() => {
|
||||
@@ -92,7 +117,7 @@ export default function SelectPage() {
|
||||
|
||||
const { title, options, selected: selectedIdx, back, key } = state;
|
||||
|
||||
const handleSelect = async (idx: number) => {
|
||||
const commitSelect = async (idx: number) => {
|
||||
if (saving) return;
|
||||
selectPageResult = { key, selected: idx };
|
||||
|
||||
@@ -109,6 +134,35 @@ export default function SelectPage() {
|
||||
setLocation(back);
|
||||
};
|
||||
|
||||
const handleSelect = async (idx: number) => {
|
||||
if (
|
||||
key === "dacVolumeDirect" &&
|
||||
idx !== selectedIdx &&
|
||||
(idx === 1 || idx === 2)
|
||||
) {
|
||||
setVolumeDirectConfirmIdx(idx);
|
||||
return;
|
||||
}
|
||||
await commitSelect(idx);
|
||||
};
|
||||
|
||||
const volumeDirectDialogCopy =
|
||||
volumeDirectConfirmIdx === 1
|
||||
? {
|
||||
title: volumeDirectConfirmText.title0db ?? "开启 0dB 直通模式?",
|
||||
desc:
|
||||
volumeDirectConfirmText.desc0db ??
|
||||
"直通模式会将音量调到最大,并且不可调节。",
|
||||
}
|
||||
: volumeDirectConfirmIdx === 2
|
||||
? {
|
||||
title: volumeDirectConfirmText.title12db ?? "开启 -12dB 直通模式?",
|
||||
desc:
|
||||
volumeDirectConfirmText.desc12db ??
|
||||
"直通模式会将音量调到 -12dB,并且不可调节。",
|
||||
}
|
||||
: null;
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-black">
|
||||
{/* ── Header ── */}
|
||||
@@ -185,6 +239,37 @@ export default function SelectPage() {
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<AlertDialog
|
||||
open={volumeDirectConfirmIdx !== null}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) setVolumeDirectConfirmIdx(null);
|
||||
}}
|
||||
>
|
||||
<AlertDialogContent className="top-[42%] border-white/10 bg-zinc-900 text-white sm:max-w-md">
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle className="text-white">{volumeDirectDialogCopy?.title}</AlertDialogTitle>
|
||||
<AlertDialogDescription className="text-white/60">
|
||||
{volumeDirectDialogCopy?.desc}
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel className="border-white/20 bg-transparent text-white hover:bg-white/10">
|
||||
{volumeDirectConfirmText.cancel ?? "取消"}
|
||||
</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
className="bg-[#00FFF6] text-black hover:bg-[#00FFF6]/90 focus-visible:ring-[#00FFF6]"
|
||||
onClick={() => {
|
||||
const idx = volumeDirectConfirmIdx;
|
||||
setVolumeDirectConfirmIdx(null);
|
||||
if (idx !== null) void commitSelect(idx);
|
||||
}}
|
||||
>
|
||||
{volumeDirectConfirmText.confirm ?? "确认"}
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user