Showing
5 changed files
with
19 additions
and
48 deletions
... | @@ -2,7 +2,7 @@ import React, { Component } from 'react'; | ... | @@ -2,7 +2,7 @@ import React, { Component } from 'react'; |
2 | import { View, Text, StyleSheet,ScrollView, RefreshControl } from 'react-native'; | 2 | import { View, Text, StyleSheet,ScrollView, RefreshControl } from 'react-native'; |
3 | import HistoryGraph from '../component/HistoryGraph' | 3 | import HistoryGraph from '../component/HistoryGraph' |
4 | import SegmentedControlTab from "react-native-segmented-control-tab"; | 4 | import SegmentedControlTab from "react-native-segmented-control-tab"; |
5 | -import {get_id,add_data, get_week_data, get_month_data, get_year_data, add_temp_data} from'../component/DBhelper.js'; | 5 | +import {get_id, add_data, get_week_data, get_month_data, get_year_data} from'../component/DBhelper.js'; |
6 | 6 | ||
7 | //var today = new Date(); | 7 | //var today = new Date(); |
8 | //today.setHours(today.getHours()+9); | 8 | //today.setHours(today.getHours()+9); |
... | @@ -41,7 +41,6 @@ export default class HomeTab extends Component { | ... | @@ -41,7 +41,6 @@ export default class HomeTab extends Component { |
41 | } | 41 | } |
42 | 42 | ||
43 | componentWillUnmount() { | 43 | componentWillUnmount() { |
44 | - // Remove the event listener | ||
45 | this.focusListener.remove(); | 44 | this.focusListener.remove(); |
46 | } | 45 | } |
47 | 46 | ||
... | @@ -75,8 +74,7 @@ export default class HomeTab extends Component { | ... | @@ -75,8 +74,7 @@ export default class HomeTab extends Component { |
75 | .then((response) => response.json()) | 74 | .then((response) => response.json()) |
76 | .then((responseJson)=> { | 75 | .then((responseJson)=> { |
77 | console.log(responseJson) | 76 | console.log(responseJson) |
78 | - //add_data(responseJson) | 77 | + add_data(responseJson) |
79 | - add_temp_data(); | ||
80 | },function(){ | 78 | },function(){ |
81 | }) | 79 | }) |
82 | .then(()=>{this.handleIndexChange(this.state.selectedIndex)}) | 80 | .then(()=>{this.handleIndexChange(this.state.selectedIndex)}) | ... | ... |
... | @@ -2,7 +2,7 @@ import React, { Component } from 'react'; | ... | @@ -2,7 +2,7 @@ import React, { Component } from 'react'; |
2 | import { View, Text, StyleSheet, SafeAreaView, ScrollView, Image } from 'react-native'; | 2 | import { View, Text, StyleSheet, SafeAreaView, ScrollView, Image } from 'react-native'; |
3 | import Circle from '../component/circle_component' | 3 | import Circle from '../component/circle_component' |
4 | import {Table, TableWrapper, Row,Rows} from 'react-native-table-component' | 4 | import {Table, TableWrapper, Row,Rows} from 'react-native-table-component' |
5 | -import {get_now_weight, get_today_data, add_data,add_temp_data,get_id} from'../component/DBhelper.js'; | 5 | +import {get_now_weight, get_today_data, add_data ,get_id} from'../component/DBhelper.js'; |
6 | 6 | ||
7 | var date = new Date(); | 7 | var date = new Date(); |
8 | date.setHours(date.getHours()+9); | 8 | date.setHours(date.getHours()+9); |
... | @@ -24,16 +24,12 @@ export default class HomeTab extends Component { | ... | @@ -24,16 +24,12 @@ export default class HomeTab extends Component { |
24 | componentDidMount() { | 24 | componentDidMount() { |
25 | const { navigation } = this.props; | 25 | const { navigation } = this.props; |
26 | this.focusListener = navigation.addListener('didFocus', () => { | 26 | this.focusListener = navigation.addListener('didFocus', () => { |
27 | - this.setState({ | 27 | + this.setState({current_weight : get_now_weight(), table_contents : get_today_data()}); |
28 | - current_weight : get_now_weight(), | ||
29 | - table_contents : get_today_data() | ||
30 | - }); | ||
31 | }); | 28 | }); |
32 | } | 29 | } |
33 | 30 | ||
34 | componentWillUnmount() { | 31 | componentWillUnmount() { |
35 | - // Remove the event listener | 32 | + this.focusListener.remove(); |
36 | - this.focusListener.remove(); | ||
37 | } | 33 | } |
38 | 34 | ||
39 | get_diff_data(){ | 35 | get_diff_data(){ |
... | @@ -51,14 +47,10 @@ export default class HomeTab extends Component { | ... | @@ -51,14 +47,10 @@ export default class HomeTab extends Component { |
51 | .then((response) => response.json()) | 47 | .then((response) => response.json()) |
52 | .then((responseJson)=> { | 48 | .then((responseJson)=> { |
53 | console.log(responseJson) | 49 | console.log(responseJson) |
54 | - //add_data(responseJson); | 50 | + add_data(responseJson); |
55 | - add_temp_data(); | ||
56 | },function(){ | 51 | },function(){ |
57 | }) | 52 | }) |
58 | - .then(()=>{this.setState({ | 53 | + .then(()=>{this.setState({current_weight : get_now_weight(), table_contents : get_today_data()})}) |
59 | - current_weight : get_now_weight(), | ||
60 | - table_contents : get_today_data() | ||
61 | - })}) | ||
62 | .catch((error) => { | 54 | .catch((error) => { |
63 | console.error(error); | 55 | console.error(error); |
64 | }) | 56 | }) | ... | ... |
... | @@ -17,7 +17,7 @@ export default class SettingTab extends Component { | ... | @@ -17,7 +17,7 @@ export default class SettingTab extends Component { |
17 | } | 17 | } |
18 | 18 | ||
19 | save_app_data(){ | 19 | save_app_data(){ |
20 | - return fetch('http://10.0.2.2:3000/app/save_data/',{ | 20 | + return fetch('http://testloadbalancer-1847561458.ap-northeast-2.elb.amazonaws.com/app/save_data/',{ |
21 | method:'POST', | 21 | method:'POST', |
22 | headers: { | 22 | headers: { |
23 | 'Accept': 'application/json', | 23 | 'Accept': 'application/json', | ... | ... |
... | @@ -67,23 +67,6 @@ export function add_data(responseJson){ | ... | @@ -67,23 +67,6 @@ export function add_data(responseJson){ |
67 | return responseJson.length; | 67 | return responseJson.length; |
68 | } | 68 | } |
69 | 69 | ||
70 | -export function add_temp_data(){ | ||
71 | - realm.write(() => { | ||
72 | - let myWaste = realm.create('Waste', { | ||
73 | - weight: parseFloat(747), | ||
74 | - diff: parseFloat(257), | ||
75 | - date: parseFloat(1576691588000), | ||
76 | - }); | ||
77 | - }); | ||
78 | - realm.write(() => { | ||
79 | - let myWaste = realm.create('Waste', { | ||
80 | - weight: parseFloat(1466), | ||
81 | - diff: parseFloat(468), | ||
82 | - date: parseFloat(1576650859000), | ||
83 | - }); | ||
84 | - }); | ||
85 | -} | ||
86 | - | ||
87 | export function get_now_weight(){ | 70 | export function get_now_weight(){ |
88 | let wastes = realm.objects('Waste'); | 71 | let wastes = realm.objects('Waste'); |
89 | let recent = wastes.max('date'); | 72 | let recent = wastes.max('date'); |
... | @@ -92,7 +75,8 @@ export function get_now_weight(){ | ... | @@ -92,7 +75,8 @@ export function get_now_weight(){ |
92 | console.log("now_weight",recentWeight) | 75 | console.log("now_weight",recentWeight) |
93 | if(recentWeight.length != 0) | 76 | if(recentWeight.length != 0) |
94 | return recentWeight[recentWeight.length-1].weight; | 77 | return recentWeight[recentWeight.length-1].weight; |
95 | - else return 0; | 78 | + else |
79 | + return 0; | ||
96 | } | 80 | } |
97 | 81 | ||
98 | export function get_last_update(){ | 82 | export function get_last_update(){ |
... | @@ -107,18 +91,6 @@ export function get_recent_date(){ | ... | @@ -107,18 +91,6 @@ export function get_recent_date(){ |
107 | return realm.objects('Waste').max("date"); | 91 | return realm.objects('Waste').max("date"); |
108 | } | 92 | } |
109 | 93 | ||
110 | -// export function get_today_data(today){ | ||
111 | -// let wastes = realm.objects('Waste'); | ||
112 | -// var list = []; | ||
113 | -// for(var i =0; i<wastes.length; i++){ | ||
114 | -// if(get_date(wastes[i].date) == get_date(today)){ | ||
115 | -// temp = [waste[i].date, waste[i].diff, waste[i].weight] | ||
116 | -// list.append(temp); | ||
117 | -// } | ||
118 | -// } | ||
119 | -// return list; | ||
120 | -// } | ||
121 | - | ||
122 | export function get_today_data(){ | 94 | export function get_today_data(){ |
123 | var today_start = get_today_start(); | 95 | var today_start = get_today_start(); |
124 | console.log("today_start: ",today_start) | 96 | console.log("today_start: ",today_start) | ... | ... |
... | @@ -18,6 +18,15 @@ export default class LoginButton extends Component { | ... | @@ -18,6 +18,15 @@ export default class LoginButton extends Component { |
18 | onPress: () => null, | 18 | onPress: () => null, |
19 | } | 19 | } |
20 | 20 | ||
21 | + componentDidUpdate(prevProps, prevState){ | ||
22 | + if (this.props.data !== prevProps.data) { | ||
23 | + this.setState({ | ||
24 | + ...this.state, | ||
25 | + title: this.props.data.current_weight | ||
26 | + }) | ||
27 | + } | ||
28 | + } | ||
29 | + | ||
21 | render() { | 30 | render() { |
22 | return ( | 31 | return ( |
23 | <TouchableOpacity | 32 | <TouchableOpacity | ... | ... |
-
Please register or login to post a comment