implementation
This commit is contained in:
parent
3a2c9e93e2
commit
df54d76341
@ -26,6 +26,7 @@ export default function Create() {
|
|||||||
console.log("responce", responce) // JSON data parsed by `data.json()` call
|
console.log("responce", responce) // JSON data parsed by `data.json()` call
|
||||||
ctx.clear_Message2Opponent()
|
ctx.clear_Message2Opponent()
|
||||||
ctx.setFetching(false)
|
ctx.setFetching(false)
|
||||||
|
ctx.addGameData(responce)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,14 +38,14 @@ export default function Create() {
|
|||||||
}
|
}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
>
|
>
|
||||||
<Wobler text="Leaderboard" dance={ctx.fetching} />
|
<Wobler text="Create" dance={ctx.fetching} />
|
||||||
</button>
|
</button>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function Definitions() {
|
function Definitions() {
|
||||||
const [ctx, dispatchCtx] = React.useContext(AppContext)
|
const [ctx, dispatchCtx] = React.useContext(AppContext)
|
||||||
const [data] = React.useContext(AppData)
|
const [data, dispatchData] = React.useContext(AppData)
|
||||||
|
|
||||||
const isCurrentUser = data.isCurrentUser
|
const isCurrentUser = data.isCurrentUser
|
||||||
const whitePlayerName = ctx.newGame.whitePlayer
|
const whitePlayerName = ctx.newGame.whitePlayer
|
||||||
@ -77,6 +78,7 @@ function Definitions() {
|
|||||||
|
|
||||||
getGameProposalRequest,
|
getGameProposalRequest,
|
||||||
clear_Message2Opponent: () => { dispatchCtx({ update: "newGame", message: '' }) },
|
clear_Message2Opponent: () => { dispatchCtx({ update: "newGame", message: '' }) },
|
||||||
|
addGameData: (data) => { dispatchData({ type: "addGame", value: data})}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,10 +2,25 @@ export const reducer = (state, action) => {
|
|||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
|
||||||
case "toggleOfflineMode":
|
case "toggleOfflineMode":
|
||||||
return { ...state,
|
return {
|
||||||
|
...state,
|
||||||
offlineMode: !state.offlineMode // on/off
|
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:
|
default:
|
||||||
console.warn("Unknown action.type", action)
|
console.warn("Unknown action.type", action)
|
||||||
return state
|
return state
|
||||||
@ -13,10 +28,10 @@ export const reducer = (state, action) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const initialState = {
|
export const initialState = {
|
||||||
games: null,
|
games: [],
|
||||||
gamesFetching: false,
|
gamesFetching: false,
|
||||||
|
|
||||||
leaderboard: null,
|
leaderboard: [],
|
||||||
leaderboardFetching: false,
|
leaderboardFetching: false,
|
||||||
|
|
||||||
isCurrentUser: () => null,
|
isCurrentUser: () => null,
|
||||||
|
Loading…
Reference in New Issue
Block a user