Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesPull RequestsActionsSecurityInsightsSettings
✨ AI
More
Blame · Line-by-line history

RootNavigator.tsx

Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.

RootNavigator.tsxBlame81 lines · 1 contributor
c53cf00Claude1import React, { createContext, useState, useEffect } from 'react';
2import { NavigationContainer } from '@react-navigation/native';
3import { createNativeStackNavigator } from '@react-navigation/native-stack';
4import { View, ActivityIndicator } from 'react-native';
5import { colors } from '../theme/colors';
6import { AuthScreen } from '../screens/AuthScreen';
7import { MainTabNavigator } from './MainTabNavigator';
8import { useAuth } from '../hooks/useAuth';
9import { type User } from '../api/client';
10
11// ─── Auth context — shared across the whole app ───────────────────────────────
12
13export interface AuthContextValue {
14 user: User | null;
15 token: string | null;
16 login: (tokenOrUsername: string, password?: string, host?: string) => Promise<void>;
17 logout: () => Promise<void>;
18}
19
20export const AuthContext = createContext<AuthContextValue>({
21 user: null,
22 token: null,
23 login: async () => {},
24 logout: async () => {},
25});
26
27// ─── Root param list ──────────────────────────────────────────────────────────
28
29type RootStackParamList = {
30 Auth: undefined;
31 Main: undefined;
32};
33
34const Stack = createNativeStackNavigator<RootStackParamList>();
35
36// ─── Navigator ────────────────────────────────────────────────────────────────
37
38export function RootNavigator() {
39 const auth = useAuth();
40
41 const contextValue: AuthContextValue = {
42 user: auth.user,
43 token: auth.token,
44 login: auth.login,
45 logout: auth.logout,
46 };
47
48 if (auth.loading) {
49 return (
50 <View style={{ flex: 1, backgroundColor: colors.bg, alignItems: 'center', justifyContent: 'center' }}>
51 <ActivityIndicator size="large" color={colors.accent} />
52 </View>
53 );
54 }
55
56 return (
57 <AuthContext.Provider value={contextValue}>
58 <NavigationContainer
59 theme={{
60 dark: true,
61 colors: {
62 primary: colors.accent,
63 background: colors.bg,
64 card: colors.bgSecondary,
65 text: colors.text,
66 border: colors.border,
67 notification: colors.accent,
68 },
69 }}
70 >
71 <Stack.Navigator screenOptions={{ headerShown: false }}>
72 {auth.isAuthenticated ? (
73 <Stack.Screen name="Main" component={MainTabNavigator} />
74 ) : (
75 <Stack.Screen name="Auth" component={AuthScreen} />
76 )}
77 </Stack.Navigator>
78 </NavigationContainer>
79 </AuthContext.Provider>
80 );
81}