|
| 1 | +import { useEffect, useRef } from 'react'; |
| 2 | +import { View, Text, StyleSheet, TouchableOpacity, SafeAreaView, Platform, StatusBar } from 'react-native'; |
| 3 | +import { router, useRouter } from 'expo-router'; |
| 4 | +import CustomWebView from '../../components/CustomWebView'; |
| 5 | +import { useAuth } from '../../hooks/useAuth'; |
| 6 | +import { IconSymbol } from '@/components/ui/IconSymbol'; |
| 7 | + |
| 8 | +export default function TabOneScreen() { |
| 9 | + const { isAuthenticated, logout, token } = useAuth(); |
| 10 | + const router = useRouter(); |
| 11 | + const isFirstRender = useRef(true); |
| 12 | + |
| 13 | + useEffect(() => { |
| 14 | + // 첫 렌더링에서는 리다이렉트 스킵 |
| 15 | + if (isFirstRender.current) { |
| 16 | + isFirstRender.current = false; |
| 17 | + return; |
| 18 | + } |
| 19 | + |
| 20 | + // 이후 렌더링에서만 리다이렉트 수행 |
| 21 | + if (!isAuthenticated) { |
| 22 | + router.replace('/auth/login'); |
| 23 | + } |
| 24 | + }, [isAuthenticated]); |
| 25 | + |
| 26 | + const onPressLogout = async () => { |
| 27 | + try { |
| 28 | + await logout(); |
| 29 | + router.replace('/auth/login'); |
| 30 | + } catch (error) { |
| 31 | + console.error('로그아웃 실패:', error); |
| 32 | + } |
| 33 | + }; |
| 34 | + |
| 35 | + if (!isAuthenticated) { |
| 36 | + return null; |
| 37 | + } |
| 38 | + |
| 39 | + return ( |
| 40 | + <View style={styles.container}> |
| 41 | + <StatusBar barStyle="dark-content" backgroundColor="#f8f9fa" /> |
| 42 | + <View style={styles.webViewContainer}> |
| 43 | + <CustomWebView url="https://www.gitanimals.org/" token={token} /> |
| 44 | + </View> |
| 45 | + </View> |
| 46 | + ); |
| 47 | +} |
| 48 | + |
| 49 | +const styles = StyleSheet.create({ |
| 50 | + container: { |
| 51 | + flex: 1, |
| 52 | + backgroundColor: '#fff', |
| 53 | + }, |
| 54 | + safeArea: { |
| 55 | + backgroundColor: '#f8f9fa', |
| 56 | + }, |
| 57 | + header: { |
| 58 | + backgroundColor: '#f8f9fa', |
| 59 | + borderBottomWidth: 1, |
| 60 | + borderBottomColor: '#e9ecef', |
| 61 | + ...Platform.select({ |
| 62 | + ios: { |
| 63 | + shadowColor: '#000', |
| 64 | + shadowOffset: { width: 0, height: 1 }, |
| 65 | + shadowOpacity: 0.1, |
| 66 | + shadowRadius: 3, |
| 67 | + }, |
| 68 | + android: { |
| 69 | + elevation: 3, |
| 70 | + }, |
| 71 | + }), |
| 72 | + }, |
| 73 | + headerContent: { |
| 74 | + flexDirection: 'row', |
| 75 | + justifyContent: 'space-between', |
| 76 | + alignItems: 'center', |
| 77 | + paddingHorizontal: 16, |
| 78 | + paddingVertical: 12, |
| 79 | + }, |
| 80 | + titleContainer: { |
| 81 | + flexDirection: 'row', |
| 82 | + alignItems: 'center', |
| 83 | + }, |
| 84 | + welcomeText: { |
| 85 | + fontSize: 18, |
| 86 | + fontWeight: '600', |
| 87 | + color: '#24292e', |
| 88 | + marginLeft: 8, |
| 89 | + }, |
| 90 | + logoutButton: { |
| 91 | + backgroundColor: '#dc3545', |
| 92 | + paddingVertical: 8, |
| 93 | + paddingHorizontal: 16, |
| 94 | + borderRadius: 8, |
| 95 | + }, |
| 96 | + buttonText: { |
| 97 | + color: '#fff', |
| 98 | + fontSize: 14, |
| 99 | + fontWeight: '500', |
| 100 | + }, |
| 101 | + webViewContainer: { |
| 102 | + flex: 1, |
| 103 | + }, |
| 104 | +}); |
0 commit comments