Skip to content
Snippets Groups Projects
Commit e14bc746 authored by Joni Laukka's avatar Joni Laukka
Browse files

game selection update

parent 65219bf5
No related branches found
No related tags found
2 merge requests!31Development,!28Routing
...@@ -88,6 +88,10 @@ class App extends Component { ...@@ -88,6 +88,10 @@ class App extends Component {
authenticateComplete: true authenticateComplete: true
}); });
}); });
} else {
this.setState({
authenticateComplete: true
});
} }
} }
...@@ -138,7 +142,7 @@ class App extends Component { ...@@ -138,7 +142,7 @@ class App extends Component {
render() { render() {
// TODO: think better solution to wait for authenticator // TODO: think better solution to wait for authenticator
if (!this.state.authenticateComplete) { if (!this.state.authenticateComplete) {
return false; return <div>Authenticating...</div>;
} }
return ( return (
...@@ -146,14 +150,17 @@ class App extends Component { ...@@ -146,14 +150,17 @@ class App extends Component {
<div> <div>
{/* Debug Sign out button ------------------------ */} {/* Debug Sign out button ------------------------ */}
{this.state.logged && ( {this.state.logged && (
<button <div>
onClick={() => { <label>Logged in: {sessionStorage.getItem("name")}</label>
sessionStorage.setItem("token", ""); <button
this.setState({ logged: false }); onClick={() => {
}} sessionStorage.setItem("token", "");
> this.setState({ logged: false });
Sign out }}
</button> >
Sign out
</button>
</div>
)} )}
{/* Debug End ----------------------- */} {/* Debug End ----------------------- */}
......
...@@ -2,35 +2,8 @@ import React, { Fragment } from "react"; ...@@ -2,35 +2,8 @@ import React, { Fragment } from "react";
import GameCard from "./GameCard"; import GameCard from "./GameCard";
class GameList extends React.Component { class GameList extends React.Component {
constructor(props) {
super(props);
this.state = {
games: []
};
}
componentDidMount() {
this.getGames();
}
getGames() {
fetch(`${process.env.REACT_APP_API_URL}/game/listgames`)
.then(response => response.json())
.then(games => {
this.setState({
games: games,
selectedGame: games !== undefined && games[0].id
});
// taking the initialized gameID to UserMap.js (GameList.js -> Header.js -> App.js -> UserMap.js)
this.props.handleGameChange(games[0].id);
})
.catch(error => {
console.log(error);
});
}
render() { render() {
let gamelistItems = this.state.games.map(game => { let gamelistItems = this.props.games.map(game => {
return ( return (
<GameCard <GameCard
key={game.id} key={game.id}
......
...@@ -4,9 +4,29 @@ import NewGameForm from "./NewGameForm"; ...@@ -4,9 +4,29 @@ import NewGameForm from "./NewGameForm";
export default class GameSelection extends React.Component { export default class GameSelection extends React.Component {
state = { state = {
newGameForm: false newGameForm: false,
games: []
}; };
componentDidMount() {
this.getGames();
}
getGames() {
fetch(`${process.env.REACT_APP_API_URL}/game/listgames`)
.then(response => response.json())
.then(games => {
this.setState({
games: games
});
// taking the initialized gameID to UserMap.js (GameList.js -> Header.js -> App.js -> UserMap.js)
//this.props.handleGameChange(games[0].id);
})
.catch(error => {
console.log(error);
});
}
render() { render() {
return ( return (
<div> <div>
...@@ -22,10 +42,14 @@ export default class GameSelection extends React.Component { ...@@ -22,10 +42,14 @@ export default class GameSelection extends React.Component {
<NewGameForm <NewGameForm
view="" view=""
handleState={this.handleState} handleState={this.handleState}
toggleView={() => this.setState({ newGameForm: false })} toggleView={() =>
this.setState({ newGameForm: false }, () => {
this.getGames();
})
}
/> />
)} )}
<GameList /> <GameList games={this.state.games} />
</div> </div>
); );
} }
......
import React from "react"; import React from "react";
import UserMap from "./UserMap"; import UserMap from "./UserMap";
import { BrowserRouter as Router, Link } from "react-router-dom";
export default class GameView extends React.Component { export default class GameView extends React.Component {
state = { state = {
...@@ -27,6 +28,9 @@ export default class GameView extends React.Component { ...@@ -27,6 +28,9 @@ export default class GameView extends React.Component {
return ( return (
<div> <div>
<div>{this.state.gameId}</div> <div>{this.state.gameId}</div>
<Link to="/">
<button>Game selection</button>
</Link>
<UserMap <UserMap
position={initialPosition} position={initialPosition}
zoom={this.state.zoom} zoom={this.state.zoom}
......
...@@ -122,7 +122,7 @@ export class RegisterForm extends React.Component { ...@@ -122,7 +122,7 @@ export class RegisterForm extends React.Component {
<h2>{this.state.errorMsg}</h2> <h2>{this.state.errorMsg}</h2>
</form> </form>
<Link to="/"> <Link to="/">
<button>Back</button> <button>Login</button>
</Link> </Link>
</div> </div>
</div> </div>
......
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