aboutsummaryrefslogtreecommitdiff
path: root/src/store/reducers/userXReducer.ts
blob: 0a9e71bb8998e8aba35b13452c23eceffaa59a21 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import {ScreenType} from '../../types/types';
import {EMPTY_SCREEN_TO_USERS_LIST, EMPTY_USER_X} from '../initialStates';
import {createSlice} from '@reduxjs/toolkit';

const userXSlice = createSlice({
  name: 'userX',
  initialState: EMPTY_SCREEN_TO_USERS_LIST,
  reducers: {
    userXRequested: (state, action) => {
      state[<ScreenType>action.payload.screenType][action.payload.userId] =
        EMPTY_USER_X;
    },

    userXProfileFetched: (state, action) => {
      state[<ScreenType>action.payload.screenType][
        action.payload.userId
      ].profile = action.payload.data;
    },

    userXUserFetched: (state, action) => {
      state[<ScreenType>action.payload.screenType][action.payload.userId].user =
        action.payload.user;
    },

    userXMomentCategoriesFetched: (state, action) => {
      const categories: string[] = action.payload.data;
      state[<ScreenType>action.payload.screenType][
        action.payload.userId
      ].momentCategories = categories;
    },

    userXMomentsFetched: (state, action) => {
      state[<ScreenType>action.payload.screenType][
        action.payload.userId
      ].moments = action.payload.data;
    },

    userXFriendsFetched: (state, action) => {
      state[<ScreenType>action.payload.screenType][
        action.payload.userId
      ].friends = action.payload.data;
    },

    userXAvatarFetched: (state, action) => {
      state[<ScreenType>action.payload.screenType][
        action.payload.userId
      ].avatar = action.payload.data;
    },

    userXCoverFetched: (state, action) => {
      state[<ScreenType>action.payload.screenType][
        action.payload.userId
      ].cover = action.payload.data;
    },

    userXSocialsFetched: (state, action) => {
      state[<ScreenType>action.payload.screenType][
        action.payload.userId
      ].socialAccounts = action.payload.data;
    },

    userXFriendshipEdited: (state, action) => {
      state[<ScreenType>action.payload.screenType][
        action.payload.userId
      ].profile.friendship_status = action.payload.data;
    },

    resetScreen: (state, action) => {
      for (let userId in state[<ScreenType>action.payload.screenType]) {
        state[<ScreenType>action.payload.screenType][userId] = EMPTY_USER_X;
      }
    },
  },
});

export const {
  userXUserFetched,
  userXRequested,
  userXAvatarFetched,
  userXFriendsFetched,
  userXCoverFetched,
  userXMomentsFetched,
  userXProfileFetched,
  userXSocialsFetched,
  userXMomentCategoriesFetched,
  userXFriendshipEdited,
  resetScreen,
} = userXSlice.actions;
export const userXReducer = userXSlice.reducer;