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
|
||||
ctx.clear_Message2Opponent()
|
||||
ctx.setFetching(false)
|
||||
ctx.addGameData(responce)
|
||||
});
|
||||
}
|
||||
|
||||
@ -37,14 +38,14 @@ export default function Create() {
|
||||
}
|
||||
onClick={onClick}
|
||||
>
|
||||
<Wobler text="Leaderboard" dance={ctx.fetching} />
|
||||
<Wobler text="Create" dance={ctx.fetching} />
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
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})}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user