import * as React from 'react'; import { View, Button, Pressable, Text } from 'react-native'; import { useTranslation } from 'react-i18next'; import { HomeScreenProps } from '../types'; import CircularPanel from '../components/CircularPanel'; import { SvgXml } from 'react-native-svg'; import helpSvg from '../svg/help'; import { getColorByBrightness } from "@mancala/core"; export function HomeScreen({ navigation, route }: HomeScreenProps) { const { context } = route.params; const { t } = useTranslation(); const [lastGameId, setLastGameId] = React.useState(undefined); const textColorOnAppBar = getColorByBrightness( context.themeManager.theme.appBarBgColor, context.themeManager.theme.textColor, context.themeManager.theme.textLightColor ); const updateHeaderButton = () => { navigation.setOptions({ headerRight: () => ( { navigation.push("Help", { context }) }}> ), }); } React.useEffect(() => { updateHeaderButton(); const savedGameId = context.storage.getString('lastGameId'); if (savedGameId) { setLastGameId(savedGameId); } }, []); return ( navigation.replace('Loby', { context })}> {t('NewGame')}} /> {lastGameId && ( <> { try { const userKey = await context.userKeyStore.getUserKey(); navigation.replace('Game', { context, gameId: lastGameId, userKey }); } catch (error) { context.storage.deleteString('lastGameId'); setLastGameId(undefined); } }}> {t('RejoinGame')}} /> )} ); }