GameProposal: Reject

This commit is contained in:
djmil 2023-11-15 19:44:42 +01:00
parent 392e7e9251
commit 60d6af94e1
8 changed files with 58 additions and 21 deletions

View File

@ -76,4 +76,18 @@ public class GameProposalController {
return ResponseEntity
.ok(canceledGameView);
}
@PutMapping("/{uuid}/reject")
public ResponseEntity<GameView> reject(
@AuthenticationPrincipal User issuer,
@PathVariable UUID uuid
) {
final GameView rejectedGameView = cordaClient.gameProposalReject(
issuer.getHoldingIdentity(),
uuid
);
return ResponseEntity
.ok(rejectedGameView);
}
}

View File

@ -31,6 +31,12 @@ export default function useGamesApi(gamesReducer, config) {
onPushing: (isPushingGameProposalCancel) => dispatchGames({ type: 'next', isPushingGameProposalCancel }),
onSuccess: (canceledGame) => dispatchGames({ type: 'next', gamesList: games.nextGameList(canceledGame), proposal: gamesInitialState.proposal })
}),
pushGameProposalReject: ({ uuid }) => ifNot(games.isPushingGameProposalReject) &&
doPushing(`/api/gameproposal/${uuid}/reject`, 'PUT', null, {
onPushing: (isPushingGameProposalReject) => dispatchGames({ type: 'next', isPushingGameProposalReject }),
onSuccess: (rejectedGame) => dispatchGames({ type: 'next', gamesList: games.nextGameList(rejectedGame), proposal: gamesInitialState.proposal })
}),
}
}

View File

@ -102,9 +102,8 @@
margin: 2px;
}
.ActionPanel .Create.ready /* , */ /* OR .game-action.busy */
{
background-color:#00b0ff60;
.ActionPanel .Create.ready { /* , */ /* OR .game-action.busy */
background-color:#00b0ff30;
}
.ActionPanel .Create.ready:hover {
@ -115,20 +114,29 @@
background-color:#00b0fff0;
}
.ActionPanel .Cancel:hover,
.ActionPanel .Reject:hover {
background-color:#ff000030
.ActionPanel .Cancel.ready,
.ActionPanel .Reject.ready {
background-color:#ffaaaa60
}
.ActionPanel .Cancel:active,
.ActionPanel .Reject:active {
background-color:#ff000080
.ActionPanel .Cancel.ready:hover,
.ActionPanel .Reject.ready:hover {
background-color:#ff000060
}
.ActionPanel .Accept:hover {
background-color: #00af0030;
.ActionPanel .Cancel.ready:active,
.ActionPanel .Reject.ready:active {
background-color:#ff0000a0
}
.ActionPanel .Accept:active {
background-color:#00af0080;
.ActionPanel .Accept.ready {
background-color: #00af0018;
}
.ActionPanel .Accept.ready:hover {
background-color:#00af0060;
}
.ActionPanel .Accept.ready:active {
background-color:#00af00a0;
}

View File

@ -97,8 +97,8 @@ function ActionPanel({ players, gamesApi }) {
} />
<Route path='proposal' element={[
<Accept key={1} />,
<Reject key={2} />,
<Cancel key={3} onClick={({ uuid }) => gamesApi.pushGameProposalCancel({ uuid })} />
<Reject key={2} onClick={(uuid) => gamesApi.pushGameProposalReject({ uuid })} />,
<Cancel key={3} onClick={(uuid) => gamesApi.pushGameProposalCancel({ uuid })} />
]} />
<Route path='active' element={[<DrawReq key={1} />, <DrawAcq key={2} />, <Surrender key={3} />]} />
<Route path='archive' element={[<Backward key={1} />, <Forward key={2} />]} />

View File

@ -1,14 +1,15 @@
import React, { useContext } from 'react';
import { GamesContext } from '../../../context/games';
export default function Accept() {
export default function Accept({ onClick }) {
const games = useContext(GamesContext);
const selectedGame = games.findGame({ uuid: games.proposal.selectedUUID });
const isReady = selectedGame?.status === 'GAME_PROPOSAL_WAIT_FOR_YOU' ? true : '';
if (selectedGame?.status !== 'GAME_PROPOSAL_WAIT_FOR_OPPONENT')
return (
<button className='Accept'>
<button className={'Accept' + (isReady && ' ready')}>
Accept
</button>
)

View File

@ -6,10 +6,13 @@ export default function Cancel({ onClick }) {
const games = useContext(GamesContext);
const selectedGame = games.findGame({ uuid: games.proposal.selectedUUID });
const isReady = selectedGame?.status === 'GAME_PROPOSAL_WAIT_FOR_OPPONENT' ? true : '';
if (selectedGame?.status === 'GAME_PROPOSAL_WAIT_FOR_OPPONENT')
return (
<button className='Cancel' onClick={() => onClick({ uuid: games.proposal.selectedUUID })} >
<button className={'Cancel' + (isReady && ' ready')}
onClick={() => isReady ? onClick(selectedGame.uuid) : alert('You have to select pending GameProposal')}
>
<Wobler text="Cancel" dance={games.isPushingGameProposalCancel} />
</button>
)

View File

@ -1,15 +1,19 @@
import React, { useContext } from 'react';
import Wobler from '../../../components/Wobler';
import { GamesContext } from '../../../context/games';
export default function Reject() {
export default function Reject({ onClick }) {
const games = useContext(GamesContext);
const selectedGame = games.findGame({ uuid: games.proposal.selectedUUID });
const isReady = selectedGame?.status === 'GAME_PROPOSAL_WAIT_FOR_YOU' ? true : '';
if (selectedGame?.status !== 'GAME_PROPOSAL_WAIT_FOR_OPPONENT')
return (
<button className='Reject'>
Reject
<button className={'Reject' + (isReady && ' ready')}
onClick={() => isReady ? onClick(selectedGame.uuid) : alert('You have to select some GameProposal')}
>
<Wobler text="Reject" dance={games.isPushingGameProposalReject} />
</button>
)
}

View File

@ -28,6 +28,7 @@ export const gamesInitialState = {
isPollingGamesList: false,
isPushingNewGame: false,
isPushingGameProposalCancel: false,
isPushingGameProposalReject: false,
findGame,
nextGameList,