From d1e09081ab7a0f5a77035a97c023fb73841176fb Mon Sep 17 00:00:00 2001 From: ric <s1094610@studenti.univpm.it> Date: Tue, 7 Dec 2021 19:08:33 +0100 Subject: [PATCH] user data --- mobile/Screens/chatScreen.js | 10 ++++++++-- mobile/Screens/homeScreen.js | 23 +++++++++++++++++++++++ mobile/Screens/loginScreen.js | 5 ++++- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/mobile/Screens/chatScreen.js b/mobile/Screens/chatScreen.js index 938e346..a46bc1b 100644 --- a/mobile/Screens/chatScreen.js +++ b/mobile/Screens/chatScreen.js @@ -10,16 +10,22 @@ class ChatScreen extends Component { this.state = { msg : "", msgList: [], - user: this.props.route.params.user }; } + + componentDidMount() { + //Now we have the informations about the user + //so we can display for example the name in + //themessages + //const {user} = this.props.route.params; + //alert(user.username); + this.socket = io("http://192.168.196.145:3000", { //192.168.178.92 ric ip transports: ['websocket'] //this line is fundamental }); this.socket.on('msg', msg =>{ - alert(msg); this.setState({msgList: [...this.state.msgList, msg]}) }) } diff --git a/mobile/Screens/homeScreen.js b/mobile/Screens/homeScreen.js index 8b13789..abdeda8 100644 --- a/mobile/Screens/homeScreen.js +++ b/mobile/Screens/homeScreen.js @@ -1 +1,24 @@ +import React from 'react'; +import { StyleSheet, Text, View } from 'react-native'; +class HomeScreen extends React.Component { + render() { + return ( + <View style={styles.container}> + <Text>HOMEPAGE</Text> + </View> + ); + } +} + +// ... +const styles = StyleSheet.create({ + container: { + flex: 1, + backgroundColor: '#fff', + alignItems: 'center', + justifyContent: 'center', + }, + }); + +export default HomeScreen; diff --git a/mobile/Screens/loginScreen.js b/mobile/Screens/loginScreen.js index 30417d4..2ede41e 100644 --- a/mobile/Screens/loginScreen.js +++ b/mobile/Screens/loginScreen.js @@ -31,7 +31,10 @@ class LoginScreen extends Component { console.log(obj.body.result); if (obj.status == 200) { alert('Succesful login') - this.props.navigation.navigate('Chat', {user : obj.body.result}) + this.props.navigation.navigate('Chat', { + screen : 'Chat', + params: {user : obj.body.result}, + }) } else if (obj.status == 201){ alert('Succesful login') -- GitLab