diff --git a/webapp/src/components/Game/GameAction/Create.jsx b/webapp/src/components/Game/GameAction/Create.jsx
index f513f17..d95499b 100644
--- a/webapp/src/components/Game/GameAction/Create.jsx
+++ b/webapp/src/components/Game/GameAction/Create.jsx
@@ -26,6 +26,7 @@ export default function Create() {
console.log("responce", responce) // JSON data parsed by `data.json()` call
ctx.clear_Message2Opponent()
ctx.setFetching(false)
+ ctx.addGameData(responce)
});
}
@@ -37,14 +38,14 @@ export default function Create() {
}
onClick={onClick}
>
-
+
)
}
function Definitions() {
const [ctx, dispatchCtx] = React.useContext(AppContext)
- const [data] = React.useContext(AppData)
+ const [data, dispatchData] = React.useContext(AppData)
const isCurrentUser = data.isCurrentUser
const whitePlayerName = ctx.newGame.whitePlayer
@@ -77,6 +78,7 @@ function Definitions() {
getGameProposalRequest,
clear_Message2Opponent: () => { dispatchCtx({ update: "newGame", message: '' }) },
+ addGameData: (data) => { dispatchData({ type: "addGame", value: data})}
}
}
diff --git a/webapp/src/context/data/reducer.js b/webapp/src/context/data/reducer.js
index 6e9e065..9304370 100644
--- a/webapp/src/context/data/reducer.js
+++ b/webapp/src/context/data/reducer.js
@@ -2,23 +2,38 @@ export const reducer = (state, action) => {
switch (action.type) {
case "toggleOfflineMode":
- return { ...state,
+ return {
+ ...state,
offlineMode: !state.offlineMode // on/off
}
+ case "addGame":
+ console.log("oldState", state)
+ console.log("adding", action.value)
+ const newGames = [...state.games, action.value]
+ console.log("newGames", newGames)
+ const newState = {
+ ...state,
+ games: newGames
+ }
+ //newState.games.push(action.value)
+ console.log("newState", newState)
+ return newState
+
+
default:
console.warn("Unknown action.type", action)
return state
}
}
-
-export const initialState = {
- games: null,
+
+export const initialState = {
+ games: [],
gamesFetching: false,
- leaderboard: null,
+ leaderboard: [],
leaderboardFetching: false,
-
+
isCurrentUser: () => null,
offlineMode: false