diff --git a/react-native/screens/TranslateScreen.tsx b/react-native/screens/TranslateScreen.tsx index ff93801..f99bc43 100644 --- a/react-native/screens/TranslateScreen.tsx +++ b/react-native/screens/TranslateScreen.tsx @@ -1,14 +1,12 @@ import React, { useState, useEffect } from 'react'; import { StyleSheet, View, TouchableOpacity, ImageBackground, Dimensions, Alert } from 'react-native'; +import { useToast, Box, Modal, Button, HStack, Text, Divider } from 'native-base'; import { Camera } from 'expo-camera'; import { Ionicons } from '@expo/vector-icons'; import { theme } from '../core/theme'; import type { Navigation, Result, ResultsForm } from '../types'; -import AppLoading from 'expo-app-loading'; -import useFonts from '../hooks/useFonts' import SwipeUpDown from 'react-native-swipe-up-down'; import BottomDrawer from '../components/BottomDrawer'; -import { useToast, Box } from 'native-base'; import mime from "mime"; import * as ImagePicker from 'expo-image-picker'; import { useAuth } from '../contexts/Auth'; @@ -27,23 +25,19 @@ const date = new Date(); export default function TranslateScreen({ navigation }: Navigation) { const [hasPermission, setHasPermission] = useState(false); - const [fontsLoaded, SetFontsLoaded] = useState(false); const [type, setType] = useState(Camera.Constants.Type.back); const [camera, setCamera] = useState(null); const [imageUri, setImageUri] = useState(''); - const [results, setResults] = useState({fullText: [], korean: '', trans_full: ''}); + const [results, setResults] = useState(); const [showKorean, setShowKorean] = useState(false); const [isFullDrawer, setFullDrawer] = useState(false); const [loading, setLoading] = useState(false); const [openSaveForm, setOpenSaveForm] = useState(false); + const [openInitialEventForm, setOpenInitialEventForm] = useState(false); const toast = useToast(); const auth = useAuth(); - const LoadFontsAndRestoreToken = async () => { - await useFonts(); - }; - useEffect(() => { (async () => { const { status } = await Camera.requestCameraPermissionsAsync(); @@ -55,20 +49,34 @@ export default function TranslateScreen({ navigation }: Navigation) { if (imageUri) { extractText } - }, [imageUri]) + }, [imageUri]); useEffect(() => { if (results?.fullText && results.fullText.filter(item => item.highlight === true).length > 0) { - const message = i18n.t('translateMessage_1') - toast.show({ // Design according to mui toast guidelines (https://material.io/components/snackbars#anatomy) - render: () => { - return - {message} - ; - } - }); + // const message = i18n.t('translateMessage_1') + // toast.show({ // Design according to mui toast guidelines (https://material.io/components/snackbars#anatomy) + // render: () => { + // return + // {message} + // ; + // } + // }); + if (results?.event_num) { + setOpenInitialEventForm(true); + } + else { + const message = "There are no extracted events!" + toast.show({ // Design according to mui toast guidelines (https://material.io/components/snackbars#anatomy) + placement: "top", + render: () => { + return + {message} + ; + } + }); + } } - }, [results]) + }, [results]); // DEV TEST // if (hasPermission === null) { @@ -78,16 +86,6 @@ export default function TranslateScreen({ navigation }: Navigation) { // return No access to camera! // } - if (!fontsLoaded) { - return ( - SetFontsLoaded(true)} - onError={() => {}} - /> - ); - } - const takePicture = async () => { if (camera) { const data = await camera.takePictureAsync(null); @@ -135,9 +133,9 @@ export default function TranslateScreen({ navigation }: Navigation) { }) .then(response => response.json()) .then(data => { - console.log(data) - setResults(data) - setLoading(false) + console.log(data); + setResults(data); + setLoading(false); }) .catch(function (error) { console.log(error?.response?.status) // 401 @@ -151,6 +149,30 @@ export default function TranslateScreen({ navigation }: Navigation) { }); } } + + // TEST: mockup data + // setResults({ + // fullText: [ + // {id: 1, content: "1. Schedule of the closing ceremony and diploma presentation ceremony: Friday, January 4, 2019 at 9 o'clock for students to go to school.\n1) ", date: "", highlight: false, registered: false}, + // {id: 2, content: "Closing ceremony", date: "2022-01-04", highlight: true, registered: false}, + // {id: 3, content: ": 1st and 2nd graders, each classroom, 9:00-10:50 (no meals)\n2) ", date: "", highlight: false, registered: false}, + // {id: 4, content: "Diploma representation ceremony", date: "2022-01-04", highlight: true, registered: true}, + // {id: 5, content: ": 3rd grade, multi-purpose auditorium (2nd floor), 10:30-12:20\n2. School opening and entrance ceremony for new students: March 4th (Mon), 2019 at 9 o'clock for students to go to school.", date: "", highlight: false, registered: false}, + // ], + // korean: "가정통신문\n예당중학교\n8053-8388\n꿈은 크게. 마음은 넘게·\n행동은 바르게\n학부모님께\n희망찬 새해를 맞이하며 학부모님 가정에 건강과 행운이 함께 하시기를 기원 드립니다.\n드릴 말씀은, 2018학년도 종업식 및 졸업장 수여식과 2019학년도 개학 및 신입생 입학식을 다음과 같이 안내드리오니, 이후 3월 개학 때까지 학생들이 자기주도 학습 능력을 배양하고 다양한 체험 활동을 통하여 심신이 건강해지며 각종 유해 환경에 노출되지 않고 안전하고 줄거운 시간이 되도록 지도해 주시기 바랍니다.\n", + // trans_full: "", + // event_num: 2, + // events: [ + // { + // title: "opening ceremony", + // date: "2022-03-24" + // }, + // { + // title: "closing ceremony", + // date: "2022-03-24" + // } + // ] + // }) } const handleKorean = (): void => { @@ -223,10 +245,6 @@ export default function TranslateScreen({ navigation }: Navigation) { } } - const closeResults = (): void => { - navigation.navigate('Home'); - } - const retakePicture = (): void => { setImageUri(''); setResults({id: 0, fullText: [], korean: ''}); @@ -252,7 +270,6 @@ export default function TranslateScreen({ navigation }: Navigation) { openSaveForm={openSaveForm} handleKorean={handleKorean} saveResults={saveResults} - closeResults={closeResults} retakePicture={retakePicture} handleOpenSaveForm={handleOpenSaveForm} /> @@ -266,7 +283,6 @@ export default function TranslateScreen({ navigation }: Navigation) { openSaveForm={openSaveForm} handleKorean={handleKorean} saveResults={saveResults} - closeResults={closeResults} retakePicture={retakePicture} handleOpenSaveForm={handleOpenSaveForm} /> @@ -278,8 +294,28 @@ export default function TranslateScreen({ navigation }: Navigation) { extraMarginTop={10} swipeHeight={Dimensions.get('window').height*0.65} /> + + + + {results?.event_num} Events Extracted + + + {results?.events?.map((item, index) => + + {item.date}  + {item.title} + + )} + + + + + + + - ) : ( /* After taking a picture, before OCR(pressing the check button) */ diff --git a/react-native/types.ts b/react-native/types.ts index 5be067b..2c9db0a 100644 --- a/react-native/types.ts +++ b/react-native/types.ts @@ -77,7 +77,10 @@ interface Result { imageUri?: string, fullText: Event[], korean: string, - trans_full?: string + trans_full?: string, + + event_num?: number, + events?: { title: string, date: string }[] } interface Notice {