eletrotupi / tcc/ frontend/app/(tabs)/_layout.tsxde3942abec2fde759f3254cc59f6d34efcb79340
2.2 KB | 83 lines Raw
1
import { Tabs, Redirect, router } from 'expo-router';
2
import React, { useEffect } from 'react';
3
import { View, ActivityIndicator } from 'react-native';
4

5
import { HapticTab } from '@/components/misc/haptic-tab';
6
import { IconSymbol } from '@/components/ui/icon-symbol';
7
import { Colors } from '@/constants/theme';
8
import { useColorScheme } from '@/hooks/use-color-scheme';
9
import { useAuth } from '@/context/AuthContext';
10

11
export default function TabLayout() {
12
  const colorScheme = useColorScheme();
13
  const { isAuthenticated, isLoading } = useAuth();
14

15
  useEffect(() => {
16
    if (!isLoading && !isAuthenticated) {
17
      router.replace('/auth/login');
18
    }
19
  }, [isAuthenticated, isLoading]);
20

21
  if (isLoading) {
22
    return (
23
      <View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
24
        <ActivityIndicator size="large" />
25
      </View>
26
    );
27
  }
28

29
  if (!isAuthenticated) {
30
    return <Redirect href="/auth/login" />;
31
  }
32

33
  return (
34
    <Tabs
35
      screenOptions={{
36
        tabBarInactiveTintColor: Colors['light'].tabIconDefault,
37
        tabBarActiveTintColor: Colors['light'].tabIconSelected,
38
        headerShown: false,
39
        tabBarButton: HapticTab,
40
      }}>
41

42
      <Tabs.Screen
43
        name="history"
44
        options={{
45
          title: 'Histórico',
46
          tabBarIcon: ({ color }) => <IconSymbol size={28} name="history" color={color} />,
47
        }}
48
      />
49

50
      <Tabs.Screen
51
        name="insights"
52
        options={{
53
          title: 'Jornada',
54
          tabBarIcon: ({ color }) => <IconSymbol size={28} name="book" color={color} />,
55
        }}
56
      />
57

58
      <Tabs.Screen
59
        name="new"
60
        options={{
61
          title: 'Novo',
62
          tabBarIcon: ({ color }) => <IconSymbol size={28} name="add-circle" color={color} />,
63
        }}
64
      />
65

66
      <Tabs.Screen
67
        name="actions"
68
        options={{
69
          title: 'Ações',
70
          tabBarIcon: ({ color }) => <IconSymbol size={28} name="bolt" color={color} />,
71
        }}
72
      />
73

74
      <Tabs.Screen
75
        name="settings"
76
        options={{
77
          title: 'Ajustes',
78
          tabBarIcon: ({ color }) => <IconSymbol size={28} name="settings.fill" color={color} />,
79
        }}
80
      />
81
    </Tabs>
82
  );
83
}