feat: user state
This commit is contained in:
parent
57c932471f
commit
2c22db517b
|
@ -1,10 +1,12 @@
|
|||
import merge from 'deepmerge';
|
||||
import {combineReducers} from 'redux';
|
||||
|
||||
import createCommonStore from '~/common/store';
|
||||
import chat from '~/common/state/chat';
|
||||
import user from '~/common/state/user';
|
||||
import createCommonStore from '~/common/store';
|
||||
|
||||
const reducer = combineReducers({
|
||||
chat,
|
||||
user,
|
||||
});
|
||||
|
||||
|
|
|
@ -8,19 +8,19 @@ import hydration from './hydration';
|
|||
|
||||
export const userSelector = (state) => state.user;
|
||||
|
||||
export const friendsSelector = createSelector(
|
||||
export const friendshipSelector = createSelector(
|
||||
userSelector,
|
||||
(user) => user.friends,
|
||||
(user) => user.friendship,
|
||||
);
|
||||
|
||||
export const activeFriendsSelector = createSelector(
|
||||
friendsSelector,
|
||||
(friends) => Object.values(friends).filter(({state}) => 'active' === state),
|
||||
export const activeFriendshipSelector = createSelector(
|
||||
friendshipSelector,
|
||||
(friendship) => Object.values(friendship).filter(({state}) => 'active' === state),
|
||||
);
|
||||
|
||||
export const pendingFriendsSelector = createSelector(
|
||||
friendsSelector,
|
||||
(friends) => Object.values(friends).filter(({state}) => 'pending' === state),
|
||||
export const pendingFriendshipSelector = createSelector(
|
||||
friendshipSelector,
|
||||
(friendship) => Object.values(friendship).filter(({state}) => 'pending' === state),
|
||||
);
|
||||
|
||||
export const redditUsernameSelector = createSelector(
|
||||
|
@ -31,19 +31,34 @@ export const redditUsernameSelector = createSelector(
|
|||
const slice = createSlice({
|
||||
name: 'user',
|
||||
initialState: {
|
||||
favorites: {},
|
||||
friends: {},
|
||||
blocked: [],
|
||||
favorites: [],
|
||||
friendship: [],
|
||||
isAnonymous: false,
|
||||
redditUsername: 'anonymous',
|
||||
...(hydration('user') || {isAnonymous: true}),
|
||||
},
|
||||
reducers: {
|
||||
addFriend: (state, action) => {},
|
||||
addToFavorites: (state, action) => {},
|
||||
blockUser: (state, action) => {},
|
||||
removeFriend: (state, action) => {},
|
||||
removeFromFavorites: (state, action) => {},
|
||||
updateFriendshipStatus: (state, action) => {},
|
||||
addFriendship: (state, {payload: {friendship}}) => {
|
||||
state.friendship.push(friendship);
|
||||
},
|
||||
addToFavorites: (state, {payload: {favorite}}) => {
|
||||
state.favorites.push(favorite);
|
||||
},
|
||||
blockUser: (state, {payload: {blocked}}) => {
|
||||
state.blocked.push(blocked);
|
||||
},
|
||||
removeFriendship: (state, {payload: {id}}) => {
|
||||
state.friendship.splice(state.friendship.findIndex((friendship) => friendship.id === id), 1);
|
||||
},
|
||||
removeFromFavorites: (state, {payload: {type, name}}) => {
|
||||
state.favorites.splice(state.favorites.findIndex(
|
||||
(favorite) => favorite.name === name && favorite.type === type,
|
||||
), 1);
|
||||
},
|
||||
updateFriendshipStatus: (state, {payload: {id, status}}) => {
|
||||
state.friendship.find((friendship) => friendship.id === id).status = status;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user