Skip to content

Commit

Permalink
✨ delete rounds when deleting a game
Browse files Browse the repository at this point in the history
  • Loading branch information
dxanh97 committed Oct 14, 2024
1 parent 2598916 commit fd5089b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IconInfoSquareRounded, IconTrash } from '@tabler/icons-react';
import { useAppDispatch, useAppSelector } from '../redux/store';
import { selectAllGames } from '../redux/game.selector';
import { deleteGame } from '../redux/game.slice';
import { deleteGameRounds } from '../redux/round.slice';
import { formatDateTime } from '../utils/helpers';

import TopNav from '../components/shared/TopNav';
Expand All @@ -28,7 +29,10 @@ function HomePage() {
withCloseButton: false,
centered: true,
labels: { confirm: 'Oke', cancel: 'Thoi' },
onConfirm: () => dispatch(deleteGame(gameId)),
onConfirm: () => {
dispatch(deleteGame(gameId));
dispatch(deleteGameRounds(gameId));
},
});
};

Expand Down
11 changes: 10 additions & 1 deletion src/redux/round.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,17 @@ const roundSlice = createSlice({
});
},
deleteRound: roundAdaptor.removeOne,
deleteGameRounds: (state, action: PayloadAction<string>) => {
const roundIds = roundAdaptor
.getSelectors()
.selectAll(state)
.filter((round) => round.gameId === action.payload)
.map((round) => round.id);
roundAdaptor.removeMany(state, roundIds);
},
},
});

export const { createRound, updateRound, deleteRound } = roundSlice.actions;
export const { createRound, updateRound, deleteRound, deleteGameRounds } =
roundSlice.actions;
export default roundSlice;

0 comments on commit fd5089b

Please sign in to comment.