Set home as main component, rename list
This commit is contained in:
@@ -1,60 +1,22 @@
|
|||||||
import React, { Component } from 'react'
|
import React, { Component } from 'react'
|
||||||
import {
|
import {
|
||||||
View,
|
View,
|
||||||
Text,
|
Button
|
||||||
Button,
|
|
||||||
TextInput,
|
|
||||||
FlatList
|
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import * as styles from './styles'
|
import * as styles from './styles'
|
||||||
import Datastore from 'react-native-local-mongodb'
|
|
||||||
|
|
||||||
const db = new Datastore({ filename: 'asyncStorageKey', autoload: true })
|
export default class home extends Component {
|
||||||
|
|
||||||
export default class drip extends Component {
|
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
|
||||||
temperatures: []
|
|
||||||
}
|
|
||||||
db.find({ key: { $exists: true } }, (err, persistedTemperatures) => {
|
|
||||||
if (err) throw err
|
|
||||||
this.setState({
|
|
||||||
temperatures: [...persistedTemperatures, ...this.state.temperatures]
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<View style={styles.container}>
|
<View style={styles.container}>
|
||||||
<TextInput
|
|
||||||
placeholder="Enter your temperature"
|
|
||||||
onChangeText={(val) => {
|
|
||||||
this.setState({currentValue: val})
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<Button
|
<Button
|
||||||
onPress={() => {
|
onPress={() => {}}
|
||||||
const newTemp = {
|
title="Home"></Button>
|
||||||
value: this.state.currentValue,
|
|
||||||
key: Date.now().toString()
|
|
||||||
}
|
|
||||||
this.setState({
|
|
||||||
temperatures: [newTemp, ...this.state.temperatures]
|
|
||||||
})
|
|
||||||
db.insert(newTemp, (err) => {
|
|
||||||
if (err) console.log(err)
|
|
||||||
})
|
|
||||||
}}
|
|
||||||
title="Save"
|
|
||||||
/>
|
|
||||||
<FlatList
|
|
||||||
data = {this.state.temperatures}
|
|
||||||
extraData = {this.state}
|
|
||||||
renderItem={({item}) => <Text>{item.value}</Text>}
|
|
||||||
/>
|
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
import React, { Component } from 'react'
|
||||||
|
import {
|
||||||
|
View,
|
||||||
|
Text,
|
||||||
|
Button,
|
||||||
|
TextInput,
|
||||||
|
FlatList
|
||||||
|
} from 'react-native'
|
||||||
|
import * as styles from './styles'
|
||||||
|
import Datastore from 'react-native-local-mongodb'
|
||||||
|
|
||||||
|
const db = new Datastore({ filename: 'asyncStorageKey', autoload: true })
|
||||||
|
|
||||||
|
export default class temp extends Component {
|
||||||
|
constructor(props) {
|
||||||
|
super(props)
|
||||||
|
this.state = {
|
||||||
|
temperatures: []
|
||||||
|
}
|
||||||
|
db.find({ key: { $exists: true } }, (err, persistedTemperatures) => {
|
||||||
|
if (err) throw err
|
||||||
|
this.setState({
|
||||||
|
temperatures: [...persistedTemperatures, ...this.state.temperatures]
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<View style={styles.container}>
|
||||||
|
<TextInput
|
||||||
|
placeholder="Enter your temperature"
|
||||||
|
onChangeText={(val) => {
|
||||||
|
this.setState({currentValue: val})
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
onPress={() => {
|
||||||
|
const newTemp = {
|
||||||
|
value: this.state.currentValue,
|
||||||
|
key: Date.now().toString()
|
||||||
|
}
|
||||||
|
this.setState({
|
||||||
|
temperatures: [newTemp, ...this.state.temperatures]
|
||||||
|
})
|
||||||
|
db.insert(newTemp, (err) => {
|
||||||
|
if (err) console.log(err)
|
||||||
|
})
|
||||||
|
}}
|
||||||
|
title="Save"
|
||||||
|
/>
|
||||||
|
<FlatList
|
||||||
|
data = {this.state.temperatures}
|
||||||
|
extraData = {this.state}
|
||||||
|
renderItem={({item}) => <Text>{item.value}</Text>}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -10,6 +10,6 @@ public class MainActivity extends ReactActivity {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected String getMainComponentName() {
|
protected String getMainComponentName() {
|
||||||
return "drip";
|
return "home";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { AppRegistry } from 'react-native'
|
import { AppRegistry } from 'react-native'
|
||||||
import App from './App'
|
import Home from './App'
|
||||||
|
|
||||||
AppRegistry.registerComponent('drip', () => App)
|
AppRegistry.registerComponent('home', () => Home)
|
||||||
|
|||||||
Generated
+6
-16
@@ -3207,13 +3207,11 @@
|
|||||||
},
|
},
|
||||||
"balanced-match": {
|
"balanced-match": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"brace-expansion": {
|
"brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"balanced-match": "^1.0.0",
|
"balanced-match": "^1.0.0",
|
||||||
"concat-map": "0.0.1"
|
"concat-map": "0.0.1"
|
||||||
@@ -3226,18 +3224,15 @@
|
|||||||
},
|
},
|
||||||
"code-point-at": {
|
"code-point-at": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"concat-map": {
|
"concat-map": {
|
||||||
"version": "0.0.1",
|
"version": "0.0.1",
|
||||||
"bundled": true,
|
"bundled": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"console-control-strings": {
|
"console-control-strings": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
"bundled": true,
|
"bundled": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"core-util-is": {
|
"core-util-is": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
@@ -3340,8 +3335,7 @@
|
|||||||
},
|
},
|
||||||
"inherits": {
|
"inherits": {
|
||||||
"version": "2.0.3",
|
"version": "2.0.3",
|
||||||
"bundled": true,
|
"bundled": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"ini": {
|
"ini": {
|
||||||
"version": "1.3.5",
|
"version": "1.3.5",
|
||||||
@@ -3351,7 +3345,6 @@
|
|||||||
"is-fullwidth-code-point": {
|
"is-fullwidth-code-point": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"number-is-nan": "^1.0.0"
|
"number-is-nan": "^1.0.0"
|
||||||
}
|
}
|
||||||
@@ -3364,7 +3357,6 @@
|
|||||||
"minimatch": {
|
"minimatch": {
|
||||||
"version": "3.0.4",
|
"version": "3.0.4",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"brace-expansion": "^1.1.7"
|
"brace-expansion": "^1.1.7"
|
||||||
}
|
}
|
||||||
@@ -3464,8 +3456,7 @@
|
|||||||
},
|
},
|
||||||
"number-is-nan": {
|
"number-is-nan": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"bundled": true,
|
"bundled": true
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"object-assign": {
|
"object-assign": {
|
||||||
"version": "4.1.1",
|
"version": "4.1.1",
|
||||||
@@ -3580,7 +3571,6 @@
|
|||||||
"string-width": {
|
"string-width": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"bundled": true,
|
"bundled": true,
|
||||||
"optional": true,
|
|
||||||
"requires": {
|
"requires": {
|
||||||
"code-point-at": "^1.0.0",
|
"code-point-at": "^1.0.0",
|
||||||
"is-fullwidth-code-point": "^1.0.0",
|
"is-fullwidth-code-point": "^1.0.0",
|
||||||
|
|||||||
Reference in New Issue
Block a user