Skip to content

Commit

Permalink
Merge pull request #50 from dsc-sookmyung/feature/translate
Browse files Browse the repository at this point in the history
[#11] feat: implement api fetch
  • Loading branch information
hee-suh authored Mar 23, 2022
2 parents 644aeb5 + eba7ed9 commit 348bdae
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
13 changes: 12 additions & 1 deletion react-native/components/BottomDrawer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Popover, Button, Text, Modal, FormControl, Input, VStack, Select, Check
import { theme } from '../core/theme';
import type { BottomDrawerProps, EventForm, UserData } from '../types';
import { useAuth } from '../contexts/Auth';
import { useNavigation, StackActions } from '@react-navigation/native';


const highlight = (text: string, registered: boolean) =>
Expand All @@ -20,6 +21,7 @@ function BottomDrawer(props: BottomDrawerProps) {
const [user, setUser] = useState<UserData>({uid: 1, uprofileImg: 1, username: 'hee', ulanguage: 'ko', uchildren: [{cid: 1, cname: 'soo', color: 1}, {cid: 2, cname: 'joo', color: 3}]})
// const [user, setUser] = useState<UserData>();
const auth = useAuth();
const navigation = useNavigation();

useEffect(()=> {
// setUser(auth?.userData);
Expand Down Expand Up @@ -76,7 +78,16 @@ function BottomDrawer(props: BottomDrawerProps) {
})
.then(response => response.json())
.then(data => status = data)
.catch(error => console.log('error', error));
.catch(function (error) {
console.log(error.response.status) // 401
console.log(error.response.data.error) //Please Authenticate or whatever returned from server
if(error.response.status==401) {
//redirect to login
Alert.alert("The session has expired. Please log in again.");
auth.signOut();
navigation.dispatch(StackActions.popToTop())
}
});
}

switch (status) {
Expand Down
17 changes: 14 additions & 3 deletions react-native/screens/TranslateScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ export default function TranslateScreen({ navigation }: Navigation) {
console.log(error.response.data.error) //Please Authenticate or whatever returned from server
if(error.response.status==401) {
//redirect to login
Alert.alert("The session has expired. Please log in again.");

auth.signOut();
navigation.dispatch(StackActions.popToTop())
}
Expand Down Expand Up @@ -182,10 +184,10 @@ export default function TranslateScreen({ navigation }: Navigation) {
'fullText': results?.fullText,
'korean': results?.korean
}
formdata.append('noticeRequestDTO', data);
formdata.append('noticeRequestDTO', new Blob([JSON.stringify(data)], {type: 'application/json'}));

if (auth?.authData?.jwt_token) {
fetch("http://localhost:8080/notice/ocr", {
fetch('http://localhost:8080/notice/ocr', {
method: 'POST',
headers: {
'JWT_TOKEN': auth.authData.jwt_token
Expand All @@ -195,7 +197,16 @@ export default function TranslateScreen({ navigation }: Navigation) {
})
.then(response => response.json())
.then(data => Alert.alert(`The result was saved in Search as [${data?.title}]`))
.catch(error => console.log('error', error));
.catch(function (error) {
console.log(error.response.status) // 401
console.log(error.response.data.error) //Please Authenticate or whatever returned from server
if(error.response.status==401) {
//redirect to login
Alert.alert("The session has expired. Please log in again.");
auth.signOut();
navigation.dispatch(StackActions.popToTop())
}
});
}
}
}
Expand Down

0 comments on commit 348bdae

Please sign in to comment.