add alert for userkey error

This commit is contained in:
Halit Aksoy 2022-09-03 23:27:13 +03:00
parent 81365b8353
commit 6d28d86a7c
2 changed files with 17 additions and 4 deletions

View File

@ -15,6 +15,8 @@ import { getColorByBrightness } from './util/ColorUtil';
import { ConnectionState } from './models/ConnectionState'; import { ConnectionState } from './models/ConnectionState';
import { Theme } from './theme/Theme'; import { Theme } from './theme/Theme';
import LobyPage from './routes/LobyPage'; import LobyPage from './routes/LobyPage';
import swal from 'sweetalert';
const context = initContext(); const context = initContext();
const MancalaApp: FunctionComponent = () => { const MancalaApp: FunctionComponent = () => {
@ -40,9 +42,15 @@ const MancalaApp: FunctionComponent = () => {
setTheme(theme) setTheme(theme)
} }
const connectToServer = async () => { const connectToServer = async () => {
const userKey = await context.userKeyStore.getUserKey(); try {
setUserKey(userKey); const userKey = await context.userKeyStore.getUserKey();
(context.rtmt as RTMTWS).initWebSocket(userKey); 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(() => { React.useEffect(() => {
@ -74,7 +82,6 @@ const MancalaApp: FunctionComponent = () => {
context.themeManager.theme.textColor, context.themeManager.theme.textColor,
context.themeManager.theme.textLightColor context.themeManager.theme.textLightColor
); );
if (!userKey) return <></>;
return ( return (
<> <>
<BrowserRouter> <BrowserRouter>

View File

@ -27,6 +27,8 @@ export type Texts = {
GameNotFound: string, GameNotFound: string,
Loading: string, Loading: string,
Playing: string, Playing: string,
Error: string,
ErrorWhenRetrievingInformation: string;
} }
export const EnUs: Texts = { export const EnUs: Texts = {
@ -57,6 +59,8 @@ export const EnUs: Texts = {
GameNotFound: "Game Not Found", GameNotFound: "Game Not Found",
Loading: "Loading", Loading: "Loading",
Playing: "Playing", Playing: "Playing",
Error: "Error",
ErrorWhenRetrievingInformation: "An error occured when retrieving information!"
} }
export const TrTr: Texts = { export const TrTr: Texts = {
@ -87,4 +91,6 @@ export const TrTr: Texts = {
GameNotFound: "Oyun Bulunamadı", GameNotFound: "Oyun Bulunamadı",
Loading: "Yükleniyor", Loading: "Yükleniyor",
Playing: "Oynuyor", Playing: "Oynuyor",
Error: "Hata",
ErrorWhenRetrievingInformation: "Bilgiler toplanırken bir hata oluştu!"
} }