fix new game button

This commit is contained in:
Halit Aksoy 2024-03-31 17:08:59 +03:00
parent 4f45da5ab5
commit 3a83bf1cd5

View File

@ -1,11 +1,10 @@
import * as React from 'react'; import * as React from 'react';
import { View, Button, Text, useWindowDimensions, Alert } from 'react-native'; import { View, Text, useWindowDimensions, Alert, Pressable } from 'react-native';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { GameScreenProps } from '../types'; import { GameScreenProps } from '../types';
import { useState } from 'react'; import { useState } from 'react';
import { Game, GameUsersConnectionInfo } from '../models/Game'; import { Game, GameUsersConnectionInfo } from '../models/Game';
import BoardViewModel from '../viewmodel/BoardViewModel'; import BoardViewModel from '../viewmodel/BoardViewModel';
import { Link } from '@react-navigation/native';
import { MancalaGame, Pit } from 'mancala.js'; import { MancalaGame, Pit } from 'mancala.js';
import { v4 } from 'uuid'; import { v4 } from 'uuid';
import PitAnimator from '../animation/PitAnimator'; import PitAnimator from '../animation/PitAnimator';
@ -22,6 +21,7 @@ import LoadingComponent from '../components/LoadingComponent';
import UserStatus from '../components/UserStatus'; import UserStatus from '../components/UserStatus';
import BoardToolbar from '../components/board/BoardToolbar'; import BoardToolbar from '../components/board/BoardToolbar';
import BoardView from '../components/board/BoardView'; import BoardView from '../components/board/BoardView';
import CircularPanel from '../components/CircularPanel';
export function GameScreen({ navigation, route }: GameScreenProps) { export function GameScreen({ navigation, route }: GameScreenProps) {
const { context, gameId, userKey } = route.params; const { context, gameId, userKey } = route.params;
@ -212,23 +212,25 @@ export function GameScreen({ navigation, route }: GameScreenProps) {
}, []); }, []);
const updateHeaderButton = () => { const updateHeaderButton = () => {
console.info(game?.mancalaGame.state) const isGameEnded = game?.mancalaGame.state === "ended" || leftPlayer;
navigation.setOptions({ navigation.setOptions({
headerRight: () => ( headerRight: () => (
<Button onPress={() => { <Pressable onPress={() => {
if (game?.mancalaGame.state !== "ended") { if (isGameEnded) {
onLeaveGameClick();
} else {
onNewGameClick(); onNewGameClick();
} else {
onLeaveGameClick();
} }
}} title={game?.mancalaGame.state !== "ended" ? t('Leave') : t('NewGame')} /> }}>
<CircularPanel color={context.themeManager.theme?.background} children={<Text style={{ color: context.themeManager.theme.textColor }}>{isGameEnded ? t('NewGame') : t('Leave')}</Text>} />
</Pressable>
), ),
}); });
} }
React.useEffect(() => { React.useEffect(() => {
updateHeaderButton(); updateHeaderButton();
}, [navigation, game]); }, [navigation, game, userKeyWhoLeave]);
const textColorOnAppBar = getColorByBrightness( const textColorOnAppBar = getColorByBrightness(
context.themeManager.theme.appBarBgColor, context.themeManager.theme.appBarBgColor,