-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
78 lines (72 loc) · 3.08 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, {Component}from 'react';
import SignUp from "./components/SignUp";
import {Scene, Router} from 'react-native-router-flux';
import Login from './components/Login';
import Home from "./components/Home";
import {AsyncStorage} from "react-native"
import {TOKEN_KEY, API_URL} from "./constant";
import MealPlanRecipe from "./components/MealPlanRecipe";
import MealPool from './components/MealPool';
import AddRecipePage from "./components/AddRecipePage";
import ShoppingListPage from "./components/ShoppingListPage";
import Inventory from "./components/Inventory";
export default class App extends Component {
state = {
init : true,
userId: 0
}
componentDidMount(){
console.disableYellowBox = true;
// console.ignoredYellowBox = ['Warning:'];
AsyncStorage.getItem(TOKEN_KEY)
.then((accessToken)=>{
if(accessToken!=null){
this.userInfoHandler(accessToken);
fetch(API_URL, {
method: 'GET',
headers: {
'Authorization': accessToken
}
}).then((response)=>{
if(response.status=='200'){
this.setState({init:false});
}else{
this.setState({init:true});
}
})
}
}).catch((error)=>{
console.log(`Unable to get token -->${error}`);
});
}
userInfoHandler(accessToken){
return fetch(`${API_URL}/`, {
method: 'GET',
headers: {
'Authorization': accessToken
}
}).then((response)=>{
if(response.status=='200'){
return response.json();
}
}).then((responseData)=>{
this.setState({userId: responseData.userId});
}).catch((error)=>{
console.log(`Error in fetching user id --> ${error}`);
})
}
render(){
return <Router>
<Scene key="root">
<Scene key="login" component={Login} hideNavBar={true} title="Login" initial={this.state.init}/>
<Scene key="signup" component={SignUp} hideNavBar={true} title="SignUp"/>
<Scene key="home" data={this.state.userId} component={Home} hideNavBar={true} title = "My Kitchen Manager" initial={!this.state.init}/>
<Scene key="recipe" component={MealPlanRecipe} hideNavBar={true} title="MealPlanRecipe" />
<Scene key="add_recipe_page" component={AddRecipePage} hideNavBar={true} title="AddRecipePage" />
<Scene key="meal_pool" component={MealPool} hideNavBar={true} title="MealPool"/>
<Scene key="shopping_list_page" component={ShoppingListPage} hideNavBar={true} title="ShoppingList"/>
{/*<Scene key="inventory_page" component={Inventory} hideNavBar={true} title="Inventory"/>*/}
</Scene>
</Router>
}
}