mirror of
https://github.com/blakeblackshear/frigate.git
synced 2025-12-06 21:44:13 +03:00
suppress double toasts
This commit is contained in:
parent
b88bf2f08d
commit
7e4f95c10d
@ -334,74 +334,86 @@ export default function Step2ProbeOrSnapshot({
|
|||||||
[generateDynamicStreamUrl],
|
[generateDynamicStreamUrl],
|
||||||
);
|
);
|
||||||
|
|
||||||
const testConnection = useCallback(async () => {
|
const testConnection = useCallback(
|
||||||
const streamUrl = await generateStreamUrl(wizardData);
|
async (showToast = true) => {
|
||||||
|
const streamUrl = await generateStreamUrl(wizardData);
|
||||||
|
|
||||||
if (!streamUrl) {
|
if (!streamUrl) {
|
||||||
toast.error(t("cameraWizard.commonErrors.noUrl"));
|
toast.error(t("cameraWizard.commonErrors.noUrl"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setIsTesting(true);
|
setIsTesting(true);
|
||||||
setTestStatus("");
|
setTestStatus("");
|
||||||
setTestResult(null);
|
setTestResult(null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setTestStatus(t("cameraWizard.step2.testing.probingMetadata"));
|
setTestStatus(t("cameraWizard.step2.testing.probingMetadata"));
|
||||||
const result = await probeUri(streamUrl, true, setTestStatus);
|
const result = await probeUri(streamUrl, true, setTestStatus);
|
||||||
|
|
||||||
if (result && result.success) {
|
if (result && result.success) {
|
||||||
setTestResult(result);
|
setTestResult(result);
|
||||||
const streamId = `stream_${Date.now()}`;
|
const streamId = `stream_${Date.now()}`;
|
||||||
onUpdate({
|
onUpdate({
|
||||||
streams: [
|
streams: [
|
||||||
{
|
{
|
||||||
id: streamId,
|
id: streamId,
|
||||||
url: streamUrl,
|
url: streamUrl,
|
||||||
roles: ["detect"] as StreamRole[],
|
roles: ["detect"] as StreamRole[],
|
||||||
testResult: result,
|
testResult: result,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
toast.success(t("cameraWizard.step2.testSuccess"));
|
|
||||||
} else {
|
if (showToast) {
|
||||||
const errMsg = result?.error || "Unable to probe stream";
|
toast.success(t("cameraWizard.step2.testSuccess"));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
const errMsg = result?.error || "Unable to probe stream";
|
||||||
|
setTestResult({
|
||||||
|
success: false,
|
||||||
|
error: errMsg,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (showToast) {
|
||||||
|
toast.error(
|
||||||
|
t("cameraWizard.commonErrors.testFailed", { error: errMsg }),
|
||||||
|
{
|
||||||
|
duration: 6000,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
const axiosError = error as {
|
||||||
|
response?: { data?: { message?: string; detail?: string } };
|
||||||
|
message?: string;
|
||||||
|
};
|
||||||
|
const errorMessage =
|
||||||
|
axiosError.response?.data?.message ||
|
||||||
|
axiosError.response?.data?.detail ||
|
||||||
|
axiosError.message ||
|
||||||
|
"Connection failed";
|
||||||
setTestResult({
|
setTestResult({
|
||||||
success: false,
|
success: false,
|
||||||
error: errMsg,
|
error: errorMessage,
|
||||||
});
|
});
|
||||||
toast.error(
|
|
||||||
t("cameraWizard.commonErrors.testFailed", { error: errMsg }),
|
if (showToast) {
|
||||||
{
|
toast.error(
|
||||||
duration: 6000,
|
t("cameraWizard.commonErrors.testFailed", { error: errorMessage }),
|
||||||
},
|
{
|
||||||
);
|
duration: 10000,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
setIsTesting(false);
|
||||||
|
setTestStatus("");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
},
|
||||||
const axiosError = error as {
|
[wizardData, generateStreamUrl, t, onUpdate, probeUri],
|
||||||
response?: { data?: { message?: string; detail?: string } };
|
);
|
||||||
message?: string;
|
|
||||||
};
|
|
||||||
const errorMessage =
|
|
||||||
axiosError.response?.data?.message ||
|
|
||||||
axiosError.response?.data?.detail ||
|
|
||||||
axiosError.message ||
|
|
||||||
"Connection failed";
|
|
||||||
setTestResult({
|
|
||||||
success: false,
|
|
||||||
error: errorMessage,
|
|
||||||
});
|
|
||||||
toast.error(
|
|
||||||
t("cameraWizard.commonErrors.testFailed", { error: errorMessage }),
|
|
||||||
{
|
|
||||||
duration: 10000,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} finally {
|
|
||||||
setIsTesting(false);
|
|
||||||
setTestStatus("");
|
|
||||||
}
|
|
||||||
}, [wizardData, generateStreamUrl, t, onUpdate, probeUri]);
|
|
||||||
|
|
||||||
const handleContinue = useCallback(() => {
|
const handleContinue = useCallback(() => {
|
||||||
onNext();
|
onNext();
|
||||||
@ -416,7 +428,8 @@ export default function Step2ProbeOrSnapshot({
|
|||||||
if (probeMode) {
|
if (probeMode) {
|
||||||
probeCamera();
|
probeCamera();
|
||||||
} else {
|
} else {
|
||||||
testConnection();
|
// Auto-run the connection test but suppress toasts to avoid duplicates
|
||||||
|
testConnection(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [hasStarted, probeMode, probeCamera, testConnection]);
|
}, [hasStarted, probeMode, probeCamera, testConnection]);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user