feat: initialize mobile blackjack app with authentication and game features
This commit is contained in:
65
App.js
Normal file
65
App.js
Normal file
@@ -0,0 +1,65 @@
|
||||
import { useCallback, useState } from 'react';
|
||||
import { ActivityIndicator, StyleSheet, View } from 'react-native';
|
||||
import { StripeProvider } from '@stripe/stripe-react-native';
|
||||
import { SafeAreaProvider } from 'react-native-safe-area-context';
|
||||
import { colors } from './src/theme';
|
||||
import { apiFetch } from './src/api';
|
||||
import { useAuth } from './src/hooks/useAuth';
|
||||
import LoginScreen from './src/screens/LoginScreen';
|
||||
import LobbyScreen from './src/screens/LobbyScreen';
|
||||
import TableScreen from './src/screens/TableScreen';
|
||||
|
||||
export default function App() {
|
||||
const { token, user, loading, login, logout, setUser } = useAuth();
|
||||
const [selectedTable, setSelectedTable] = useState(null);
|
||||
|
||||
const refreshUser = useCallback(async () => {
|
||||
if (!token) {
|
||||
return;
|
||||
}
|
||||
const data = await apiFetch('/api/me', token);
|
||||
setUser(data);
|
||||
}, [token, setUser]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
<View style={styles.loading}>
|
||||
<ActivityIndicator color={colors.goldBright} />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<SafeAreaProvider>
|
||||
<StripeProvider publishableKey={process.env.EXPO_PUBLIC_STRIPE_PUBLISHABLE_KEY || ''}>
|
||||
{!token || !user ? (
|
||||
<LoginScreen onLogin={login} loading={loading} />
|
||||
) : selectedTable ? (
|
||||
<TableScreen
|
||||
token={token}
|
||||
tableId={selectedTable}
|
||||
user={user}
|
||||
onLeave={() => setSelectedTable(null)}
|
||||
/>
|
||||
) : (
|
||||
<LobbyScreen
|
||||
user={user}
|
||||
token={token}
|
||||
onLogout={logout}
|
||||
onSelectTable={setSelectedTable}
|
||||
onRefreshUser={refreshUser}
|
||||
/>
|
||||
)}
|
||||
</StripeProvider>
|
||||
</SafeAreaProvider>
|
||||
);
|
||||
}
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
loading: {
|
||||
flex: 1,
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
backgroundColor: colors.backgroundTop
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user