Skip to content

Commit

Permalink
fix: update room reducer to match message from MC EPI
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-welker committed Mar 4, 2024
1 parent e7edb0b commit 6110741
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/lib/store/rooms/rooms.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,32 @@ const roomsSlice = createSlice({
initialState,
reducers: {
setRoomState(state, action:PayloadAction<Message>) {
const type = action.payload.type;
const type = action.payload.type;
const key = type.slice(type.lastIndexOf('/') + 1);

// extract the room key from the type
const matches = type.match('/room/(.*)/status');
console.log(type, key);

if (!matches) return;

const key = matches[1];
if(!key) return;

// This method solves the issue of multiple layers of properties
// and avoids doing a deep copy of the object

const content = action.payload.content as RoomState;

console.log(content);

// Get existing room state
const existingState = state[key] ?? {};

// merge new state with existing
const newState = _.merge(existingState, content);
const newState = merge(existingState, content);

Check failure on line 32 in src/lib/store/rooms/rooms.slice.ts

View workflow job for this annotation

GitHub Actions / build

Cannot find name 'merge'.

// overlay the incoming state properties onto the existing item
// or create new item
state[key] = newState;

console.log(state);

return state;
}
},
Expand Down

0 comments on commit 6110741

Please sign in to comment.