aboutsummaryrefslogtreecommitdiff
path: root/src/store/reducers/userBlockReducer.ts
blob: 68b9a54490177041653edcfb1df25aed9e04c2ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import {createSlice} from '@reduxjs/toolkit';
import {NO_BLOCKED_USERS} from '../initialStates';

const userBlockSlice = createSlice({
  name: 'userBlock',
  initialState: NO_BLOCKED_USERS,
  reducers: {
    userBlockFetched: (state, action) => {
      state.blockedUsers = action.payload;
    },

    updateBlockedList: (state, action) => {
      const {isBlocked, data} = action.payload;
      if (!isBlocked) {
        state.blockedUsers.push(data);
      } else {
        state.blockedUsers = state.blockedUsers.filter(
          (user) => user.username !== data.username,
        );
      }
    },
  },
});

export const {userBlockFetched, updateBlockedList} = userBlockSlice.actions;
export const userBlockReducer = userBlockSlice.reducer;