Skip to content

Commit

Permalink
fix(webapp): remove project should remove the project from board
Browse files Browse the repository at this point in the history
  • Loading branch information
ben196888 committed Jul 18, 2024
1 parent 1619d60 commit 12053b4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 5 additions & 4 deletions packages/webapp/src/game/store/slice/projectBoard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ const initialState = (): ProjectSlot[] => [];

const initialize = (state: ProjectSlot[], maxProjectSlots: number): void => {
for (let i = 0; i < maxProjectSlots; i++) {
state.push(ProjectSlotSlice.initialState());
const slotId = `project-slot-${i}`;
state.push(ProjectSlotSlice.initialState(slotId));
}
}

Expand All @@ -21,11 +22,11 @@ const add = (state: ProjectSlot[], card: ProjectCard): void => {

const remove = (state: ProjectSlot[], removedSlots: ProjectSlot[]): void => {
removedSlots.forEach(removeSlot => {
let slotToBeRemoved = state.find(slot => slot.card?.id === removeSlot.card?.id && slot.owner === removeSlot.owner);
if (!slotToBeRemoved) {
const slotIndexToBeRemoved = state.findIndex(slot => slot.id === removeSlot.id);
if (slotIndexToBeRemoved === -1) {
throw new Error('Project slot not found');
}
slotToBeRemoved = ProjectSlotSlice.initialState();
state[slotIndexToBeRemoved] = ProjectSlotSlice.initialState(removeSlot.id);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@ export interface ProjectContribution {
}

export interface ProjectSlot {
id: string;
card?: ProjectCard;
owner: PlayerID;
ownerToken: number;
contributions: ProjectContribution[];
lastContributor: PlayerID;
}

const initialState = (): ProjectSlot => ({
const initialState = (id: string): ProjectSlot => ({
id,
owner: '',
ownerToken: 0,
contributions: [],
Expand Down

0 comments on commit 12053b4

Please sign in to comment.