diff --git a/mobile/App.js b/mobile/App.js index 7524f0c67f5470474344c00287d54cd1d860f146..cb5f96fdd18a5256764a75ce3623a2b50217626b 100644 --- a/mobile/App.js +++ b/mobile/App.js @@ -2,9 +2,10 @@ import React from 'react'; import { NavigationContainer } from '@react-navigation/native'; import { createNativeStackNavigator } from '@react-navigation/native-stack'; import LoginScreen from './Screens/loginScreen' -import HomeScreen from './Screens/homeScreen' +import ChatScreen from './Screens/chatScreen' import RegistrationScreen from './Screens/registrationScreen' + const Stack = createNativeStackNavigator(); class App extends React.Component { @@ -12,19 +13,19 @@ class App extends React.Component { //In the render here we define the application Screen routes //with navigation, then in the classes we'll use the navigate //method to move from one page to another + render() { - let x = 1; - console.log("App executed"); + return ( <NavigationContainer> <Stack.Navigator> - <Stack.Screen + <Stack.Screen name="Login" component={LoginScreen} /> <Stack.Screen - name="Home" - component={HomeScreen} + name="Forum" + component={ChatScreen} /> <Stack.Screen name="Registration" diff --git a/mobile/Screens/homeScreen.js b/mobile/Screens/chatScreen.js similarity index 74% rename from mobile/Screens/homeScreen.js rename to mobile/Screens/chatScreen.js index 7fe59a1ec2d7cf1970030a6e3e1dd21857277268..4383ead526d9142c86a54a8044da23a4379f7900 100644 --- a/mobile/Screens/homeScreen.js +++ b/mobile/Screens/chatScreen.js @@ -1,22 +1,25 @@ import React, {Component} from 'react'; import { StyleSheet, Text, View, Button, TextInput } from 'react-native'; import {io} from "socket.io-client"; //socket.io-client +import uuid from 'react-native-uuid'; -class HomeScreen extends Component { +class ChatScreen extends Component { constructor(props) { super(props); this.state = { - msg : "" + msg : "", + msgList: [] }; } componentDidMount() { - this.socket = io("http://192.168.178.92:3000", { + this.socket = io("http://192.168.178.92: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]}) }) } @@ -26,8 +29,17 @@ class HomeScreen extends Component { } render() { + + const msgList = this.state.msgList.map(msg => ( + <Text key={uuid.v4()}>{msg}</Text> + )); + return ( + <View style={styles.container}> + + {msgList} + <TextInput style={styles.input} placeholder="Send a message" @@ -37,13 +49,12 @@ class HomeScreen extends Component { onChangeText={msg => { this.setState({ msg }); }} - /> + /> </View> ); } } -// ... const styles = StyleSheet.create({ container: { flex: 1, @@ -62,4 +73,4 @@ const styles = StyleSheet.create({ } }); -export default HomeScreen; \ No newline at end of file +export default ChatScreen; \ No newline at end of file diff --git a/mobile/Screens/loginScreen.js b/mobile/Screens/loginScreen.js index 4095ae591f78940da596bb571a26c3cd253e73ca..71a2547cc1e17f1835c2411be4bfcdf90dbd6b23 100644 --- a/mobile/Screens/loginScreen.js +++ b/mobile/Screens/loginScreen.js @@ -1,108 +1,107 @@ -import React, {Component} from 'react'; +import React, { Component } from 'react'; import { StyleSheet, Text, View, Button, TextInput } from 'react-native'; class LoginScreen extends Component { - constructor(props) { - super(props); - this.state = { - username: "", - password: "" - }; - } + constructor(props) { + super(props); + this.state = { + username: "", + password: "" + }; + } - submitLogin() { - - //here we're going to post the username and password inserted in the - //login page, in particulare this is a post request to the /signin route - //in the server that will response with status:200 if the credentials are in the - //database and with status:422 if not - fetch('http://192.168.178.92:3000/signin', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ - username : this.state.username, - password : this.state.password - }), - }) //here we handle the status response of the server - .then(res =>{ - if (res.status !== 200){ + submitLogin() { + + //here we're going to post the username and password inserted in the + //login page, in particulare this is a post request to the /signin route + //in the server that will response with status:200 if the credentials are in the + //database and with status:422 if not + fetch('http://192.168.178.92:3000/signin', {//192.168.178.92 + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + username: this.state.username, + password: this.state.password + }), + }) //here we handle the status response of the server + .then(res => { + if (res.status !== 200) { alert('Invalid username or password'); } - else{ + else { alert('Succesful login') - this.props.navigation.navigate('Home') + this.props.navigation.navigate('Forum') } }) - //here we set again username and password as blank - //probably in the future we'll need to send the credentials to the home page - //to create the user for the socket.io chat - this.setState({ username: "" }); - this.setState({ password: "" }); - } + //here we set again username and password as blank + //probably in the future we'll need to send the credentials to the home page + //to create the user for the socket.io chat + this.setState({ username: "" }); + this.setState({ password: "" }); + } - render() { + render() { - return ( - <View style={styles.container}> - <Text>LOGIN</Text> + return ( + <View style={styles.container}> + <Text>LOGIN</Text> - <TextInput - style={styles.TextInput} - placeholder = "Username" - autoCorrect = {false} - value = {this.state.username} - onChangeText = {username => { - this.setState({ username }); - }} - /> - + <TextInput + style={styles.TextInput} + placeholder="Username" + autoCorrect={false} + value={this.state.username} + onChangeText={username => { + this.setState({ username }); + }} + /> - <TextInput - style={styles.TextInput} - placeholder="Password" - autoCorrect={false} - secureTextEntry={true} - value = {this.state.password} - onChangeText = {password => { - this.setState({ password }); - }} - /> + <TextInput + style={styles.TextInput} + placeholder="Password" + autoCorrect={false} + secureTextEntry={true} + value={this.state.password} + onChangeText={password => { + this.setState({ password }); + }} + /> - <Button - title="Login" - onPress={() => - this.submitLogin() - } - /> - {/* this will be the button for the registration page */} - <Button - title="Go to Registration" - onPress={() => { - this.props.navigation.navigate('Registration') - } - } - /> - </View> - ); - } + <Button + title="Login" + onPress={() => + this.submitLogin() + } + /> + {/* this will be the button for the registration page */} + <Button + title="Go to Registration" + onPress={() => { + this.props.navigation.navigate('Registration') + } + } + /> + </View> + ); + } } // ... const styles = StyleSheet.create({ - container: { - flex: 1, - backgroundColor: '#fff', - alignItems: 'center', - justifyContent: 'center', - }, - TextInput: { - height: 40, - width: 200, - borderWidth: 2, - padding:10 - } - }); + container: { + flex: 1, + backgroundColor: '#fff', + alignItems: 'center', + justifyContent: 'center', + }, + TextInput: { + height: 40, + width: 200, + borderWidth: 2, + padding: 10 + } +}); export default LoginScreen; \ No newline at end of file diff --git a/mobile/package-lock.json b/mobile/package-lock.json index 2d79da0f91ea73bb64432f50a835b20d5b71e4ab..82afa1a720d1eac3af63e75f2e24a44bbf46453c 100644 --- a/mobile/package-lock.json +++ b/mobile/package-lock.json @@ -1231,6 +1231,14 @@ "minimist": "^1.2.0" } }, + "@egjs/hammerjs": { + "version": "2.0.17", + "resolved": "https://registry.npmjs.org/@egjs/hammerjs/-/hammerjs-2.0.17.tgz", + "integrity": "sha512-XQsZgjm2EcVUiZQf11UBJQfmZeEmOW8DpI1gsFeln6w0ae0ii4dMQEQ0kjl6DspdWX1aGY1/loyXnP0JS06e/A==", + "requires": { + "@types/hammerjs": "^2.0.36" + } + }, "@expo/config": { "version": "5.0.9", "resolved": "https://registry.npmjs.org/@expo/config/-/config-5.0.9.tgz", @@ -1748,6 +1756,16 @@ } } }, + "@react-navigation/drawer": { + "version": "6.1.8", + "resolved": "https://registry.npmjs.org/@react-navigation/drawer/-/drawer-6.1.8.tgz", + "integrity": "sha512-kYE2EO5dianUuUcaYmAlYBcgtmvGm2fxWTQ5sn103cgPNidp4KBUR9ClkhF+btfRaHKq+8Ul5M6qvL0mBAv/Lg==", + "requires": { + "@react-navigation/elements": "^1.2.1", + "color": "^3.1.3", + "warn-once": "^0.1.0" + } + }, "@react-navigation/elements": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/@react-navigation/elements/-/elements-1.2.1.tgz", @@ -1818,6 +1836,11 @@ "@types/node": "*" } }, + "@types/hammerjs": { + "version": "2.0.40", + "resolved": "https://registry.npmjs.org/@types/hammerjs/-/hammerjs-2.0.40.tgz", + "integrity": "sha512-VbjwR1fhsn2h2KXAY4oy1fm7dCxaKy0D+deTb8Ilc3Eo3rc5+5eA4rfYmZaHgNJKxVyI0f6WIXzO2zLkVmQPHA==" + }, "@types/istanbul-lib-coverage": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.3.tgz", @@ -2543,6 +2566,15 @@ "object-visit": "^1.0.0" } }, + "color": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/color/-/color-3.2.1.tgz", + "integrity": "sha512-aBl7dZI9ENN6fUGC7mWpMTPNHmWUSNan9tuWN6ahh5ZLNk9baLJOnSMlrQkHcrfFgz2/RigjUVAjdx36VcemKA==", + "requires": { + "color-convert": "^1.9.3", + "color-string": "^1.6.0" + } + }, "color-convert": { "version": "1.9.3", "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", @@ -2556,6 +2588,15 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" }, + "color-string": { + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/color-string/-/color-string-1.9.0.tgz", + "integrity": "sha512-9Mrz2AQLefkH1UvASKj6v6hj/7eWgjnT/cVsR8CumieLoT+g900exWeNogqtweI8dxloXN9BDQTYro1oWu/5CQ==", + "requires": { + "color-name": "^1.0.0", + "simple-swizzle": "^0.2.2" + } + }, "colorette": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/colorette/-/colorette-1.4.0.tgz", @@ -3674,6 +3715,21 @@ } } }, + "hoist-non-react-statics": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz", + "integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==", + "requires": { + "react-is": "^16.7.0" + }, + "dependencies": { + "react-is": { + "version": "16.13.1", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", + "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" + } + } + }, "http-errors": { "version": "1.7.3", "resolved": "https://registry.npmjs.org/http-errors/-/http-errors-1.7.3.tgz", @@ -4979,6 +5035,11 @@ "minimist": "^1.2.5" } }, + "mockdate": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/mockdate/-/mockdate-3.0.5.tgz", + "integrity": "sha512-iniQP4rj1FhBdBYS/+eQv7j1tadJ9lJtdzgOpvsOHng/GbcDh2Fhdeq+ZRldrPYdXvCyfFUmFeEwEGXZB5I/AQ==" + }, "ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -5926,6 +5987,61 @@ "nullthrows": "^1.1.1" } }, + "react-native-gesture-handler": { + "version": "1.10.3", + "resolved": "https://registry.npmjs.org/react-native-gesture-handler/-/react-native-gesture-handler-1.10.3.tgz", + "integrity": "sha512-cBGMi1IEsIVMgoox4RvMx7V2r6bNKw0uR1Mu1o7NbuHS6BRSVLq0dP34l2ecnPlC+jpWd3le6Yg1nrdCjby2Mw==", + "requires": { + "@egjs/hammerjs": "^2.0.17", + "fbjs": "^3.0.0", + "hoist-non-react-statics": "^3.3.0", + "invariant": "^2.2.4", + "prop-types": "^15.7.2" + }, + "dependencies": { + "fbjs": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/fbjs/-/fbjs-3.0.1.tgz", + "integrity": "sha512-8+vkGyT4lNDRKHQNPp0yh/6E7FfkLg89XqQbOYnvntRh+8RiSD43yrh9E5ejp1muCizTL4nDVG+y8W4e+LROHg==", + "requires": { + "cross-fetch": "^3.0.4", + "fbjs-css-vars": "^1.0.0", + "loose-envify": "^1.0.0", + "object-assign": "^4.1.0", + "promise": "^7.1.1", + "setimmediate": "^1.0.5", + "ua-parser-js": "^0.7.30" + } + } + } + }, + "react-native-reanimated": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/react-native-reanimated/-/react-native-reanimated-2.2.4.tgz", + "integrity": "sha512-Nn648MfEEnTCEiWsl1YmfkojiLyV0NMY0EiRdDRbZNfJVfxBuyqhCxI/4Jd7aBi162qpgf8XK2mByYgvF4zLrQ==", + "requires": { + "@babel/plugin-transform-object-assign": "^7.10.4", + "fbjs": "^3.0.0", + "mockdate": "^3.0.2", + "string-hash-64": "^1.0.3" + }, + "dependencies": { + "fbjs": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/fbjs/-/fbjs-3.0.1.tgz", + "integrity": "sha512-8+vkGyT4lNDRKHQNPp0yh/6E7FfkLg89XqQbOYnvntRh+8RiSD43yrh9E5ejp1muCizTL4nDVG+y8W4e+LROHg==", + "requires": { + "cross-fetch": "^3.0.4", + "fbjs-css-vars": "^1.0.0", + "loose-envify": "^1.0.0", + "object-assign": "^4.1.0", + "promise": "^7.1.1", + "setimmediate": "^1.0.5", + "ua-parser-js": "^0.7.30" + } + } + } + }, "react-native-safe-area-context": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/react-native-safe-area-context/-/react-native-safe-area-context-3.3.2.tgz", @@ -5939,6 +6055,11 @@ "warn-once": "^0.1.0" } }, + "react-native-uuid": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/react-native-uuid/-/react-native-uuid-2.0.1.tgz", + "integrity": "sha512-cptnoIbL53GTCrWlb/+jrDC6tvb7ypIyzbXNJcpR3Vab0mkeaaVd5qnB3f0whXYzS+SMoSQLcUUB0gEWqkPC0g==" + }, "react-native-web": { "version": "0.17.1", "resolved": "https://registry.npmjs.org/react-native-web/-/react-native-web-0.17.1.tgz", @@ -6499,6 +6620,21 @@ "plist": "^3.0.4" } }, + "simple-swizzle": { + "version": "0.2.2", + "resolved": "https://registry.npmjs.org/simple-swizzle/-/simple-swizzle-0.2.2.tgz", + "integrity": "sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo=", + "requires": { + "is-arrayish": "^0.3.1" + }, + "dependencies": { + "is-arrayish": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.3.2.tgz", + "integrity": "sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ==" + } + } + }, "sisteransi": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/sisteransi/-/sisteransi-1.0.5.tgz", @@ -6759,6 +6895,11 @@ "resolved": "https://registry.npmjs.org/strict-uri-encode/-/strict-uri-encode-2.0.0.tgz", "integrity": "sha1-ucczDHBChi9rFC3CdLvMWGbONUY=" }, + "string-hash-64": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/string-hash-64/-/string-hash-64-1.0.3.tgz", + "integrity": "sha512-D5OKWKvDhyVWWn2x5Y9b+37NUllks34q1dCDhk/vYcso9fmhs+Tl3KR/gE4v5UNj2UA35cnX4KdVVGkG1deKqw==" + }, "string-width": { "version": "4.2.3", "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", diff --git a/mobile/package.json b/mobile/package.json index db8ad37e252c8469b52ab5786e71df9eeb47a3e5..c05f76f129b02969d28a66c6f315b1d5bf2355ff 100644 --- a/mobile/package.json +++ b/mobile/package.json @@ -10,6 +10,7 @@ "eject": "expo eject" }, "dependencies": { + "@react-navigation/drawer": "^6.1.8", "@react-navigation/native": "^6.0.6", "@react-navigation/native-stack": "^6.2.5", "expo": "~43.0.2", @@ -19,8 +20,11 @@ "react-native": "0.64.3", "react-native-safe-area-context": "3.3.2", "react-native-screens": "~3.8.0", + "react-native-uuid": "^2.0.1", "react-native-web": "0.17.1", - "socket.io-client": "^4.4.0" + "socket.io-client": "^4.4.0", + "react-native-gesture-handler": "~1.10.2", + "react-native-reanimated": "~2.2.0" }, "devDependencies": { "@babel/core": "^7.12.9"