mancala/mobile/src/screens/LobyScreen.tsx

33 lines
1.3 KiB
TypeScript
Raw Normal View History

2024-03-24 14:23:08 +03:00
import * as React from 'react';
import { View, Text, Button } from 'react-native';
import { useTranslation } from 'react-i18next';
import { LobyScreenProps } from '../types';
import { useEffect } from 'react';
import { CommonMancalaGame } from 'mancala.js';
import { channel_on_game_start } from '../const/channel_names';
2024-03-24 14:23:08 +03:00
export default function LobyScreen({ navigation, route }: LobyScreenProps) {
const { context } = route.params;
2024-03-24 14:23:08 +03:00
const { t } = useTranslation();
const onGameStart = async (message: Object) => {
const newGame: CommonMancalaGame = message as CommonMancalaGame;
const userKey = await context.userKeyStore.getUserKey();
2024-03-31 16:39:39 +03:00
navigation.replace("Game", { context, gameId: newGame.id, userKey })
}
useEffect(() => {
context.rtmt.addMessageListener(channel_on_game_start, onGameStart);
context.rtmt.sendMessage("new_game", {});
return () => {
context.rtmt.removeMessageListener(channel_on_game_start, onGameStart);
}
}, []);
2024-03-24 14:23:08 +03:00
return (
2024-03-31 16:39:39 +03:00
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: context.themeManager.theme?.background }}>
2024-03-31 17:29:52 +03:00
<Text style={{color: "#000"}}>{t('SearchingOpponent')}</Text>
2024-03-24 14:23:08 +03:00
</View>
);
}