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 return ResponseEntity
.ok(canceledGameView); .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 }), onPushing: (isPushingGameProposalCancel) => dispatchGames({ type: 'next', isPushingGameProposalCancel }),
onSuccess: (canceledGame) => dispatchGames({ type: 'next', gamesList: games.nextGameList(canceledGame), proposal: gamesInitialState.proposal }) 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; margin: 2px;
} }
.ActionPanel .Create.ready /* , */ /* OR .game-action.busy */ .ActionPanel .Create.ready { /* , */ /* OR .game-action.busy */
{ background-color:#00b0ff30;
background-color:#00b0ff60;
} }
.ActionPanel .Create.ready:hover { .ActionPanel .Create.ready:hover {
@ -115,20 +114,29 @@
background-color:#00b0fff0; background-color:#00b0fff0;
} }
.ActionPanel .Cancel:hover, .ActionPanel .Cancel.ready,
.ActionPanel .Reject:hover { .ActionPanel .Reject.ready {
background-color:#ff000030 background-color:#ffaaaa60
} }
.ActionPanel .Cancel:active, .ActionPanel .Cancel.ready:hover,
.ActionPanel .Reject:active { .ActionPanel .Reject.ready:hover {
background-color:#ff000080 background-color:#ff000060
} }
.ActionPanel .Accept:hover { .ActionPanel .Cancel.ready:active,
background-color: #00af0030; .ActionPanel .Reject.ready:active {
background-color:#ff0000a0
} }
.ActionPanel .Accept:active { .ActionPanel .Accept.ready {
background-color:#00af0080; 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={[ <Route path='proposal' element={[
<Accept key={1} />, <Accept key={1} />,
<Reject key={2} />, <Reject key={2} onClick={(uuid) => gamesApi.pushGameProposalReject({ uuid })} />,
<Cancel key={3} onClick={({ uuid }) => gamesApi.pushGameProposalCancel({ uuid })} /> <Cancel key={3} onClick={(uuid) => gamesApi.pushGameProposalCancel({ uuid })} />
]} /> ]} />
<Route path='active' element={[<DrawReq key={1} />, <DrawAcq key={2} />, <Surrender key={3} />]} /> <Route path='active' element={[<DrawReq key={1} />, <DrawAcq key={2} />, <Surrender key={3} />]} />
<Route path='archive' element={[<Backward key={1} />, <Forward key={2} />]} /> <Route path='archive' element={[<Backward key={1} />, <Forward key={2} />]} />

View File

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

View File

@ -6,10 +6,13 @@ export default function Cancel({ onClick }) {
const games = useContext(GamesContext); const games = useContext(GamesContext);
const selectedGame = games.findGame({ uuid: games.proposal.selectedUUID }); 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') if (selectedGame?.status === 'GAME_PROPOSAL_WAIT_FOR_OPPONENT')
return ( 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} /> <Wobler text="Cancel" dance={games.isPushingGameProposalCancel} />
</button> </button>
) )

View File

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

View File

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