forked from OpenBazaar/haven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
follow.js
53 lines (49 loc) · 1.75 KB
/
follow.js
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
import { createAction, handleActions } from 'redux-actions';
export const actions = {
fetchFollowers: 'FOLLOW/FETCH_FOLLOWERS',
setFollowers: 'FOLLOW/SET_FOLLOWERS',
fetchFollowings: 'FOLLOW/FETCH_FOLLOWINGS',
fetchFollowingsFromLocal: 'FOLLOW/FETCH_FOLLOWINGS_FROM_LOCAL',
setFollowings: 'FOLLOW/SET_FOLLOWINGS',
setFollowingsFromLocal: 'FOLLOW/SET_FOLLOWINGS_FROM_LOCAL',
followPeer: 'FOLLOW/FOLLOW_PEER',
unfollowPeer: 'FOLLOW/UNFOLLOW_PEER',
addFollowing: 'FOLLOW/ADD_FOLLOWER',
removeFollowing: 'FOLLOW/REMOVE_FOLLOWER',
};
export const fetchFollowers = createAction(actions.fetchFollowers);
export const fetchFollowings = createAction(actions.fetchFollowings);
export const fetchFollowingsFromLocal = createAction(actions.fetchFollowingsFromLocal);
export const followPeer = createAction(actions.followPeer);
export const unfollowPeer = createAction(actions.unfollowPeer);
const initialState = {
followers: [],
followings: [],
followingsFromLocal: [],
};
export default handleActions(
{
[actions.setFollowers]: (state, action) => ({
...state,
followers: action.payload,
}),
[actions.setFollowings]: (state, action) => ({
...state,
followings: action.payload,
}),
[actions.setFollowingsFromLocal]: (state, action) => ({
...state,
followingsFromLocal: action.payload,
}),
[actions.addFollowing]: (state, action) => ({
...state,
followings: [...state.followings, { peerID: action.payload }],
followingsFromLocal: [...state.followingsFromLocal, action.payload],
}),
[actions.removeFollowing]: (state, action) => ({
...state,
followingsFromLocal: state.followingsFromLocal.filter(following => following !== action.payload),
}),
},
initialState,
);