Skip to content
Snippets Groups Projects
Commit 52076b6a authored by Taneli Riihimäki's avatar Taneli Riihimäki
Browse files

Continue working on login functionalities, added game listing

parent ddac8d34
No related branches found
No related tags found
No related merge requests found
import React, { Component, Fragment } from "react";
import { FlatList, Button } from "react-native";
class GameList extends Component {
constructor(props) {
super(props);
this.state = {
games: [],
selectedGame: null,
editForm: false
};
}
componentDidMount() {
this.getGames();
}
getGames() {
fetch("http://172.20.2.110:5000/game/listgames")
.then(response => response.json())
.then(games => {
this.setState({
games
});
})
.catch(error => {
console.log(error);
});
}
render() {
return (
<Fragment>
{this.state.games.length > 0 && (
<FlatList
data={this.state.games}
renderItem={({ item }) => <Button title={item.name} />}
/>
)}
</Fragment>
);
}
}
export default GameList;
import React, { Component } from "react"; import React, { Component, Fragment } from "react";
import { StyleSheet, Text, View, Button, AsyncStorage } from "react-native"; import { View, Button, AsyncStorage } from "react-native";
import LoginForm from "./LoginForm"; import LoginForm from "./LoginForm";
import RegisterForm from "./RegisterForm"; import RegisterForm from "./RegisterForm";
import GameList from "./GameList";
class Login extends Component { class Login extends Component {
state = { state = {
...@@ -35,7 +36,7 @@ class Login extends Component { ...@@ -35,7 +36,7 @@ class Login extends Component {
componentDidMount() { componentDidMount() {
let token = this.loadToken(); let token = this.loadToken();
if (token) { if (token) {
fetch(`${process.env.REACT_APP_URL}/user/verify`, { fetch(`http://172.20.2.110:5000/user/verify`, {
headers: { headers: {
Authorization: "Bearer " + token Authorization: "Bearer " + token
} }
...@@ -80,11 +81,14 @@ class Login extends Component { ...@@ -80,11 +81,14 @@ class Login extends Component {
/> />
)} )}
{this.state.username && ( {this.state.username && (
<Button <Fragment>
id="logoutButton" <Button
onPress={this.handleLogout.bind(this)} id="logoutButton"
title="Logout" onPress={this.handleLogout.bind(this)}
/> title="Logout"
/>
<GameList />
</Fragment>
)} )}
</View> </View>
{this.state.form === "register" && ( {this.state.form === "register" && (
......
...@@ -21,13 +21,6 @@ export class LoginForm extends React.Component { ...@@ -21,13 +21,6 @@ export class LoginForm extends React.Component {
this.props.toggleView(this.props.view); this.props.toggleView(this.props.view);
}; };
// remove login view with ESC
handleEsc = e => {
if (e.keyCode === 27) {
this.handleView();
}
};
handleLogin = e => { handleLogin = e => {
const name = this.state.username; const name = this.state.username;
const password = this.state.password; const password = this.state.password;
......
...@@ -35,9 +35,6 @@ export class RegisterForm extends React.Component { ...@@ -35,9 +35,6 @@ export class RegisterForm extends React.Component {
handleRegister = e => { handleRegister = e => {
const name = this.state.username; const name = this.state.username;
const password = this.state.password; const password = this.state.password;
console.log("PÄÄSTII TÄNNE");
this.setState({ registered: true });
console.log("Registered: " + this.state.registered);
if (this.state.password !== this.state.password2) { if (this.state.password !== this.state.password2) {
this.handleError("Passwords do not match"); this.handleError("Passwords do not match");
} else { } else {
...@@ -77,7 +74,6 @@ export class RegisterForm extends React.Component { ...@@ -77,7 +74,6 @@ export class RegisterForm extends React.Component {
return ( return (
<View className="fade-main"> <View className="fade-main">
<View className="sticky"> <View className="sticky">
{this.state.registered && <Text>REKISTERÖIDÄÄN</Text>}
<Text className="close" onPress={this.handleView}> <Text className="close" onPress={this.handleView}>
× ×
</Text> </Text>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment