Compare commits

...

2 Commits

Author SHA1 Message Date
262fa0636d initial implementation 2023-10-31 13:17:41 +01:00
1cf762254c mock implementstion 2023-10-31 10:16:35 +01:00
5 changed files with 35 additions and 4 deletions

View File

@ -6,6 +6,7 @@ import GameAction from './Game/GameAction'
import GameBoard from './Game/GameBoard' import GameBoard from './Game/GameBoard'
import NewGame from './Game/NewGame' import NewGame from './Game/NewGame'
import GameMessage from './Game/GameMessage' import GameMessage from './Game/GameMessage'
import Message2Opponent from './Game/Message2Opponent'
export default function Game() { export default function Game() {
@ -20,6 +21,7 @@ export default function Game() {
<GameAction /> <GameAction />
<GameMessage /> <GameMessage />
<GameBoard /> <GameBoard />
<Message2Opponent />
</div> </div>
</div> </div>
) )

View File

@ -17,7 +17,8 @@ export default function Create() {
postData("/api/gameproposal", request) postData("/api/gameproposal", request)
.then((responce) => { .then((responce) => {
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()
}); });
} }
@ -32,7 +33,7 @@ export default function Create() {
} }
function Definitions() { function Definitions() {
const [ctx] = React.useContext(AppContext) const [ctx, dispatchCtx] = React.useContext(AppContext)
const [data] = React.useContext(AppData) const [data] = React.useContext(AppData)
const isCurrentUser = data.isCurrentUser const isCurrentUser = data.isCurrentUser
@ -54,7 +55,7 @@ function Definitions() {
opponentName, opponentName,
opponentColor, opponentColor,
board: null, board: null,
message: "let's play a game" message: ctx.newGame.message
} }
} }
@ -64,6 +65,7 @@ function Definitions() {
isEnabled, isEnabled,
get_GameProposalRequest, get_GameProposalRequest,
clear_Message2Opponent: () => { dispatchCtx({ update: "newGame", message: '' }) }
} }
} }
@ -81,7 +83,7 @@ function get_Opponent(isCurrentUser, whitePlayerName, blackPlayerName) {
async function postData(url = "", data = {}) { async function postData(url = "", data = {}) {
console.log("POST", url, data) console.log("POST", url, data)
const response = await fetch(url, { const response = await fetch(url, {
method: "POST", method: "POST",
headers: { headers: {

View File

@ -0,0 +1,3 @@
.message2opponent input{
width: 270px;
}

View File

@ -0,0 +1,23 @@
import './Message2Opponent.css'
import React from 'react'
import { AppContext } from '../../context/app'
export default function Message2Opponent() {
const [ctx, dispatchCtx] = React.useContext(AppContext)
const setMessage = (message) => {
dispatchCtx({ update: "newGame", message })
}
return (
<div className='message2opponent'>
<input
placeholder='Message to opponent'
value={ctx.newGame.message}
maxLength={150}
onChange={e => setMessage(e.target.value)}
/>
</div>
)
}

View File

@ -24,6 +24,7 @@ export const initialState = {
newGame: { newGame: {
whitePlayer: '', whitePlayer: '',
blackPlayer: '', blackPlayer: '',
message: '',
}, },
} }