From ff044beb7ac7a0b40473feda80dba2ea3e977287 Mon Sep 17 00:00:00 2001 From: troyeguo <13820674+troyeguo@users.noreply.github.com> Date: Thu, 16 Apr 2026 16:06:09 +0800 Subject: [PATCH] feat: enhance user feedback and error handling in settings components --- src/assets/locales/zh-CN.json | 3 ++- .../readerSettings/dropdownList/component.tsx | 10 ++++++++-- src/components/textToSpeech/component.tsx | 2 +- src/containers/settings/aiSetting/component.tsx | 9 +++++++++ .../settings/backgroundSetting/component.tsx | 10 ++++++---- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/assets/locales/zh-CN.json b/src/assets/locales/zh-CN.json index 10404893..12ac3f29 100644 --- a/src/assets/locales/zh-CN.json +++ b/src/assets/locales/zh-CN.json @@ -12,6 +12,7 @@ "Text alignment": "文字对齐", "Text orientation": "文字方向", "Horizontal": "横排", + "You can add models manually by selecting the custom model": "您可以通过选择自定义模型来手动添加模型", "Vertical": "竖排", "Synchronisation successful": "同步成功", "Permanently Delete": "永久删除", @@ -951,4 +952,4 @@ "Custom AI Dictionary": "自定义 AI 词典", "Custom AI Assistance": "自定义 AI 辅助", "Model assignment": "模型分配" -} \ No newline at end of file +} diff --git a/src/components/readerSettings/dropdownList/component.tsx b/src/components/readerSettings/dropdownList/component.tsx index 4e4eb7aa..564fb448 100644 --- a/src/components/readerSettings/dropdownList/component.tsx +++ b/src/components/readerSettings/dropdownList/component.tsx @@ -4,7 +4,7 @@ import "./dropdownList.css"; import { Trans } from "react-i18next"; import { DropdownListProps, DropdownListState } from "./interface"; import { ConfigService } from "../../../assets/lib/kookit-extra-browser.min"; -import { loadFontData } from "../../../utils/common"; +import { loadFontData, vexComfirmAsync } from "../../../utils/common"; import toast from "react-hot-toast"; declare var window: any; class DropdownList extends React.Component< @@ -83,7 +83,13 @@ class DropdownList extends React.Component< ConfigService.setReaderConfig(option, ""); } if (arr[0] === "Load local fonts") { - loadFontData(); + vexComfirmAsync( + this.props.t( + "Please install local fonts to your machine and then restart the application" + ) + ); + + return; } break; diff --git a/src/components/textToSpeech/component.tsx b/src/components/textToSpeech/component.tsx index b72e1a26..5d82fe1f 100644 --- a/src/components/textToSpeech/component.tsx +++ b/src/components/textToSpeech/component.tsx @@ -1106,7 +1106,7 @@ class TextToSpeech extends React.Component< } ); } - + toast.success(this.props.t("Setup successful")); if (this.state.isAudioOn) { this.handleVoiceSwitch(voiceName, newEngine, previousEngine); } diff --git a/src/containers/settings/aiSetting/component.tsx b/src/containers/settings/aiSetting/component.tsx index 47a95639..1de558fa 100644 --- a/src/containers/settings/aiSetting/component.tsx +++ b/src/containers/settings/aiSetting/component.tsx @@ -132,6 +132,15 @@ class AISetting extends React.Component { } const data = await response.json(); const rawModels = data.data || data.models || data.results || data || []; + if (rawModels.length === 0) { + toast.error(this.props.t("No models found")); + toast.error( + this.props.t( + "You can add models manually by selecting the custom model" + ) + ); + return; + } const models = rawModels.map((m: any) => ({ id: m.id || m.model || m.name, name: m.id || m.display_name || m.name || m.model, diff --git a/src/containers/settings/backgroundSetting/component.tsx b/src/containers/settings/backgroundSetting/component.tsx index 46e3f1aa..222c9cb6 100644 --- a/src/containers/settings/backgroundSetting/component.tsx +++ b/src/containers/settings/backgroundSetting/component.tsx @@ -117,14 +117,14 @@ class BackgroundSetting extends React.Component< handleSetAppBackground = (image: BackgroundImage) => { ConfigService.setReaderConfig("appBackgroundImage", image.id); - this.setState({ appBackgroundId: image.id, previewImage: null }); + this.setState({ appBackgroundId: image.id }); applyAppBackgroundImage(); toast.success(this.props.t("Change successful")); }; handleClearAppBackground = () => { ConfigService.setReaderConfig("appBackgroundImage", ""); - this.setState({ appBackgroundId: "", previewImage: null }); + this.setState({ appBackgroundId: "" }); applyAppBackgroundImage(); toast.success(this.props.t("Change successful")); }; @@ -137,16 +137,18 @@ class BackgroundSetting extends React.Component< if (image.backgroundColor) { ConfigService.setReaderConfig("backgroundColor", image.backgroundColor); } - this.setState({ readerBackgroundId: image.id, previewImage: null }); + this.setState({ readerBackgroundId: image.id }); this.props.handleReaderBackgroundImage?.(image.id); toast.success(this.props.t("Change successful")); }; handleClearReaderBackground = () => { ConfigService.setReaderConfig("readerBackgroundImage", ""); - this.setState({ readerBackgroundId: "", previewImage: null }); + this.setState({ readerBackgroundId: "" }); this.props.handleReaderBackgroundImage?.(""); toast.success(this.props.t("Change successful")); + ConfigService.setReaderConfig("textColor", ""); + ConfigService.setReaderConfig("backgroundColor", ""); }; handleDelete = async (e: React.MouseEvent, image: BackgroundImage) => {