HomeTab.js
5.04 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import React, { Component } from 'react';
import { View, Text, StyleSheet, SafeAreaView, ScrollView, Image } from 'react-native';
import Circle from '../component/circle_component'
import {Table, TableWrapper, Row,Rows} from 'react-native-table-component'
import {get_now_weight, get_today_data, add_data ,get_id} from'../component/DBhelper.js';
var date = new Date();
date.setHours(date.getHours()+9);
var month = date.getMonth()+1;
if(month == 11){
month = 12
}
export default class HomeTab extends Component {
constructor(props){
super(props);
this.state = {
ID : get_id(),
today : date.getFullYear() + "." + month + "." + date.getDate(),
current_weight : get_now_weight() ,
table_contents : get_today_data()
}
}
componentDidMount() {
const { navigation } = this.props;
this.focusListener = navigation.addListener('didFocus', () => {
this.setState({current_weight : get_now_weight(), table_contents : get_today_data()});
});
}
componentWillUnmount() {
this.focusListener.remove();
}
get_diff_data(){
return fetch('http://testloadbalancer-1847561458.ap-northeast-2.elb.amazonaws.com/app/get_diff_data/',{
method:'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body:JSON.stringify({
ras_id : this.state.ID,
date : "1576648647000",
}),
})
.then((response) => response.json())
.then((responseJson)=> {
console.log(responseJson)
add_data(responseJson);
},function(){
})
.then(()=>{this.setState({current_weight : get_now_weight(), table_contents : get_today_data()})})
.catch((error) => {
console.error(error);
})
}
render() {
return (
<View style={style.container}>
<View style={style.header}>
<Text style={style.tabName}>Home</Text>
</View>
<View style={{flexDirection:'row',flex:0.8,backgroundColor: "rgba(230,230,230,0.5)"}}>
<View style={{flex:1,justifyContent:'center'}}>
<Image style={style.img}
source={require("../assets/calendar.jpg")}/>
</View>
<View style={{flex : 8, justifyContent:'center'}}>
<Text style ={style.date_text}>{this.state.today}</Text>
</View>
</View>
<View style={this.state.current_weight}>
<Circle
title={this.state.current_weight/1000}
onPress={()=>{this.get_diff_data()}}>
</Circle>
</View>
<View style={style.waste_detail}>
<SafeAreaView style={style.scroll_container}>
<ScrollView style={style.scroll_page}>
<Text style={style.history}>Today's History</Text>
<Table>
<TableWrapper>
<Row data={['시간', '증감량', '총량']} flexArr={[1, 1, 1]} textStyle={style.row_style1}/>
<Rows data={this.state.table_contents} flexArr={[1, 1, 1]} textStyle={style.row_style2}/>
</TableWrapper>
</Table>
</ScrollView>
</SafeAreaView>
</View>
</View>
);
}
}
const style = StyleSheet.create({
container: {
flex: 1,
},
header: {
flex :1,
justifyContent : 'center',
},
tabName:{
marginStart : 10,
textAlignVertical : 'center',
fontSize : 20,
color : "#0066cc",
fontWeight: 'bold',
},
current_state:{
flex: 5,
backgroundColor: "rgba(230,230,230,0.5)"
},
waste_detail:{
flex :5,
backgroundColor: "rgba(230,230,230,0.5)",
},
date_text:{
fontSize :20,
marginStart:5,
textAlignVertical:'center'
},
scroll_container : {
flex:1,
},
scroll_page:{
margin:20,
borderWidth : 1,
},
history : {
fontSize : 22,
marginBottom : 5,
marginStart : 5
},
content:{
fontSize : 15,
},
wrapper: {
flexDirection: 'row'
},
row_style1:{
textAlign : 'center',
fontSize : 18,
marginBottom : 5,
borderBottomWidth:1,
},
row_style2:{
borderBottomWidth:1,
marginVertical : 2,
fontSize : 15,
textAlign : 'center',
},
img:{
width :20,
resizeMode : 'contain',
alignSelf:'baseline',
marginStart:10,
},
});