Skip to content

Commit

Permalink
#24: Creates new reducer to use new coordinates data
Browse files Browse the repository at this point in the history
  • Loading branch information
williamquintas authored and arthursimas1 committed Jun 1, 2023
1 parent 1cd6e48 commit 3155fd0
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions features/sessions/slice.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import type { AppState } from "../../config/store";
import { ICoordinatesData } from "../../models/ICoordinatesData";
import { IEntity } from "../../models/IEntity";
export interface SessionState {
id: string;
Expand Down Expand Up @@ -50,6 +51,22 @@ export const sessionSlice = createSlice({
(entity) => entity.id !== action.payload
);
},
appendCoordinateToEntity: (
state,
action: PayloadAction<ICoordinatesData>
) => {
const currentEntities = [...state.entities];
const editedEntity = currentEntities.find(
(entity) => entity.id === action.payload.id
);

if (editedEntity) {
currentEntities[currentEntities.indexOf(editedEntity)].coordinates.push(
action.payload
);
state.entities = currentEntities;
}
},
},
});

Expand All @@ -59,6 +76,7 @@ export const {
editEntity,
updateEntities,
deleteEntity,
appendCoordinateToEntity,
} = sessionSlice.actions;

export const selectSession = (state: AppState) => state.session;
Expand Down

0 comments on commit 3155fd0

Please sign in to comment.