add leave game dialog

This commit is contained in:
Halit Aksoy 2022-09-04 00:16:14 +03:00
parent 9ea7ecfe93
commit 886852611b
2 changed files with 27 additions and 8 deletions

View File

@ -21,8 +21,8 @@ export type Texts = {
YouLeftTheGame: string, YouLeftTheGame: string,
UserLeftTheGame: string, UserLeftTheGame: string,
SearchingOpponent: string, SearchingOpponent: string,
PleaseWait : string, PleaseWait: string,
GameDraw : string, GameDraw: string,
Anonymous: string, Anonymous: string,
GameNotFound: string, GameNotFound: string,
Loading: string, Loading: string,
@ -32,6 +32,9 @@ export type Texts = {
UCanOnlyPlayYourOwnPits: string, UCanOnlyPlayYourOwnPits: string,
UMustWaitUntilCurrentMoveComplete: string, UMustWaitUntilCurrentMoveComplete: string,
UCanNotPlayEmptyPit: string, UCanNotPlayEmptyPit: string,
AreYouSureToLeaveGame: string,
Yes: string,
Cancel: string,
} }
export const EnUs: Texts = { export const EnUs: Texts = {
@ -56,8 +59,8 @@ export const EnUs: Texts = {
YouLeftTheGame: "You Left The Game", YouLeftTheGame: "You Left The Game",
UserLeftTheGame: "Left The Game", UserLeftTheGame: "Left The Game",
SearchingOpponent: "Searching Opponent", SearchingOpponent: "Searching Opponent",
PleaseWait : "Please Wait", PleaseWait: "Please Wait",
GameDraw : "Draw", GameDraw: "Draw",
Anonymous: "Anonymous", Anonymous: "Anonymous",
GameNotFound: "Game Not Found", GameNotFound: "Game Not Found",
Loading: "Loading", Loading: "Loading",
@ -67,7 +70,9 @@ export const EnUs: Texts = {
UCanOnlyPlayYourOwnPits: "You can only play your own pits", UCanOnlyPlayYourOwnPits: "You can only play your own pits",
UMustWaitUntilCurrentMoveComplete: "You must wait until the current move is complete", UMustWaitUntilCurrentMoveComplete: "You must wait until the current move is complete",
UCanNotPlayEmptyPit: "You can not play empty pit", UCanNotPlayEmptyPit: "You can not play empty pit",
AreYouSureToLeaveGame: "Are you sure to leave game?",
Yes: "Yes",
Cancel: "Cancel",
} }
export const TrTr: Texts = { export const TrTr: Texts = {
@ -93,7 +98,7 @@ export const TrTr: Texts = {
UserLeftTheGame: "Oyundan Ayrıldı", UserLeftTheGame: "Oyundan Ayrıldı",
SearchingOpponent: "Rakip Aranıyor", SearchingOpponent: "Rakip Aranıyor",
PleaseWait: "Lütfen Bekleyin", PleaseWait: "Lütfen Bekleyin",
GameDraw : "Berabere", GameDraw: "Berabere",
Anonymous: "Anonim", Anonymous: "Anonim",
GameNotFound: "Oyun Bulunamadı", GameNotFound: "Oyun Bulunamadı",
Loading: "Yükleniyor", Loading: "Yükleniyor",
@ -103,4 +108,7 @@ export const TrTr: Texts = {
UCanOnlyPlayYourOwnPits: "Sadece sana ait olan kuyular ile oynayabilirsin", UCanOnlyPlayYourOwnPits: "Sadece sana ait olan kuyular ile oynayabilirsin",
UMustWaitUntilCurrentMoveComplete: "Devam eden haraketin bitmesini beklemelisin", UMustWaitUntilCurrentMoveComplete: "Devam eden haraketin bitmesini beklemelisin",
UCanNotPlayEmptyPit: "Boş kuyu ile oynayamazsın", UCanNotPlayEmptyPit: "Boş kuyu ile oynayamazsın",
AreYouSureToLeaveGame: "Oyundan ayrılmak istediğine emin misin?",
Yes: "Evet",
Cancel: "İptal"
} }

View File

@ -29,6 +29,7 @@ import BoardViewModel from '../viewmodel/BoardViewModel';
import Center from '../components/Center'; import Center from '../components/Center';
import { Game, GameUsersConnectionInfo } from '../models/Game'; import { Game, GameUsersConnectionInfo } from '../models/Game';
import notyf from '../util/Notyf'; import notyf from '../util/Notyf';
import swal from 'sweetalert';
const GamePage: FunctionComponent<{ const GamePage: FunctionComponent<{
context: Context, context: Context,
@ -138,7 +139,17 @@ const GamePage: FunctionComponent<{
const checkHasAnOngoingAction = () => hasOngoingAction; const checkHasAnOngoingAction = () => hasOngoingAction;
const onLeaveGameClick = () => { const onLeaveGameClick = () => {
swal({
title: context.texts.AreYouSureToLeaveGame,
icon: "warning",
buttons: [context.texts.Yes, context.texts.Cancel],
dangerMode: true,
})
.then((cancel) => {
if (!cancel) {
context.rtmt.sendMessage(channel_leave_game, {}); context.rtmt.sendMessage(channel_leave_game, {});
}
});
}; };
const onNewGameClick = () => { const onNewGameClick = () => {
@ -149,7 +160,7 @@ const GamePage: FunctionComponent<{
if (!game || isSpectator || !userKey) { if (!game || isSpectator || !userKey) {
return; return;
} }
if(game.mancalaGame.getPlayerIdByIndex(index) !== userKey) { if (game.mancalaGame.getPlayerIdByIndex(index) !== userKey) {
notyf.error(context.texts.UCanOnlyPlayYourOwnPits); notyf.error(context.texts.UCanOnlyPlayYourOwnPits);
return; return;
} }