-
Notifications
You must be signed in to change notification settings - Fork 0
/
side_bar_container.js
51 lines (44 loc) · 1.32 KB
/
side_bar_container.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
import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import SideBar from './side_bar';
import { fetchSubs } from '../../actions/subscription_actions';
import { receiveFilter, clearFilter } from '../../actions/ui_actions';
import mapFilter from '../../util/mapFilter';
const mapStateToProps = (state, ownProps) => {
const currentUser = state.session.currentUser;
const filter = state.ui.filter;
const location = ownProps.location.pathname;
const history = ownProps.history;
if (!currentUser) {
return {
subs: [],
currentUser,
filter,
location,
history,
};
}
const subIds = currentUser.subIds;
const allSubs = state.entities.subscriptions.subs;
const users = state.entities.users;
let subs = mapFilter(subIds, id => allSubs[id]);
subs = subs.map(sub => Object.assign({}, sub, users[Number(sub.subscribeeId)]));
const needsSubRequest = subIds.length !== subs;
return {
subs,
currentUser,
needsSubRequest,
filter,
location,
history,
};
};
const mapDispatchToProps = (dispatch) => ({
fetchSubs: () => dispatch(fetchSubs()),
receiveFilter: (filter) => dispatch(receiveFilter(filter)),
clearFilter: () => dispatch(clearFilter()),
});
export default withRouter(connect(
mapStateToProps,
mapDispatchToProps
)(SideBar));