Skip to content

Commit

Permalink
Fix: full hand data.
Browse files Browse the repository at this point in the history
  • Loading branch information
dleclercpro committed Jan 8, 2024
1 parent 904f9f0 commit d550277
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Apps/ClientApp/src/actions/ServerActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ export const getFullHandData = (): AppThunkAction<void> => {
return (dispatch: AppThunkDispatch<void>) => {

return new CallGetFullHand().execute()
.then((response: FullHandData) => {
dispatch(setFullHand(response));
.then((response: ServerResponse<FullHandData>) => {
dispatch(setFullHand(response.data));
});
};
}
Expand Down
3 changes: 2 additions & 1 deletion Apps/ClientApp/src/calls/base/Call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ class Call {
}

// Something went wrong, but we let the processing happen further down the line
return Promise.reject(new Error(error));
console.warn(`Error in call: ${this.name}`);
return Promise.reject(error ?? 'UNKNOWN_ERROR');
}
}

Expand Down
4 changes: 2 additions & 2 deletions Apps/ClientApp/src/calls/game/CallGetFullHand.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { SERVER_URL } from '../../config';
import { API_URL } from '../../config';
import CallGET from '../base/CallGET';

export class CallGetFullHand extends CallGET {

constructor() {
super('GetHand', `${SERVER_URL}/static/hand.json`);
super('GetFullHand', `${API_URL}/game/hand`);
}
};
2 changes: 2 additions & 0 deletions Apps/ClientApp/src/components/Hand.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class Hand extends React.Component<Props, {}> {
getFilteredTilesForDialog = (dialog : DialogType): HandTile[] => {
const { tiles, isWaterTileSelected } = this.props;

console.log(tiles);

return tiles.filter((tile: HandTile) => {
const { type } = tile;

Expand Down
11 changes: 5 additions & 6 deletions Apps/ClientApp/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ export const TILE_PATH: string = getHexagonalPath(TILE_SIZE, TILE_STROKE);
export const TILE_PATH_BOARD: string = getHexagonalPath(TILE_SIZE, 0); // Superimposing tiles on their contours

// Server
export const SERVER_URL = DEV ? 'http://localhost:8000' : '';
export const API_URL = `${SERVER_URL}/api/v1`;
export const POLL_RATE = 5 * 1000; // ms
export const FETCH_DEFAULT_TIMEOUT = 2000; // ms
export const API_URL = `/api/v1`;
export const POLL_RATE = 5 * 1_000; // ms
export const FETCH_DEFAULT_TIMEOUT = 2_000; // ms
export const MAX_POLL_RETRIES = 5;

// FX
export const FX_SOUND_NEW_TURN = `${SERVER_URL}/static/new-turn.wav`;
export const FX_SOUND_GAME_OVER = `${SERVER_URL}/static/game-over.wav`;
export const FX_SOUND_NEW_TURN = `/static/new-turn.wav`;
export const FX_SOUND_GAME_OVER = `/static/game-over.wav`;
19 changes: 19 additions & 0 deletions Apps/ServerApp/src/controllers/game/GetFullHandController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { RequestHandler } from 'express';
import { successResponse } from '../../utils/calls';
import { logger } from '../../utils/logging';
import { FULL_HAND_JSON } from '../../config/GameConfig';

const GetFullHandController: RequestHandler = async (req, res, next) => {
try {
return res.json(successResponse(FULL_HAND_JSON));

} catch (err: unknown) {
if (err instanceof Error) {
logger.warn(err.message);
}

next(err);
}
}

export default GetFullHandController;
2 changes: 2 additions & 0 deletions Apps/ServerApp/src/routes/api/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { PlayGameValidation } from '../../middleware/validation/PlayGameValidati
import { PlayGameSanitization } from '../../middleware/sanitization/PlayGameSanitization';
import { CreateGameValidation } from '../../middleware/validation/CreateGameValidation';
import { CreateGameSanitization } from '../../middleware/sanitization/CreateGameSanitization';
import GetFullHandController from '../../controllers/game/GetFullHandController';



Expand All @@ -23,6 +24,7 @@ router.use(SessionMiddleware);
router.post('/', [CreateGameValidation, CreateGameSanitization], CreateGameController);
router.post('/:id', [PlayGameValidation, PlayGameSanitization], PlayGameController);
router.get('/:id/:version', [], GetGameController);
router.get('/hand', [], GetFullHandController);



Expand Down

0 comments on commit d550277

Please sign in to comment.