From 3258068765f197e0191e1dcd4f8dd09be2808b18 Mon Sep 17 00:00:00 2001 From: 0hee0 Date: Sun, 29 May 2022 23:21:32 +0900 Subject: [PATCH] [#3] fix: add missing parts --- react-native/components/Home/NoEventBox.tsx | 7 ++- react-native/screens/HomeScreen.tsx | 47 +++++++++++++-------- react-native/screens/IntroductionScreen.tsx | 6 +-- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/react-native/components/Home/NoEventBox.tsx b/react-native/components/Home/NoEventBox.tsx index 848c1d1..c10747a 100644 --- a/react-native/components/Home/NoEventBox.tsx +++ b/react-native/components/Home/NoEventBox.tsx @@ -1,12 +1,15 @@ import React from "react"; import { View, Image, StyleSheet } from "react-native"; -import { Text } from 'native-base' +import { Text } from 'native-base'; +import i18n from 'i18n-js' +import '../../locales/i18n'; + export default function NoEventBox() { return ( - There's no events today! + {i18n.t('noEvent')} ); } diff --git a/react-native/screens/HomeScreen.tsx b/react-native/screens/HomeScreen.tsx index 7003f8e..a19d947 100644 --- a/react-native/screens/HomeScreen.tsx +++ b/react-native/screens/HomeScreen.tsx @@ -1,13 +1,15 @@ import React, { useEffect, useState } from 'react'; -import { StyleSheet, View, SafeAreaView, TouchableOpacity, Image, ImageBackground, Alert } from 'react-native'; +import { StyleSheet, View, SafeAreaView, TouchableOpacity, ImageBackground, Alert } from 'react-native'; import { Text } from 'native-base' import { theme } from '../core/theme'; import type { Navigation, UserData } from '../types'; import { useAuth } from '../contexts/Auth'; import { StackActions } from '@react-navigation/native'; -import { MaterialIcons, FontAwesome } from '@expo/vector-icons'; +import { MaterialIcons } from '@expo/vector-icons'; import HomeMenu from '../components/Home/HomeMenu'; import NoEventBox from '../components/Home/NoEventBox'; +import i18n from 'i18n-js' +import '../locales/i18n'; export default function HomeScreen({ navigation }: Navigation) { const [events, setEvents] = useState<{event_num: number, children: { cid: number, cname: string, events: string[] }[]}>( @@ -30,20 +32,21 @@ export default function HomeScreen({ navigation }: Navigation) { ); const SHOW_ALL = -1; const [nowSelectedChildId, setNowSelectedChildId] = useState(SHOW_ALL); - const [user, setUser] = useState(); + const [user, setUser] = useState({ + uid: 1, + username: "Soo", + uemail: "kaithape@gmail.com", + uprofileImg: 1, + ulanguage: "english", + uchildren:[{ cid: 1, cname:"Soo", cprofileImg: 1 }, { cid: 2, cname:"Hee", cprofileImg: 4 }] + }); const auth = useAuth(); useEffect(()=> { - // setUser(auth?.userData); - setUser({ - uid: 1, - username: "Soo", - uemail: "kaithape@gmail.com", - uprofileImg: 1, - ulanguage: "english", - uchildren:[{cid: 1, cname:"Soo"}, {cid: 2, cname:"Hee"}] - }) + if (auth?.userData) { + setUser(auth?.userData); + } navigation.setOptions({ headerRight: () => ( @@ -62,12 +65,13 @@ export default function HomeScreen({ navigation }: Navigation) { .then(response => response.json()) .then(data => { setEvents(data); - }) // console.log(data) + // console.log(data); + }) .catch((error) => { console.log(error) if (error?.response?.status==401) { //redirect to login - Alert.alert("The session has expired. Please log in again."); + Alert.alert(i18n.t('sessionExpired')); auth.signOut(); navigation.dispatch(StackActions.popToTop()) } @@ -75,6 +79,12 @@ export default function HomeScreen({ navigation }: Navigation) { } }, [auth]); + useEffect(() => { + if (events && events?.children?.length > 0) { + setNowSelectedChildId(events.children[0].cid); + } + }, [events]); + const handleNowSelectedChildId = (cid: number) => { setNowSelectedChildId(cid); } @@ -88,7 +98,7 @@ export default function HomeScreen({ navigation }: Navigation) { navigation.navigate('Translate')}> - Translate + {i18n.t('translate')} @@ -96,7 +106,7 @@ export default function HomeScreen({ navigation }: Navigation) { navigation.navigate('Search')}> - Search + {i18n.t('search')} @@ -104,7 +114,7 @@ export default function HomeScreen({ navigation }: Navigation) { - Today's Events + {i18n.t('todayEvent')} {notice.events.map((event, index) => { return ( - {`[${notice.cname}] ` + event} + {`[${notice.cname}] ` + event} ) })} )) @@ -257,3 +267,4 @@ const styles = StyleSheet.create({ alignItems: 'center', } }) + diff --git a/react-native/screens/IntroductionScreen.tsx b/react-native/screens/IntroductionScreen.tsx index a03442d..863daf9 100644 --- a/react-native/screens/IntroductionScreen.tsx +++ b/react-native/screens/IntroductionScreen.tsx @@ -32,9 +32,9 @@ export default function HomeScreen({ navigation }: Navigation) { }); const auth = useAuth(); - useEffect(() => { - navigation.navigate("Home"); - }) + // useEffect(() => { + // navigation.navigate("Home"); + // }) useEffect(() => { if (response?.type === "success") {