[bugfix] Config Page: AdvancedSettings: Add save button to Entry components.
Add error handlings.
This commit is contained in:
@@ -14,6 +14,10 @@ import {
|
||||
useSpeakerMaxWords,
|
||||
|
||||
useDeepLAuthKey,
|
||||
|
||||
|
||||
useOscIpAddress,
|
||||
useOscPort,
|
||||
} from "@logics_configs";
|
||||
import { ui_configs } from "../ui_configs";
|
||||
|
||||
@@ -29,9 +33,13 @@ export const _useBackendErrorHandling = () => {
|
||||
const { updateSpeakerPhraseTimeout } = useSpeakerPhraseTimeout();
|
||||
const { updateSpeakerMaxWords } = useSpeakerMaxWords();
|
||||
|
||||
const { updateDeepLAuthKey } = useDeepLAuthKey();
|
||||
const { updateDeepLAuthKey, saveErrorDeepLAuthKey } = useDeepLAuthKey();
|
||||
|
||||
const errorHandling_Backend = ({message, data, endpoint}) => {
|
||||
|
||||
const { saveErrorOscIpAddress } = useOscIpAddress();
|
||||
const { saveErrorOscPort } = useOscPort();
|
||||
|
||||
const errorHandling_Backend = ({message, data, endpoint, _result}) => {
|
||||
switch (message) {
|
||||
case "No mic device detected":
|
||||
showNotification_Error(t("common_error.no_device_mic"));
|
||||
@@ -111,8 +119,12 @@ export const _useBackendErrorHandling = () => {
|
||||
break;
|
||||
|
||||
default:
|
||||
if (endpoint === "/set/data/deepl_auth_key") updateDeepLAuthKey(data);
|
||||
showNotification_Error(message);
|
||||
// determine by endpoint, not message.
|
||||
if (endpoint === "/set/data/deepl_auth_key") saveErrorDeepLAuthKey({message, data, endpoint, _result});
|
||||
if (endpoint === "/set/data/osc_ip_address") saveErrorOscIpAddress({message, data, endpoint, _result});
|
||||
if (endpoint === "/set/data/osc_port") saveErrorOscPort({message, data, endpoint, _result});
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { useStore_OscIpAddress } from "@store";
|
||||
import { useStdoutToPython } from "@logics/useStdoutToPython";
|
||||
import { useNotificationStatus } from "@logics_common";
|
||||
|
||||
export const useOscIpAddress = () => {
|
||||
const { showNotification_Error } = useNotificationStatus();
|
||||
const { asyncStdoutToPython } = useStdoutToPython();
|
||||
const { currentOscIpAddress, updateOscIpAddress, pendingOscIpAddress } = useStore_OscIpAddress();
|
||||
|
||||
@@ -15,10 +17,17 @@ export const useOscIpAddress = () => {
|
||||
asyncStdoutToPython("/set/data/osc_ip_address", osc_ip_address);
|
||||
};
|
||||
|
||||
const saveErrorOscIpAddress = ({data, message, _result}) => {
|
||||
updateOscIpAddress(d => d.data);
|
||||
showNotification_Error(_result);
|
||||
};
|
||||
|
||||
return {
|
||||
currentOscIpAddress,
|
||||
getOscIpAddress,
|
||||
updateOscIpAddress,
|
||||
setOscIpAddress,
|
||||
|
||||
saveErrorOscIpAddress,
|
||||
};
|
||||
};
|
||||
@@ -1,7 +1,9 @@
|
||||
import { useStore_OscPort } from "@store";
|
||||
import { useStdoutToPython } from "@logics/useStdoutToPython";
|
||||
import { useNotificationStatus } from "@logics_common";
|
||||
|
||||
export const useOscPort = () => {
|
||||
const { showNotification_Error } = useNotificationStatus();
|
||||
const { asyncStdoutToPython } = useStdoutToPython();
|
||||
const { currentOscPort, updateOscPort, pendingOscPort } = useStore_OscPort();
|
||||
|
||||
@@ -15,10 +17,17 @@ export const useOscPort = () => {
|
||||
asyncStdoutToPython("/set/data/osc_port", osc_port);
|
||||
};
|
||||
|
||||
const saveErrorOscPort = ({data, message, _result}) => {
|
||||
updateOscPort(d => d.data);
|
||||
showNotification_Error(_result);
|
||||
};
|
||||
|
||||
return {
|
||||
currentOscPort,
|
||||
getOscPort,
|
||||
updateOscPort,
|
||||
setOscPort,
|
||||
|
||||
saveErrorOscPort,
|
||||
};
|
||||
};
|
||||
@@ -18,22 +18,30 @@ export const useDeepLAuthKey = () => {
|
||||
pendingDeepLAuthKey();
|
||||
asyncStdoutToPython("/set/data/deepl_auth_key", selected_deepl_auth_key);
|
||||
};
|
||||
const saveSuccessDeepLAuthKey = (saved_deepl_auth_key) => {
|
||||
updateDeepLAuthKey(saved_deepl_auth_key);
|
||||
showNotification_Success(t("config_page.translation.deepl_auth_key.auth_key_success"));
|
||||
};
|
||||
|
||||
const deleteDeepLAuthKey = () => {
|
||||
pendingDeepLAuthKey();
|
||||
asyncStdoutToPython("/delete/data/deepl_auth_key");
|
||||
};
|
||||
|
||||
const savedDeepLAuthKey = (data) => {
|
||||
updateDeepLAuthKey(data);
|
||||
showNotification_Success(t("config_page.translation.deepl_auth_key.auth_key_success"));
|
||||
};
|
||||
|
||||
const saveErrorDeepLAuthKey = ({data, message}) => {
|
||||
updateDeepLAuthKey(data);
|
||||
showNotification_Error(message);
|
||||
};
|
||||
|
||||
return {
|
||||
currentDeepLAuthKey,
|
||||
getDeepLAuthKey,
|
||||
updateDeepLAuthKey,
|
||||
setDeepLAuthKey,
|
||||
saveSuccessDeepLAuthKey,
|
||||
deleteDeepLAuthKey,
|
||||
|
||||
saveErrorDeepLAuthKey,
|
||||
savedDeepLAuthKey,
|
||||
};
|
||||
};
|
||||
@@ -148,7 +148,7 @@ export const useReceiveRoutes = () => {
|
||||
const { updateSpeakerPhraseTimeout } = useSpeakerPhraseTimeout();
|
||||
const { updateSpeakerMaxWords } = useSpeakerMaxWords();
|
||||
|
||||
const { updateDeepLAuthKey, saveSuccessDeepLAuthKey } = useDeepLAuthKey();
|
||||
const { updateDeepLAuthKey, savedDeepLAuthKey } = useDeepLAuthKey();
|
||||
const { updateSelectedCTranslate2WeightType } = useSelectedCTranslate2WeightType();
|
||||
const {
|
||||
updateDownloadedCTranslate2WeightTypeStatus,
|
||||
@@ -352,7 +352,7 @@ export const useReceiveRoutes = () => {
|
||||
|
||||
// Translation
|
||||
"/get/data/deepl_auth_key": updateDeepLAuthKey,
|
||||
"/set/data/deepl_auth_key": saveSuccessDeepLAuthKey,
|
||||
"/set/data/deepl_auth_key": savedDeepLAuthKey,
|
||||
"/delete/data/deepl_auth_key": () => updateDeepLAuthKey(""),
|
||||
|
||||
"/get/data/ctranslate2_weight_type": updateSelectedCTranslate2WeightType,
|
||||
@@ -523,6 +523,9 @@ export const useReceiveRoutes = () => {
|
||||
"/set/data/speaker_record_timeout": errorHandling_Backend,
|
||||
"/set/data/speaker_phrase_timeout": errorHandling_Backend,
|
||||
"/set/data/speaker_max_phrases": errorHandling_Backend,
|
||||
|
||||
"/set/data/osc_ip_address": errorHandling_Backend,
|
||||
"/set/data/osc_port": errorHandling_Backend,
|
||||
};
|
||||
|
||||
|
||||
@@ -555,12 +558,14 @@ export const useReceiveRoutes = () => {
|
||||
break;
|
||||
|
||||
case 400:
|
||||
case 500:
|
||||
const error_route = error_status_routes[parsed_data.endpoint];
|
||||
if (error_route) {
|
||||
error_route({
|
||||
message: parsed_data.result.message,
|
||||
data: parsed_data.result.data,
|
||||
endpoint: parsed_data.endpoint,
|
||||
_result: parsed_data.result,
|
||||
});
|
||||
} else {
|
||||
handleInvalidEndpoint(parsed_data);
|
||||
|
||||
Reference in New Issue
Block a user