Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Step 4 solution #8

Open
wants to merge 1 commit into
base: step-4
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/pages/Lobby/NewGame/NewGame.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import React from "react";
import { Button, Grid, Typography } from "@material-ui/core";
//let's import what we need
import { useDispatch, useSelector } from "react-redux";
import { selectGame, createGame } from "../../../store/gameSlice";

export default function NewGame() {
// let's connect Redux to our Component
const dispatch = useDispatch();
const { id, idError, idLoading } = useSelector(selectGame);

return (
<Grid container direction="row" justify="center" alignItems="center">
Expand All @@ -15,11 +19,15 @@ export default function NewGame() {
<Typography color="textSecondary">game code</Typography>
<Typography variant="h1" className="highlight">
{/* let's display the game id */}
{"----"}
{id || "----"}
</Typography>
<br />
{/* let's make our button create a new game*/}
<Button
disabled={idLoading}
onClick={() => {
dispatch(createGame());
}}
style={{ marginTop: 32, marginBottom: 32 }}
disableElevation
size="large"
Expand All @@ -29,6 +37,9 @@ export default function NewGame() {
start new game
</Button>
{/* let's show an error message if there is one */}
{idError && (
<Typography color="textSecondary">Error: {idError}</Typography>
)}
</Grid>
</Grid>
);
Expand Down