Skip to content

Commit

Permalink
fix(app-board): add parent when writing locked by
Browse files Browse the repository at this point in the history
  • Loading branch information
rams23 committed Feb 4, 2021
1 parent 3c71190 commit 9e49451
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion packages/game-app/src/gameView/apis/saveCardLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { CardState, FirebaseCollection } from '@pipeline/common';
import firebase from 'firebase/app';
import 'firebase/database';

export default async function saveCardState(userId: string, gameId: string, cardId: string) {
export default async function saveCardLok(userId: string, gameId: string, cardId: string, parent: 'board' | 'panel') {
const cardState: Partial<CardState> = {
parent,
lockedBy: userId,
};

Expand Down
4 changes: 2 additions & 2 deletions packages/game-app/src/gameView/hooks/useCardEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ export default function useCardEventHandler() {
dispatch(actions.updateCardPosition({ cardId, position, target }));
}
if (event.type === GameEventType.CardMovingStart) {
const { cardId } = event;
dispatch(actions.lockCard(cardId));
const { cardId, parent } = event;
dispatch(actions.lockCard({ cardId, parent }));
}
},
[dispatch],
Expand Down
2 changes: 1 addition & 1 deletion packages/game-app/src/gameView/sagas/saveCardLock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { AuthUser, selectors as authSelectors } from '@pipeline/auth';
function* executeSaveCardLock(action: ReturnType<typeof actions.lockCard>) {
const currentGameId = yield select(selectors.getGameId);
const { id: userId }: AuthUser = yield select(authSelectors.getCurrentUser);
yield call(saveCardLock, userId, currentGameId, action.payload);
yield call(saveCardLock, userId, currentGameId, action.payload.cardId, action.payload.parent);
}

export default function* saveCardLockSaga() {
Expand Down
18 changes: 12 additions & 6 deletions packages/game-app/src/gameView/slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const extraActions = {
loadCards: createAction(`${name}/loadCards`),
loadGame: createAction<string>(`${name}/loadGame`),
updateRTDBInstanceGame: createAction<string>(`${name}/updateRTDBInstanceGame`),
lockCard: createNetworkRequiringAction<string>(`${name}/lockCard`),
lockCard: createNetworkRequiringAction<{ cardId: string; parent: 'panel' | 'board' }>(`${name}/lockCard`),
updateCardPosition: createNetworkRequiringAction<{
cardId: string;
target: 'panel' | 'board';
Expand All @@ -76,7 +76,6 @@ const initialState = {
function modifyCardState(cardState: CardState, gameState: Draft<GameState>, cardId: string) {
if (cardState.parent === 'panel' && !gameState.deckCards.includes(cardId)) {
gameState.deckCards.push(cardId);
delete gameState.cardsState[cardId];
const index = gameState.boardCards.indexOf(cardId);
if (index > -1) {
gameState.boardCards.splice(index, 1);
Expand All @@ -89,10 +88,10 @@ function modifyCardState(cardState: CardState, gameState: Draft<GameState>, card
}
gameState.boardCards.push(cardId);
}
gameState.cardsState[cardId] = {
...cardState,
};
}
gameState.cardsState[cardId] = {
...cardState,
};
const maxZIndex = gameState.boardCards.reduce((acc, val) => {
acc =
acc === undefined || (gameState.cardsState[val]?.zIndex || DEFAULT_Z_INDEX) > acc
Expand Down Expand Up @@ -132,7 +131,7 @@ const slice = createSlice({
const gameState = state.gameState!;
const cardId = action.payload.cardId;
const cardState = action.payload.cardState;
modifyCardState(cardState, gameState, cardId);
return modifyCardState(cardState, gameState, cardId);
},
stopListenOnGame(state, action: PayloadAction) {
return initialState;
Expand Down Expand Up @@ -232,6 +231,12 @@ const getCardAdditionalInfo = (cardId: string) =>
};
});

const getIsUserTheFacilitator = createSelector(
getGame,
authSelectors.getCurrentUser,
(game, user) => game?.facilitator.id === user?.id,
);

const getCardById = (cardId: string) =>
createSelector(getSlice, state => cardsEntitiesSelectors.selectById(state.cards, cardId));

Expand Down Expand Up @@ -283,4 +288,5 @@ export const selectors = {
getFilteredDeckCardsIds,
getSearchedText,
getReview,
getIsUserTheFacilitator,
};
1 change: 1 addition & 0 deletions packages/game-app/src/gameView/types/gameEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum GameEventType {
type CardMovingStart = {
type: GameEventType.CardMovingStart;
cardId: string;
parent: 'board' | 'panel';
};

type CardMovingEnd = {
Expand Down

0 comments on commit 9e49451

Please sign in to comment.