From 6d28d86a7ce8990d2ad52cb0e02b2c133409c1cb Mon Sep 17 00:00:00 2001 From: Halit Aksoy Date: Sat, 3 Sep 2022 23:27:13 +0300 Subject: [PATCH] add alert for userkey error --- src/MancalaApp.tsx | 15 +++++++++++---- src/const/texts.ts | 6 ++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/MancalaApp.tsx b/src/MancalaApp.tsx index 03b46a4..0dd1c4f 100644 --- a/src/MancalaApp.tsx +++ b/src/MancalaApp.tsx @@ -15,6 +15,8 @@ import { getColorByBrightness } from './util/ColorUtil'; import { ConnectionState } from './models/ConnectionState'; import { Theme } from './theme/Theme'; import LobyPage from './routes/LobyPage'; +import swal from 'sweetalert'; + const context = initContext(); const MancalaApp: FunctionComponent = () => { @@ -40,9 +42,15 @@ const MancalaApp: FunctionComponent = () => { setTheme(theme) } const connectToServer = async () => { - const userKey = await context.userKeyStore.getUserKey(); - setUserKey(userKey); - (context.rtmt as RTMTWS).initWebSocket(userKey); + try { + const userKey = await context.userKeyStore.getUserKey(); + setUserKey(userKey); + (context.rtmt as RTMTWS).initWebSocket(userKey); + } catch (error) { + //TODO: check if it is network error! + swal(context.texts.Error + "!", context.texts.ErrorWhenRetrievingInformation, "error"); + console.error(error); + } }; React.useEffect(() => { @@ -74,7 +82,6 @@ const MancalaApp: FunctionComponent = () => { context.themeManager.theme.textColor, context.themeManager.theme.textLightColor ); - if (!userKey) return <>; return ( <> diff --git a/src/const/texts.ts b/src/const/texts.ts index cf8cfce..7065ffc 100644 --- a/src/const/texts.ts +++ b/src/const/texts.ts @@ -27,6 +27,8 @@ export type Texts = { GameNotFound: string, Loading: string, Playing: string, + Error: string, + ErrorWhenRetrievingInformation: string; } export const EnUs: Texts = { @@ -57,6 +59,8 @@ export const EnUs: Texts = { GameNotFound: "Game Not Found", Loading: "Loading", Playing: "Playing", + Error: "Error", + ErrorWhenRetrievingInformation: "An error occured when retrieving information!" } export const TrTr: Texts = { @@ -87,4 +91,6 @@ export const TrTr: Texts = { GameNotFound: "Oyun Bulunamadı", Loading: "Yükleniyor", Playing: "Oynuyor", + Error: "Hata", + ErrorWhenRetrievingInformation: "Bilgiler toplanırken bir hata oluştu!" } \ No newline at end of file