From 605741b9c1aacfb06352b217f21ccc98c158f345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Quentin=20=E2=80=9CStorm1er=E2=80=9D=20Decaunes?= Date: Mon, 16 Mar 2020 09:54:54 +0100 Subject: [PATCH] fix: Display an friendly message instead of loading indefinitely online presets. Translations update consequently, they may not be accurate as I used google translate. --- src/components/PresetOnline.tsx | 11 +++++++++++ src/contexts/PresetsOnline.tsx | 1 + src/locales/ch.json | 5 ++++- src/locales/de.json | 5 ++++- src/locales/en.json | 5 ++++- src/locales/fr.json | 5 ++++- src/locales/tr.json | 5 ++++- src/react-app-env.d.ts | 1 + src/scenes/PresetsScene.tsx | 6 +++++- 9 files changed, 38 insertions(+), 6 deletions(-) diff --git a/src/components/PresetOnline.tsx b/src/components/PresetOnline.tsx index bc725dd..db59157 100644 --- a/src/components/PresetOnline.tsx +++ b/src/components/PresetOnline.tsx @@ -24,6 +24,17 @@ function PresetOnline() { return ; })} + ) : presetsOnlineContext.error && !presetsOnlineContext.loading ? ( + + {getTranslation("PresetOnline.pleaseCheckInternetConnection", "Please check your internet connection.")} +
+ +
) : presetsOnlineContext.loading || !sysInfoContext?.signature ? (
diff --git a/src/contexts/PresetsOnline.tsx b/src/contexts/PresetsOnline.tsx index 0bfd035..fc0dae5 100644 --- a/src/contexts/PresetsOnline.tsx +++ b/src/contexts/PresetsOnline.tsx @@ -1,6 +1,7 @@ import { createContext } from "react"; let context: PresetsOnlineContextType = { + error: false, loading: true, list: [], update() {}, diff --git a/src/locales/ch.json b/src/locales/ch.json index 6c89b70..da9c55d 100644 --- a/src/locales/ch.json +++ b/src/locales/ch.json @@ -99,5 +99,8 @@ "ryzenAdjBottomBar.createPreset": "新增预设", "ryzenAdjBottomBar.reset": "重置", "app.localeSelectorModalTitle": "更改语言", - "appContext.newReleaseAvailable": "有新版本发布,请检查发布标签。" + "appContext.newReleaseAvailable": "有新版本发布,请检查发布标签。", + "PresetOnline.errorLoadingPresets": "无法加载预设。", + "PresetOnline.retryLoadingPresetListBtn": "重试", + "PresetOnline.pleaseCheckInternetConnection": "请检查您的互联网连接。" } diff --git a/src/locales/de.json b/src/locales/de.json index fada2ef..f085229 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -99,5 +99,8 @@ "ryzenAdjBottomBar.createPreset": "Preset erstellen", "ryzenAdjBottomBar.reset": "Zurücksetzen", "app.localeSelectorModalTitle": "Sprache ändern", - "appContext.newReleaseAvailable": "Eine neue Version ist verfügbar. Überprüfen Sie die Registerkarte Version." + "appContext.newReleaseAvailable": "Eine neue Version ist verfügbar. Überprüfen Sie die Registerkarte Version.", + "PresetOnline.errorLoadingPresets": "Presets können nicht geladen werden.", + "PresetOnline.retryLoadingPresetListBtn": "Wiederholen", + "PresetOnline.pleaseCheckInternetConnection": "Bitte überprüfe deine Internetverbindung." } diff --git a/src/locales/en.json b/src/locales/en.json index 44cf2d4..ebc2880 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -99,5 +99,8 @@ "ryzenAdjBottomBar.createPreset": "Create preset", "ryzenAdjBottomBar.reset": "Reset", "app.localeSelectorModalTitle": "Change language", - "appContext.newReleaseAvailable": "A new release is available, please check the release tab." + "appContext.newReleaseAvailable": "A new release is available, please check the release tab.", + "PresetOnline.errorLoadingPresets": "Unable to load presets.", + "PresetOnline.retryLoadingPresetListBtn": "Retry", + "PresetOnline.pleaseCheckInternetConnection": "Please check your internet connection." } diff --git a/src/locales/fr.json b/src/locales/fr.json index a66cf9c..ea5b566 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -99,5 +99,8 @@ "ryzenAdjBottomBar.reset": "Reset", "ryzenAdjBottomBar.createPreset": "Créer preset", "app.localeSelectorModalTitle": "Changer de langage", - "appContext.newReleaseAvailable": "Une nouvelle version est disponible, vérifiez l'onglet releases." + "appContext.newReleaseAvailable": "Une nouvelle version est disponible, vérifiez l'onglet releases.", + "PresetOnline.errorLoadingPresets": "Impossible de charger les presets en ligne.", + "PresetOnline.retryLoadingPresetListBtn": "Réessayer", + "PresetOnline.pleaseCheckInternetConnection": "Veuillez vérifier votre connexion internet." } diff --git a/src/locales/tr.json b/src/locales/tr.json index 7438e39..7376c65 100644 --- a/src/locales/tr.json +++ b/src/locales/tr.json @@ -99,5 +99,8 @@ "ryzenAdjBottomBar.createPreset": "Preset oluştur", "ryzenAdjBottomBar.reset": "Sıfırla", "app.localeSelectorModalTitle": "Dil değiştir", - "appContext.newReleaseAvailable": "Yeni bir sürüm mevcut, lütfen sürüm sekmesini kontrol edin." + "appContext.newReleaseAvailable": "Yeni bir sürüm mevcut, lütfen sürüm sekmesini kontrol edin.", + "PresetOnline.errorLoadingPresets": "Ön ayarlar yüklenemiyor.", + "PresetOnline.retryLoadingPresetListBtn": "Yeniden Dene", + "PresetOnline.pleaseCheckInternetConnection": "Lütfen internet bağlantınızı kontrol edin." } diff --git a/src/react-app-env.d.ts b/src/react-app-env.d.ts index ef558a1..f22a196 100644 --- a/src/react-app-env.d.ts +++ b/src/react-app-env.d.ts @@ -114,6 +114,7 @@ type ApiPreset = { }; type PresetsOnlineContextType = { + error: boolean; loading: boolean; list: Array; update(): void; diff --git a/src/scenes/PresetsScene.tsx b/src/scenes/PresetsScene.tsx index 6e21ecf..6ca2e50 100644 --- a/src/scenes/PresetsScene.tsx +++ b/src/scenes/PresetsScene.tsx @@ -13,6 +13,7 @@ const uikit = window.require("uikit"); class PresetsScene extends React.Component<{}, PresetsOnlineContextType> { _isMounted = false; state: PresetsOnlineContextType = { + error: false, loading: false, list: [], update: this.updatePresetList.bind(this), @@ -72,7 +73,10 @@ class PresetsScene extends React.Component<{}, PresetsOnlineContextType> { fetch(process.env.REACT_APP_SERVER_ENDPOINT + "/presets", requestOption) .then(response => response.json()) .then((data: Array) => { - if (this._isMounted) this.setState({ list: data, loading: false }); + if (this._isMounted) this.setState({ list: data, loading: false, error: false }); + }) + .catch(reason => { + if (this._isMounted) this.setState({ error: true, loading: false }); }); }