diff --git a/App.js b/App.js index c93b50d..5ae1c7e 100644 --- a/App.js +++ b/App.js @@ -25,6 +25,7 @@ import AddDevice from './src/screens/AddDevice'; import ScanDevice from './src/screens/ScanDevice'; import UserDevices from './src/screens/UserDevices'; import UserDetailDevice from './src/screens/UserDetailDevice'; +import Measurement from './src/screens/Measurement'; import Logout from './src/screens/Logout'; import { Provider } from 'react-redux'; import store from './src/store'; @@ -154,6 +155,7 @@ const RootStack = SwitchNavigator( screen: UserAccess }, Home: { + // screen: Drawer screen: Drawer } }, diff --git a/src/components/ListUserDeviceHome.js b/src/components/ListUserDeviceHome.js new file mode 100644 index 0000000..4f3368b --- /dev/null +++ b/src/components/ListUserDeviceHome.js @@ -0,0 +1,94 @@ +import React, { Component } from 'react'; +import { + StyleSheet, + View, + Button, + ToastAndroid, + Text, + TouchableHighlight, + Image +} from 'react-native' +import { DrawerNavigator, StackNavigator } from 'react-navigation'; +import moment from 'moment' + +class ListUserDeviceHome extends Component { + + viewDetailDevices = (deviceId) => { + const { navigation } = this.props + navigation.navigate('detailDevice', {deviceId: deviceId}) + } + + render() { + const { item } = this.props + return ( + + { this.viewDetailDevices(item.id) }} + underlayColor="rgba(255,255,255,0.2)"> + + + + + + + Device Name: + + + {item.name} + + + + Active: + + + {" "+moment(item.updatedAt).fromNow()} + + + + + + + ); + } +} + +const styles = StyleSheet.create({ + button: { + // alignItems: 'center', + backgroundColor: '#0098a7', + paddingVertical: 10, + paddingHorizontal: 20, + margin: 10, + width: 300, + color: 'white', + borderRadius: 50, + }, + innerText: { + color: 'white', + fontSize: 25, + fontWeight: '500' + }, + innerTextSmall: { + color: 'white', + fontSize: 15, + fontWeight: '200' + }, + innerTextSmallBold: { + color: 'white', + fontSize: 15, + fontWeight: '600' + }, + image: { + height: 70, + // borderRadius: 50, + width: 70, + marginRight: 20 + }, + wrapper: { + flexDirection: 'row' + } + +}) + +export default ListUserDeviceHome; \ No newline at end of file diff --git a/src/screens/Home.js b/src/screens/Home.js index 0b0a2ef..6cd1477 100644 --- a/src/screens/Home.js +++ b/src/screens/Home.js @@ -1,5 +1,5 @@ import React, { Component } from 'react'; -import { View, Text, StyleSheet, Button, ToastAndroid, PermissionsAndroid, TouchableHighlight, Image} from 'react-native'; +import { View, Text, StyleSheet, Button, ToastAndroid, PermissionsAndroid, TouchableHighlight, Image, FlatList} from 'react-native'; import { bindActionCreators } from 'redux'; import { connect } from 'react-redux'; @@ -11,6 +11,8 @@ import ScanDevice from './ScanDevice'; import AddDevice from './AddDevice'; import Maps from '../components/Maps'; import HamburgerButton from '../components/HamburgerButton'; +import ListUserDeviceHome from '../components/ListUserDeviceHome'; +import Modal from "react-native-modal"; import { loadRegisteredDevices, updateDeviceLocation, LoadTreki, GetLocation } from '../store/treki/treki.action'; import { updateTokenDevice } from '../store/user/user.action'; import { NotificationsAndroid } from 'react-native-notifications'; @@ -47,10 +49,20 @@ class Home extends Component { latitude: 0, longitude: 0, accuracy: 0 - } + }, + isVisible: false, + user_id: '' } } + renderItem = ({item}) => { + return ( + + ) + } + + keyExtractor = (item, index) => `userdevices-${index}` + componentWillMount = async () => { await this.props.LoadTreki(this.setCoordinate); } @@ -96,9 +108,26 @@ class Home extends Component { - + { + this.setState({isVisible: true}) + }}> + {/* */} + + + + + this.setState({isVisible: false})}> + Hide me! + + + ); } @@ -123,7 +152,21 @@ const styles = StyleSheet.create({ borderWidth: 5, borderColor: '#0098a7', borderRadius: 30 - } + }, + modal: { + backgroundColor: 'white', + borderRadius: 10, + width: 300, + height: 400 + }, + modalWrapper: { + alignItems: 'center', + justifyContent: 'center', + flex: 1 + }, + flatList: { + alignItems: 'center' + }, }) const mapStateToProps = (state) => { diff --git a/src/screens/Measurement.js b/src/screens/Measurement.js new file mode 100644 index 0000000..28ede6d --- /dev/null +++ b/src/screens/Measurement.js @@ -0,0 +1,65 @@ +import React, { Component } from 'react' +import { Text, View, StyleSheet } from 'react-native' + +export default class componentName extends Component { + render() { + return ( + + + + + Handphone + 15.00 m + + + + + ) + } +} + +const style = StyleSheet.create({ + outer: { + backgroundColor: '#004e54', + alignItems: 'center', + justifyContent: 'center', + flex: 1 + }, + outer2: { + backgroundColor: '#006971', + alignItems: 'center', + justifyContent: 'center', + width: 600, + height: 600, + borderRadius: 300 + }, + outer3: { + backgroundColor: '#0098a7', + alignItems: 'center', + justifyContent: 'center', + width: 450, + height: 450, + borderRadius: 225 + }, + outer4: { + backgroundColor: '#00afc4', + alignItems: 'center', + justifyContent: 'center', + width: 300, + height: 300, + borderRadius: 150 + }, + title: { + color: 'white', + fontSize: 40, + borderBottomWidth: 3, + borderBottomColor: 'white', + paddingBottom: 7 + }, + distance: { + color: 'white', + fontSize: 70, + fontWeight: '600', + paddingTop: 7 + } +}) \ No newline at end of file diff --git a/src/screens/UserDetailDevice.js b/src/screens/UserDetailDevice.js index d6339fc..d61c158 100644 --- a/src/screens/UserDetailDevice.js +++ b/src/screens/UserDetailDevice.js @@ -11,6 +11,7 @@ import { import { connect } from 'react-redux'; import { bindActionCreators } from 'redux'; import { getUserDetailDevice } from '../store/devices/devices.action'; +import { updateState } from '../store/treki/treki.action' class UserDetailDevice extends Component { static navigationOptions = { @@ -25,14 +26,34 @@ class UserDetailDevice extends Component { constructor () { super() this.state = { - notif: false + notif: false, + detail: { + device_id: '', + name: '', + location: null, + createdAt: null, + updatedAt: null, + state: false + } } } - componentDidMount () { + updateData () { const { deviceId } = this.props.navigation.state.params - ToastAndroid.show(`${deviceId}`, ToastAndroid.SHORT) this.props.getUserDetailDevice(deviceId) + .then((detail) => { + console.warn(detail.data.data) + this.setState({ + detail: detail.data.data + }) + }) + } + + componentDidMount () { + // console.warn("deviceID", deviceId) + // let detail = this.props.userDevices.filter(val => val.id === deviceId); + // console.warn('detail', detail) + this.updateData(); } render() { @@ -43,14 +64,20 @@ class UserDetailDevice extends Component { Device ID - FE:JE:JK:34:32 + {this.state.detail.device_id} Name - Handphone + {this.state.detail.name} Notification - this.setState({notif: value})} value={ this.state.notif } onTintColor='#00afc4' thumbTintColor='white'/> + { + this.props.updateState(value) + .then(() => { + console.warn("UPDATE") + this.updateData(); + }) + }} value={ this.state.detail.state } onTintColor='#00afc4' thumbTintColor='white'/> Location @@ -94,8 +121,13 @@ const style = StyleSheet.create({ }) const mapDispatchToProps = (dispatch) => bindActionCreators({ - getUserDetailDevice + getUserDetailDevice, + updateState }, dispatch) -export default connect(null, mapDispatchToProps)(UserDetailDevice); +const mapStateToProps = (state) => ({ + userDevices: state.devicesReducer.userDevices, +}) + +export default connect(mapStateToProps, mapDispatchToProps)(UserDetailDevice); diff --git a/src/store/devices/devices.action.js b/src/store/devices/devices.action.js index ecc86c9..617da85 100644 --- a/src/store/devices/devices.action.js +++ b/src/store/devices/devices.action.js @@ -44,13 +44,9 @@ export const getUserDevices = (id) => { export const getUserDetailDevice = (id) => { return (dispatch) => { - axios({ + return axios({ method: `GET`, url: `http://treki.fadhilmch.com/treki/${id}`, }) - .then((resp) => { - console.warn(`=====> DATA DETAIL ${JSON.stringify(resp.data.data)}`) - // dispatch() - }) } } \ No newline at end of file diff --git a/src/store/treki/treki.action.js b/src/store/treki/treki.action.js index 2896250..c8bd9e3 100644 --- a/src/store/treki/treki.action.js +++ b/src/store/treki/treki.action.js @@ -101,6 +101,19 @@ export const saveNewDevice = (payload) => { } } +export const updateState = (payload) => { + return (dispatch) => { + console.warn('updatestate') + return axios({ + method: `PUT`, + url: `http://treki.fadhilmch.com/treki/${payload.id}/state`, + data: { + state: payload.state + } + }) + } +} + export const updateDeviceLocation = (payload) => { return (dispatch) => { axios({