From b217fcf9c00e5dd40a94545eabf88430c7ab8a7e Mon Sep 17 00:00:00 2001 From: MathieuG-P Date: Mon, 26 Dec 2022 14:17:27 +0100 Subject: [PATCH] better handle deep link error --- .../pages/settings-page.component.tsx | 31 ++++++++----------- 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/renderer/pages/settings-page.component.tsx b/src/renderer/pages/settings-page.component.tsx index 111a9602..141c8495 100644 --- a/src/renderer/pages/settings-page.component.tsx +++ b/src/renderer/pages/settings-page.component.tsx @@ -162,38 +162,33 @@ export function SettingsPage() { notificationService.notifySuccess({title, desc, duration: 3000}); } - const showDeepLinkWarning = (isDesactivation: boolean) => { - const desc = isDesactivation ? "Un problème est survenu lors de la désactivation des OneClicks, veuillez réessayez" : "Un problème est survenu lors de l'activation des OneClicks, veuillez réessayez"; - notificationService.notifyWarning({title: "Attention !", desc, duration: 3000}); - } - const toogleMapDeepLinks = () => { const isDesactivation = mapDeepLinksEnabled; - mapsManager.toogleDeepLinks().catch(() => { + mapsManager.toogleDeepLinks().then(res => { + if(res){ return showDeepLinkSuccess(isDesactivation); } + showDeepLinkError(isDesactivation); + }).catch(() => { showDeepLinkError(isDesactivation); - }).then(res => { - if(!res){ return showDeepLinkWarning(isDesactivation); } - showDeepLinkSuccess(isDesactivation) }).finally(() => mapsManager.isDeepLinksEnabled().then(enabled => setMapDeepLinksEnabled(() => enabled))); } const tooglePlaylistsDeepLinks = () => { const isDesactivation = playlistsDeepLinkEnabled; - playlistsManager.toogleDeepLinks().catch(() => { + playlistsManager.toogleDeepLinks().then(res => { + if(res){ return showDeepLinkSuccess(isDesactivation); } + showDeepLinkError(isDesactivation); + }).catch(() => { showDeepLinkError(isDesactivation); - }).then(res => { - if(!res){ return showDeepLinkWarning(isDesactivation); } - showDeepLinkSuccess(isDesactivation) }).finally(() => playlistsManager.isDeepLinksEnabled().then(enabled => setPlaylistsDeepLinkEnabled(() => enabled))); } const toogleModelsDeepLinks = () => { const isDesactivation = modelsDeepLinkEnabled; - modelsManager.toogleDeepLinks().catch(() => { - showDeepLinkError(isDesactivation) - }).then(res => { - if(!res){ return showDeepLinkWarning(isDesactivation); } - showDeepLinkSuccess(isDesactivation) + modelsManager.toogleDeepLinks().then(res => { + if(res){ return showDeepLinkSuccess(isDesactivation); } + showDeepLinkError(isDesactivation); + }).catch(() => { + showDeepLinkError(isDesactivation); }).finally(() => modelsManager.isDeepLinksEnabled().then(enabled => setModelsDeepLinkEnabled(() => enabled))); }