mirror of
https://github.com/mudabbir-ahmad/Media-Aggregation-and-Sorting-System.git
synced 2026-10-08 03:40:20 +00:00
148 lines
4.7 KiB
JavaScript
148 lines
4.7 KiB
JavaScript
import React, { useEffect, useState } from 'react';
|
|
import { StatusBar } from 'expo-status-bar';
|
|
import { NavigationContainer } from '@react-navigation/native';
|
|
import { createNativeStackNavigator } from '@react-navigation/native-stack';
|
|
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
|
|
import { ActivityIndicator, View, Text, TouchableOpacity } from 'react-native';
|
|
import * as WebBrowser from 'expo-web-browser';
|
|
import { ThemeProvider, useTheme } from './src/services/ThemeContext';
|
|
import DatabaseService from './src/services/DatabaseService';
|
|
import LoginScreen from './src/screens/LoginScreen';
|
|
import RegisterScreen from './src/screens/RegisterScreen';
|
|
import OnboardingScreen from './src/screens/OnboardingScreen';
|
|
import HomeScreen from './src/screens/HomeScreen';
|
|
import SearchScreen from './src/screens/SearchScreen';
|
|
import CollectionsScreen from './src/screens/AlbumsScreen';
|
|
import SettingsScreen from './src/screens/SettingsScreen';
|
|
|
|
// Required for OAuth deep link redirect to close the browser and return to the app
|
|
WebBrowser.maybeCompleteAuthSession();
|
|
|
|
const Stack = createNativeStackNavigator();
|
|
const Tab = createBottomTabNavigator();
|
|
|
|
// Bottom tab navigator shown after login
|
|
function MainTabs({ route }) {
|
|
const { userId } = route.params || {};
|
|
const { theme } = useTheme();
|
|
|
|
return (
|
|
<Tab.Navigator
|
|
screenOptions={{
|
|
headerShown: false,
|
|
tabBarActiveTintColor: theme.tabActive,
|
|
tabBarInactiveTintColor: theme.tabInactive,
|
|
tabBarStyle: {
|
|
backgroundColor: theme.tabBar,
|
|
borderTopColor: theme.tabBarBorder,
|
|
borderTopWidth: 1,
|
|
height: 56,
|
|
paddingBottom: 6,
|
|
paddingTop: 6,
|
|
},
|
|
tabBarLabelStyle: { fontSize: 11, fontWeight: '500' },
|
|
}}
|
|
>
|
|
<Tab.Screen
|
|
name="Library"
|
|
component={HomeScreen}
|
|
initialParams={{ userId }}
|
|
options={{
|
|
tabBarLabel: 'Library',
|
|
tabBarIcon: ({ color }) => <Text style={{ fontSize: 22, color }}>🖼️</Text>,
|
|
}}
|
|
/>
|
|
<Tab.Screen
|
|
name="Search"
|
|
component={SearchScreen}
|
|
initialParams={{ userId }}
|
|
options={{
|
|
tabBarLabel: 'Search',
|
|
tabBarIcon: ({ color }) => <Text style={{ fontSize: 22, color }}>🔍</Text>,
|
|
}}
|
|
/>
|
|
<Tab.Screen
|
|
name="Collections"
|
|
component={CollectionsScreen}
|
|
initialParams={{ userId }}
|
|
options={{
|
|
tabBarLabel: 'Collections',
|
|
tabBarIcon: ({ color }) => <Text style={{ fontSize: 22, color }}>📁</Text>,
|
|
}}
|
|
/>
|
|
</Tab.Navigator>
|
|
);
|
|
}
|
|
|
|
// Root stack navigator
|
|
function AppNavigator() {
|
|
return (
|
|
<Stack.Navigator screenOptions={{ headerShown: false }}>
|
|
<Stack.Screen name="Login" component={LoginScreen} />
|
|
<Stack.Screen name="Register" component={RegisterScreen} />
|
|
<Stack.Screen name="Onboarding" component={OnboardingScreen} />
|
|
<Stack.Screen name="MainTabs" component={MainTabs} />
|
|
<Stack.Screen name="Settings" component={SettingsScreen} />
|
|
</Stack.Navigator>
|
|
);
|
|
}
|
|
|
|
function AppInner() {
|
|
const { theme } = useTheme();
|
|
const [isReady, setIsReady] = useState(false);
|
|
const [error, setError] = useState(null);
|
|
|
|
useEffect(() => { initializeApp(); }, []);
|
|
|
|
const initializeApp = async () => {
|
|
try {
|
|
setError(null);
|
|
await DatabaseService.initDatabase();
|
|
setIsReady(true);
|
|
} catch (err) {
|
|
console.error('Database initialization failed:', err);
|
|
setError(err.message || 'Database initialization failed');
|
|
setIsReady(false);
|
|
}
|
|
};
|
|
|
|
if (!isReady && !error) {
|
|
return (
|
|
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: theme.background }}>
|
|
<ActivityIndicator size="large" color={theme.primary} />
|
|
</View>
|
|
);
|
|
}
|
|
|
|
if (error) {
|
|
return (
|
|
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center', paddingHorizontal: 20, backgroundColor: theme.background }}>
|
|
<Text style={{ fontSize: 16, color: theme.text, marginBottom: 12, textAlign: 'center' }}>{error}</Text>
|
|
<TouchableOpacity
|
|
onPress={initializeApp}
|
|
style={{ backgroundColor: theme.primary, paddingHorizontal: 16, paddingVertical: 10, borderRadius: 6 }}
|
|
>
|
|
<Text style={{ color: '#fff', fontWeight: '600' }}>Retry</Text>
|
|
</TouchableOpacity>
|
|
</View>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<NavigationContainer>
|
|
<AppNavigator />
|
|
</NavigationContainer>
|
|
<StatusBar style={theme.statusBarStyle} backgroundColor={theme.background} />
|
|
</>
|
|
);
|
|
}
|
|
|
|
export default function App() {
|
|
return (
|
|
<ThemeProvider>
|
|
<AppInner />
|
|
</ThemeProvider>
|
|
);
|
|
}
|