이윤영

Delete test function

......@@ -2,7 +2,7 @@ import React, { Component } from 'react';
import { View, Text, StyleSheet,ScrollView, RefreshControl } from 'react-native';
import HistoryGraph from '../component/HistoryGraph'
import SegmentedControlTab from "react-native-segmented-control-tab";
import {get_id,add_data, get_week_data, get_month_data, get_year_data, add_temp_data} from'../component/DBhelper.js';
import {get_id, add_data, get_week_data, get_month_data, get_year_data} from'../component/DBhelper.js';
//var today = new Date();
//today.setHours(today.getHours()+9);
......@@ -41,7 +41,6 @@ export default class HomeTab extends Component {
}
componentWillUnmount() {
// Remove the event listener
this.focusListener.remove();
}
......@@ -75,8 +74,7 @@ export default class HomeTab extends Component {
.then((response) => response.json())
.then((responseJson)=> {
console.log(responseJson)
//add_data(responseJson)
add_temp_data();
add_data(responseJson)
},function(){
})
.then(()=>{this.handleIndexChange(this.state.selectedIndex)})
......
......@@ -2,7 +2,7 @@ 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,add_temp_data,get_id} from'../component/DBhelper.js';
import {get_now_weight, get_today_data, add_data ,get_id} from'../component/DBhelper.js';
var date = new Date();
date.setHours(date.getHours()+9);
......@@ -24,16 +24,12 @@ export default class HomeTab extends Component {
componentDidMount() {
const { navigation } = this.props;
this.focusListener = navigation.addListener('didFocus', () => {
this.setState({
current_weight : get_now_weight(),
table_contents : get_today_data()
});
this.setState({current_weight : get_now_weight(), table_contents : get_today_data()});
});
}
componentWillUnmount() {
// Remove the event listener
this.focusListener.remove();
this.focusListener.remove();
}
get_diff_data(){
......@@ -51,14 +47,10 @@ export default class HomeTab extends Component {
.then((response) => response.json())
.then((responseJson)=> {
console.log(responseJson)
//add_data(responseJson);
add_temp_data();
add_data(responseJson);
},function(){
})
.then(()=>{this.setState({
current_weight : get_now_weight(),
table_contents : get_today_data()
})})
.then(()=>{this.setState({current_weight : get_now_weight(), table_contents : get_today_data()})})
.catch((error) => {
console.error(error);
})
......
......@@ -17,7 +17,7 @@ export default class SettingTab extends Component {
}
save_app_data(){
return fetch('http://10.0.2.2:3000/app/save_data/',{
return fetch('http://testloadbalancer-1847561458.ap-northeast-2.elb.amazonaws.com/app/save_data/',{
method:'POST',
headers: {
'Accept': 'application/json',
......
......@@ -67,23 +67,6 @@ export function add_data(responseJson){
return responseJson.length;
}
export function add_temp_data(){
realm.write(() => {
let myWaste = realm.create('Waste', {
weight: parseFloat(747),
diff: parseFloat(257),
date: parseFloat(1576691588000),
});
});
realm.write(() => {
let myWaste = realm.create('Waste', {
weight: parseFloat(1466),
diff: parseFloat(468),
date: parseFloat(1576650859000),
});
});
}
export function get_now_weight(){
let wastes = realm.objects('Waste');
let recent = wastes.max('date');
......@@ -92,7 +75,8 @@ export function get_now_weight(){
console.log("now_weight",recentWeight)
if(recentWeight.length != 0)
return recentWeight[recentWeight.length-1].weight;
else return 0;
else
return 0;
}
export function get_last_update(){
......@@ -107,18 +91,6 @@ export function get_recent_date(){
return realm.objects('Waste').max("date");
}
// export function get_today_data(today){
// let wastes = realm.objects('Waste');
// var list = [];
// for(var i =0; i<wastes.length; i++){
// if(get_date(wastes[i].date) == get_date(today)){
// temp = [waste[i].date, waste[i].diff, waste[i].weight]
// list.append(temp);
// }
// }
// return list;
// }
export function get_today_data(){
var today_start = get_today_start();
console.log("today_start: ",today_start)
......
......@@ -18,6 +18,15 @@ export default class LoginButton extends Component {
onPress: () => null,
}
componentDidUpdate(prevProps, prevState){
if (this.props.data !== prevProps.data) {
this.setState({
...this.state,
title: this.props.data.current_weight
})
}
}
render() {
return (
<TouchableOpacity
......