-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathApp.tsx
More file actions
103 lines (90 loc) · 2.84 KB
/
Copy pathApp.tsx
File metadata and controls
103 lines (90 loc) · 2.84 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Mediora - Apple tvOS Media App
* A media center app for browsing Jellyfin, searching TMDB,
* and requesting content via Sonarr/Radarr
*/
import React, { useEffect, useState } from 'react';
import { StatusBar, StyleSheet, View, LogBox } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { enableScreens } from 'react-native-screens';
import { SettingsProvider, ServicesProvider, useSettings } from './src/context';
import { AppNavigator } from './src/navigation';
import { LoadingScreen } from './src/components';
import { OnboardingScreen } from './src/screens';
// Enable native screens for better performance
enableScreens();
// Ignore specific warnings that are common in tvOS development
LogBox.ignoreLogs([
'Sending `onAnimatedValueUpdate` with no listeners registered',
'Non-serializable values were found in the navigation state',
]);
const ONBOARDING_SKIPPED_KEY = '@mediora/onboardingSkipped';
function AppContent() {
const { settings, isLoading } = useSettings();
const [onboardingStatus, setOnboardingStatus] = useState<
'loading' | 'show' | 'hide'
>('loading');
// Read the skip flag: users who opt into manual setup shouldn't see
// onboarding again on this device.
useEffect(() => {
let isMounted = true;
AsyncStorage.getItem(ONBOARDING_SKIPPED_KEY)
.then(skipped => {
if (isMounted) {
setOnboardingStatus(skipped === 'true' ? 'hide' : 'show');
}
})
.catch(() => {
if (isMounted) setOnboardingStatus('show');
});
return () => {
isMounted = false;
};
}, []);
// Once a connection is configured, clear the skip flag so onboarding
// reappears if settings are later cleared.
useEffect(() => {
if (settings.jellyfin) {
AsyncStorage.removeItem(ONBOARDING_SKIPPED_KEY).catch(() => {});
}
}, [settings.jellyfin]);
if (isLoading || onboardingStatus === 'loading') {
return <LoadingScreen message="Loading Mediora..." />;
}
// First run with no connection configured: offer invite code or manual setup.
if (!settings.jellyfin && onboardingStatus === 'show') {
return (
<OnboardingScreen
onSetupManually={() => {
AsyncStorage.setItem(ONBOARDING_SKIPPED_KEY, 'true').catch(() => {});
setOnboardingStatus('hide');
}}
/>
);
}
return (
<View style={styles.container}>
<StatusBar hidden />
<AppNavigator />
</View>
);
}
function App() {
return (
<SafeAreaProvider>
<SettingsProvider>
<ServicesProvider>
<AppContent />
</ServicesProvider>
</SettingsProvider>
</SafeAreaProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#000',
},
});
export default App;