SettingTab.js
4.39 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
import React, { Component } from 'react';
import { View, Text, StyleSheet, TextInput, TouchableOpacity, Image } from 'react-native';
import AddButton from '../component/AddButton'
var date = new Date();
date.setHours(date.getHours()+9);
date.setMonth(date.getMonth()+1);
export default class SettingTab extends Component {
constructor(props){
super(props);
this.state = {
ID : 'pi1',
user : 'user1'
}
}
save_app_data(){
return fetch('http://10.0.2.2:3000/app/save_data/',{
method:'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
body:JSON.stringify({
ras_id : this.state.ID,
user_id : this.state.user,
}),
})
.then((response) => console.log(response.json()))
.then((responseJson)=> {
console.log(responseJson)
},function(){
})
.catch((error) => {
console.error(error);
})
}
delete_id(){
this.setState({ID: ''})
//기기연결 해제, 디비비우기
}
render() {
return (
<View style={style.container}>
<View style={style.header}>
<Text style={style.tabName}>Setting</Text>
</View>
<View style={style.content}>
<View style={style.id}>
<Text style={{marginStart:5, marginBottom: 10, fontSize : 15}}>Lasberry PI ID</Text>
<View style={{backgroundColor:'white', height:40,width:'100%',flexDirection:'row', justifyContent:'center', alignItems:'center'}}>
<View style={{flex:8}}>
<Text style={{marginStart:10, fontSize : 15}}>{this.state.ID}</Text>
</View>
<View style={{flex:1}}>
<Image style={style.img}
source={require('../assets/check.jpg')}/>
</View>
</View>
<TouchableOpacity
onPress={()=>this.delete_id()}>
<View style={{backgroundColor:"#0066cc", height:40,width:'100%',flexDirection:'row', justifyContent:'center', alignItems:'center', marginTop:5,}}>
<View style={{flex:8}}>
<Text style={{marginStart:10, fontSize : 15, textAlign:'center'}}>Delete</Text>
</View>
</View>
</TouchableOpacity>
</View>
<View style={style.device}>
<View style={{backgroundColor:'white', height:40,width:'100%',flexDirection:'row', justifyContent:'center', alignItems:'center'}}>
<Text style={{marginStart:10, fontSize : 15}}>Connect New Device</Text>
</View>
<View style={{backgroundColor:'white', height:40,width:'100%', alignItems:'center', marginTop:5}}>
<TextInput style={{marginStart:10}}
placeholder="New Rasberry ID"
value={this.state.text}
onChangeText={(text)=>this.setState({ID:text})}/>
</View>
<AddButton
onPress={()=>{this.save_app_data()}}/>
</View>
</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',
},
content:{
flex : 8.8,
backgroundColor:"rgba(230,230,230,0.5)",
justifyContent : 'center',
padding : 20,
},
blank :{
flex:3,
},
id:{
alignSelf:'center',
width:'100%',
justifyContent:'center',
flex:1,
},
device:{
flex : 1,
},
blank :{
flex:3,
},
img:{
width : 30,
resizeMode : 'contain',
}
});