-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
57 lines (51 loc) · 1.51 KB
/
App.js
File metadata and controls
57 lines (51 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import React, { useEffect } from 'react';
import { StatusBar } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { Provider, useDispatch, useSelector } from 'react-redux';
import store from './src/store';
import AppNavigator from './src/navigation/AppNavigator';
import { loadStoredAuth } from './src/store/authSlice';
import { loadFavorites } from './src/store/favoritesSlice';
import { loadTheme } from './src/store/themeSlice';
import { useTheme } from './src/hooks/useTheme';
import ErrorBoundary from './src/lib/errorBoundary';
function AppContent() {
const dispatch = useDispatch();
const { theme, isDark } = useTheme();
const { isInitialized } = useSelector((state) => state.auth);
useEffect(() => {
const initializeApp = async () => {
try {
await Promise.all([
dispatch(loadTheme()),
dispatch(loadStoredAuth()),
dispatch(loadFavorites()),
]);
} catch (error) {
console.error('Error initializing app:', error);
}
};
initializeApp();
}, [dispatch]);
if (!isInitialized) return null;
return (
<>
<StatusBar
barStyle={isDark ? 'light-content' : 'dark-content'}
backgroundColor={theme.colors.background}
/>
<NavigationContainer>
<AppNavigator />
</NavigationContainer>
</>
);
}
export default function App() {
return (
<ErrorBoundary>
<Provider store={store}>
<AppContent />
</Provider>
</ErrorBoundary>
);
}