managarten/apps/presi/apps/mobile/app/_layout.tsx
Wuesteon d36b321d9d style: auto-format codebase with Prettier
Applied formatting to 1487+ files using pnpm format:write
  - TypeScript/JavaScript files
  - Svelte components
  - Astro pages
  - JSON configs
  - Markdown docs

  13 files still need manual review (Astro JSX comments)
2025-11-27 18:33:16 +01:00

124 lines
2.5 KiB
TypeScript

import { useEffect } from 'react';
import { Stack } from 'expo-router';
import { useSegments, useRouter } from 'expo-router';
import { View, TouchableOpacity, Text } from 'react-native';
import { MaterialIcons } from '@expo/vector-icons';
import { onAuthStateChange } from '../services/auth';
import { ThemeProvider, useTheme } from '../components/ThemeProvider';
import { Header } from '../components/Menu/Header';
function StackNavigator() {
const router = useRouter();
const { theme } = useTheme();
return (
<View style={{ flex: 1, backgroundColor: theme.colors.backgroundPage }}>
<Stack
screenOptions={{
header: ({ route, options }) => {
let title = options.title || '';
let showAddDeck = false;
let rightContent = options.headerRight?.({});
if (route.name === 'index') {
title = `My Decks (${route.params?.deckCount || 0})`;
showAddDeck = true;
}
return <Header title={title} showAddDeck={showAddDeck} rightContent={rightContent} />;
},
}}
>
<Stack.Screen
name="index"
options={{
title: 'My Decks',
}}
/>
<Stack.Screen
name="(auth)"
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="settings"
options={{
title: 'Settings',
}}
/>
<Stack.Screen
name="profile"
options={{
title: 'Profile',
}}
/>
<Stack.Screen
name="decks/[id]"
options={{
title: 'Deck Details',
}}
/>
<Stack.Screen
name="deck/[id]"
options={{
headerShown: false,
}}
/>
<Stack.Screen
name="create-deck"
options={{
title: 'Create New Deck',
presentation: 'modal',
}}
/>
<Stack.Screen
name="(auth)/login"
options={{
title: 'Login',
headerShown: false,
}}
/>
<Stack.Screen
name="(auth)/register"
options={{
title: 'Register',
headerShown: false,
}}
/>
</Stack>
</View>
);
}
function RootLayoutContent() {
const { theme } = useTheme();
return (
<View style={{ flex: 1, backgroundColor: theme.colors.backgroundPage }}>
<StackNavigator />
</View>
);
}
export default function RootLayout() {
const segments = useSegments();
const router = useRouter();
useEffect(() => {
const unsubscribe = onAuthStateChange((user) => {
if (!user && !segments.includes('(auth)')) {
router.replace('/login');
}
});
return () => {
unsubscribe();
};
}, [segments]);
return (
<ThemeProvider>
<RootLayoutContent />
</ThemeProvider>
);
}