diff --git a/components/GameList.js b/components/GameList.js new file mode 100644 index 0000000000000000000000000000000000000000..f6ecf0848edc5a5db650b0986c8ac537d6e5dee5 --- /dev/null +++ b/components/GameList.js @@ -0,0 +1,44 @@ +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; diff --git a/components/Login.js b/components/Login.js index d4e6e27b24ec550859dbe04a4ca9ec2c8d774a6a..53740ad247c628f0e59b30a5c8e96e542e2c267f 100644 --- a/components/Login.js +++ b/components/Login.js @@ -1,8 +1,9 @@ -import React, { Component } from "react"; -import { StyleSheet, Text, View, Button, AsyncStorage } from "react-native"; +import React, { Component, Fragment } from "react"; +import { View, Button, AsyncStorage } from "react-native"; import LoginForm from "./LoginForm"; import RegisterForm from "./RegisterForm"; +import GameList from "./GameList"; class Login extends Component { state = { @@ -35,7 +36,7 @@ class Login extends Component { componentDidMount() { let token = this.loadToken(); if (token) { - fetch(`${process.env.REACT_APP_URL}/user/verify`, { + fetch(`http://172.20.2.110:5000/user/verify`, { headers: { Authorization: "Bearer " + token } @@ -80,11 +81,14 @@ class Login extends Component { /> )} {this.state.username && ( - <Button - id="logoutButton" - onPress={this.handleLogout.bind(this)} - title="Logout" - /> + <Fragment> + <Button + id="logoutButton" + onPress={this.handleLogout.bind(this)} + title="Logout" + /> + <GameList /> + </Fragment> )} </View> {this.state.form === "register" && ( diff --git a/components/LoginForm.js b/components/LoginForm.js index bb3fb04c871e575248bc8674f51a7b23c5537ece..6b4fe975492c96877644914e54490c4548a5c33a 100644 --- a/components/LoginForm.js +++ b/components/LoginForm.js @@ -21,13 +21,6 @@ export class LoginForm extends React.Component { this.props.toggleView(this.props.view); }; - // remove login view with ESC - handleEsc = e => { - if (e.keyCode === 27) { - this.handleView(); - } - }; - handleLogin = e => { const name = this.state.username; const password = this.state.password; diff --git a/components/Register.js b/components/Register.js deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/components/RegisterForm.js b/components/RegisterForm.js index fa066953d39f7170b70bb5a3368aeef157f35a8c..3576dbb49edc278778577bafe13d0b277c9e3760 100644 --- a/components/RegisterForm.js +++ b/components/RegisterForm.js @@ -35,9 +35,6 @@ export class RegisterForm extends React.Component { handleRegister = e => { const name = this.state.username; 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) { this.handleError("Passwords do not match"); } else { @@ -77,7 +74,6 @@ export class RegisterForm extends React.Component { return ( <View className="fade-main"> <View className="sticky"> - {this.state.registered && <Text>REKISTERÖIDÄÄN</Text>} <Text className="close" onPress={this.handleView}> × </Text>