유희정

login check

......@@ -5,6 +5,7 @@ import { createStackNavigator } from 'react-navigation-stack'
// import MainScreen from './components/MainScreen';
import Login from './source/Login';
import MainScreen from './source/MainScreen';
import {getId} from './source/component/DBhelper'
// const AppStackNavigator = createStackNavigator({
// Main:{
......@@ -14,11 +15,18 @@ import MainScreen from './source/MainScreen';
// export default createAppContainer(AppStackNavigator);
var initialName = ''
if(getId() == true){
initialName = 'MainScreen'
}
else initialName = 'Login'
const MainNavigator = createStackNavigator({
Login : {screen: Login},
MainScreen : {screen:MainScreen},
},
{initialRouteName: 'Login',headerMode:'none'}
{initialRouteName: initialName,headerMode:'none'}
);
const App = createAppContainer(MainNavigator);
......
import React, { Component } from 'react';
import { View, Text, StyleSheet, TextInput, TouchableOpacity, Image } from 'react-native';
import AddButton from '../component/AddButton'
import {delete_all_data} from '../component/DBhelper'
import {delete_all_data, deleteId} from '../component/DBhelper'
var date = new Date();
date.setHours(date.getHours()+9);
......@@ -40,7 +40,9 @@ export default class SettingTab extends Component {
delete_id(){
this.setState({ID: ''})
//save_app_data()
delete_all_data()
//delete_all_data()
deleteId()
this.props.navigation.navigate('Login');
}
render() {
return (
......
......@@ -5,6 +5,7 @@ import { createMaterialTopTabNavigator } from 'react-navigation-tabs'
import HomeTab from './AppTabNavigator/HomeTab'
import HistoryTab from './AppTabNavigator/HistoryTab'
import SettingTab from './AppTabNavigator/SettingTab'
import {registerID} from '../source/component/DBhelper'
// 하단 탭 네비게이터 생성
const AppTabNavigator = createMaterialTopTabNavigator({
......@@ -39,14 +40,14 @@ export default class MainScreen extends Component {
constructor(props) {
super(props);
this.state = {
ID: this.props.navigation.getParam('ID'),
ID: this.props.navigation.getParam('ID',''),
};
}
static navigationOptions = {
title: 'FW IOT' }
render() {
//registerID(this.state.ID);
return <AppTabContainet/>; // AppTabContainet 컴포넌트를 리턴한다.
}
}
......
......@@ -11,9 +11,41 @@ Waste.schema = {
}
};
// Get the default Realm with support for our objects
let realm = new Realm({schema: [Waste]});
class ID {}
ID.schema={
name:'ID',
properties:{
id : 'string',
}
};
export function registerID(_id){
if(_id != ''){
realm.write(()=>{
let user = realm.create('ID',{id:_id});
console.log('success')
});
}
}
export function getId(){
let user = realm.objects('ID');
console.log(user.length);
if(user.length>0)
return true;
return false;
}
export function deleteId(){
let user = realm.objects('ID');
realm.write(()=>{
realm.delete(user);
console.log('success')
})
}
// Get the default Realm with support for our objects
let realm = new Realm({schema: [Waste, ID]});
export function add_data(responseJson){
for(i = 0; i < responseJson.length; i++){
realm.write(() => {
......@@ -36,7 +68,9 @@ export function get_now_weight(){
var recentWeight = wastes.filtered('date = $0', recent);
console.log("now_weight",recentWeight)
if(recentWeight.length != 0)
return recentWeight[0].weight;
else return 0;
}
export function get_last_update(){
......