Skip to content

Commit 1547f2a

Browse files
committed
make GameScreen and print description
1 parent e2f0480 commit 1547f2a

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

code/src/components/GameScreen.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import React from 'react'
2+
import { useSelector } from 'react-redux'
3+
4+
const GameScreen = () => {
5+
const userActions = useSelector(store => store.games.username)
6+
// console.log(userActions)
7+
8+
const games = useSelector(store => store.games.username.actions)
9+
console.log(games)
10+
11+
return (
12+
<div>
13+
<h3>{userActions.description}</h3>
14+
{/* <p>{games.description}</p> */}
15+
{/* {userActions.map(action => (
16+
<button
17+
key={action}
18+
onClick=""
19+
>
20+
{action}
21+
</button>
22+
))} */}
23+
</div>
24+
)
25+
}
26+
27+
export default GameScreen

code/src/components/StartScreen.js

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useState } from 'react'
22
import { useDispatch } from 'react-redux'
33

44
import { games, createNewPlayer } from '../reducers/games'
5+
import GameScreen from './GameScreen'
56

67
const StartScreen = () => {
78
const [inputValue, setInputValue] = useState('')
@@ -27,6 +28,7 @@ const StartScreen = () => {
2728
placeholder="Type your name..."
2829
/>
2930
<button onClick={onFormSubmit}>Start</button>
31+
<GameScreen />
3032
</form>
3133
)
3234
}

code/src/reducers/games.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,29 @@ export const createNewPlayer = (username) => {
2929
username: `${username}`
3030
}),
3131
})
32-
.then((res) => res.json())
32+
.then(res => res.json())
3333
.then(data => dispatch(games.actions.setUserName(data)))
3434
}
3535
}
3636

37+
// map over actions send in action ?
38+
// type: 'move',
39+
// direction: action.direction
40+
41+
/* export const CarryOnGame = () => {
42+
return (dispatch) => {
43+
fetch('https://wk16-backend.herokuapp.com/action', {
44+
method: 'POST',
45+
headers: {
46+
'Content-type': 'application/json'
47+
},
48+
body: JSON.stringify({
49+
direction
50+
}),
51+
})
52+
.then(res => res.json())
53+
.then(data => dispatch(games.actions.setDescription(data)))
54+
}
55+
}
56+
*/
3757
export default games

0 commit comments

Comments
 (0)