diff --git a/src/UserAccountPanel.js b/src/UserAccountPanel.js index 3393f4a..3587688 100644 --- a/src/UserAccountPanel.js +++ b/src/UserAccountPanel.js @@ -7,21 +7,103 @@ import React from 'react'; import { AppRegistry, StyleSheet, - Text, View, + NativeModules, + Alert, + Image, + TextInput, + Button, + Text, } from 'react-native'; class UserAccountPanel extends React.Component { + constructor(props) { + super(props); + this.state = { + userName: "", + userEmail: "", + isEditing: false, + } + }; + + componentDidMount() { + NativeModules.User.getName() + .then(result => this.setState({userName: result})) + .catch(error => Alert.alert("ERROR!", `${error}`)); + NativeModules.User.getEmail() + .then(result => this.setState({userEmail: result})) + .catch(error => Alert.alert("ERROR!", `${error}`)); + }; + + userNameOnChange = (text) => { + this.setState({userName: text}); + }; + + userEmailOnChange = (text) => { + this.setState({userEmail: text}); + } + + + quitButtonPressed = () => { + if(this.state.isEditing) { + Alert.alert("Are you sure?", "It looks like you still have unsaved changes, which are going to be lost.", + [ + { + text: "No!", + style: "cancel" + }, + { + text: "Yes, quit!", + onPress: () => NativeModules.NoteWidgetClickHandler.goToNotesScreen() + } + ]) + } + else { + NativeModules.NoteWidgetClickHandler.goToNotesScreen(); + } + }; + + saveButtonPressed = () => { + NativeModules.User.setEmail(this.state.userEmail); + NativeModules.User.setName(this.state.userName); + this.setState({isEditing: false}); + } + + editButtonPressed = () => { + this.setState({isEditing: true}); + }; + render() { - return( - - - UserAccountPanel - This panel will have all the features of User's account. - Further implementation will yet be done! + return ( + + + + + + User's name: + + + User's email: + + + + + +