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[action.payload.screenType][action.payload.userId] = EMPTY_USER_X; }, userXProfileFetched: (state, action) => { state[action.payload.screenType][ action.payload.userId ].profile = action.payload.data; }, userXUserFetched: (state, action) => { state[action.payload.screenType][action.payload.userId].user = action.payload.user; }, userXMomentCategoriesFetched: (state, action) => { const categories: string[] = action.payload.data; state[action.payload.screenType][ action.payload.userId ].momentCategories = categories; }, userXMomentsFetched: (state, action) => { state[action.payload.screenType][ action.payload.userId ].moments = action.payload.data; }, userXFriendsFetched: (state, action) => { state[action.payload.screenType][ action.payload.userId ].friends = action.payload.data; }, userXAvatarFetched: (state, action) => { state[action.payload.screenType][ action.payload.userId ].avatar = action.payload.data; }, userXCoverFetched: (state, action) => { state[action.payload.screenType][ action.payload.userId ].cover = action.payload.data; }, userXSocialsFetched: (state, action) => { state[action.payload.screenType][ action.payload.userId ].socialAccounts = action.payload.data; }, userXFriendshipEdited: (state, action) => { state[action.payload.screenType][ action.payload.userId ].profile.friendship_status = action.payload.data; }, resetScreen: (state, action) => { for (let userId in state[action.payload.screenType]) { state[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;