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