이윤영

Add DBHelper.js

......@@ -26,7 +26,8 @@
"react-navigation": "^4.0.10",
"react-navigation-drawer": "^2.3.3",
"react-navigation-stack": "^1.10.3",
"react-navigation-tabs": "^2.5.6"
"react-navigation-tabs": "^2.5.6",
"realm": "^3.6.0"
},
"devDependencies": {
"@babel/core": "^7.7.2",
......
......@@ -104,6 +104,9 @@ export default class HomeTab extends Component {
/>
}
>
<View style={style.header}>
<Text style={style.tabName}>History </Text>
</View>
<Text>{this.state.title}</Text>
<SegmentedControlTab
values={["Week", "Month", "Year"]}
......@@ -121,5 +124,16 @@ const style = StyleSheet.create({
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
header: {
flex :1,
justifyContent : 'center',
},
tabName:{
marginStart : 10,
textAlignVertical : 'center',
fontSize : 20,
color : "#0066cc",
fontWeight: 'bold',
}
})
\ No newline at end of file
......
import React, { Component } from 'react';
import { View, Text, StyleSheet, SafeAreaView, ScrollView, Image } from 'react-native';
import WasteDetail from '../WasteDetail'
import Circle from '../component/circle_component'
import {Table, TableWrapper, Row,Rows} from 'react-native-table-component'
import {get_now_weight} from'../component/DBhelper.js';
var date = new Date();
date.setHours(date.getHours()+9);
var month = date.getMonth()+1;
......@@ -16,7 +17,7 @@ export default class HomeTab extends Component {
this.state = {
ID : this.props.navigation.getParam('id','pi1'),
today : date.getFullYear() + "." + month + "." + date.getDate(),
current_weight : 0,
current_weight : get_now_weight() ,
table_contents : [['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','4:27:52', '+0.12kg', 'Total : 1.38kg'],
['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],
['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],['오후','6:12:15', '+0.25kg', 'Total : 1.5 kg'],
......@@ -63,9 +64,9 @@ export default class HomeTab extends Component {
<Text style ={style.date_text}>{this.state.today}</Text>
</View>
</View>
<View style={style.current_state}>
<View style={this.state.current_weight}>
<Circle
title={"3.6"}
title={this.state.current_weight}
onPress={()=>{this.get_diff_data()}}>
</Circle>
</View>
......
import React, { Component } from 'react';
import { StyleSheet, Text, View, TextInput, Image} from 'react-native';
import LoginButton from './component/LoginButton';
import {add_data} from'./component/DBhelper.js';
export default class Login extends Component {
......@@ -8,30 +9,24 @@ export default class Login extends Component {
super(props);
this.state = {
ID: '',
};
}
}
static navigationOptions = {
title: 'Login',
};
/*handlePress = async () => {
fetch('http://localhost:3000/app/get_data/'+this.state.ID, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
})
.then((response) => response.json())
.then((responseJson) => {
Alert.alert("Author name at 0th index: " + responseJson[0].name);
})
.catch((error) => {
console.error(error);
});
}
*/
getdata() {
return fetch('http://10.0.2.2:3000/app/get_data/uid1')
.then((response) => response.json())
.then((responseJson) => {
// alert(responseJson[0].ras_id.S);
//alert(responseJson.length)
add_data(responseJson);
})
.catch((error) => {
console.error(error);
});
}
render() {
return (
......@@ -60,7 +55,8 @@ export default class Login extends Component {
onChangeText={(text) => {this.setState({ID:text})}}
/>
<LoginButton
onPress={() =>{ this.props.navigation.navigate('MainScreen', { ID: this.state.ID }) }}
// onPress={()=>getdata}
onPress={() =>{ this.getdata().then(this.props.navigation.navigate('MainScreen', { ID: this.state.ID })) }}
/>
</View>
</View>
......
import React, { Component } from 'react';
import { View, Text, StyleSheet } from 'react-native';
export default class HomeTab extends Component {
render() {
return (
<View style={style.container}>
<Text> 3.8kg 추가</Text>
</View>
);
}
}
const style = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "rgba(230,230,230,0.5)"
}
});
// Define your models and their properties
import Realm from 'realm'
class Waste {}
Waste.schema = {
name: 'Waste',
properties: {
weight: 'int',
diff: 'int',
date: 'float',
}
};
// Get the default Realm with support for our objects
let realm = new Realm({schema: [Waste]});
// // Create Realm objects and write to local storage
// realm.write(() => {
// let myWaste = realm.create('Waste', {
// weight: 1655,
// diff: 500,
// date: '1576236841329.253',
// });
// // myWaste.miles += 2SS0; // Update a property value
// });
// // Query Realm for all cars with a high mileage
// let wastes = realm.objects('Waste').filtered('weight > 1000');
// // Will return a Results object with our 1 car
// cars.length // => 1
// // Add another car
// realm.write(() => {
// let myCar = realm.create('Car', {
// make: 'Ford',
// model: 'Focus',
// miles: 2000,
// });
// });
// // Query results are updated in realtime
// cars.length // => 2
export function add_data(responseJson){
for(i = 0; i < responseJson.length; i++){
realm.write(() => {
// responseJson[0].ras_id.S
let myWaste = realm.create('Waste', {
weight: Number(responseJson[i].weight.N),
diff: Number(responseJson[i].diff.N),
date: Number(responseJson[i].save_date.S),
});
});
}
return responseJson.length;
}
export function get_now_weight(){
let wastes = realm.objects('Waste');
let recent = realm.objects('Waste').max('date').date;
let recentWeight = wastes.filtered('date = 1576223063238.5166');
return recentWeight[0].weight;
// return "3.8"
}
export function get_recent_date(){
return realm.objects('Waste').max("date");
}
\ No newline at end of file
This diff is collapsed. Click to expand it.