Skip to content

Commit 78a631f

Browse files
committed
Fix <AllRead /> & hide account from list if no notifications
1 parent 7191edd commit 78a631f

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

src/js/routes/notifications.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,50 @@ import React from 'react';
22
import ReactCSSTransitionGroup from 'react-addons-css-transition-group';
33
import { connect } from 'react-redux';
44

5-
// import AllRead from '../components/all-read';
6-
// import Oops from '../components/oops';
5+
import AllRead from '../components/all-read';
6+
import Oops from '../components/oops';
77
import AccountNotifications from '../components/notifications';
88

99
export class NotificationsRoute extends React.Component {
1010
render() {
11-
const { accountNotifications } = this.props;
11+
const { accountNotifications, hasNotifications } = this.props;
1212
const wrapperClass = 'container-fluid main-container notifications';
13-
// const notificationsEmpty = accountNotifications.isEmpty();
14-
const notificationsEmpty = false;
1513

16-
// if (this.props.failed) {
17-
// return <Oops />;
18-
// }
14+
if (this.props.failed) {
15+
return <Oops />;
16+
}
1917

20-
// if (notificationsEmpty) {
21-
// return <AllRead />;
22-
// };
18+
if (!hasNotifications) {
19+
return <AllRead />;
20+
};
2321

2422
return (
25-
<div className={wrapperClass + (notificationsEmpty ? ' all-read' : '')}>
23+
<div className={wrapperClass + (!hasNotifications ? ' all-read' : '')}>
2624
<ReactCSSTransitionGroup
2725
transitionName="repository"
2826
transitionEnter={false}
2927
transitionLeaveTimeout={325}>
30-
{accountNotifications.map((obj, key) => {
31-
return (
32-
<AccountNotifications
33-
key={key}
34-
hostname={obj.get('hostname')}
35-
notifications={obj.get('notifications')} />
36-
);
37-
})}
28+
{accountNotifications.map((obj, key) => (
29+
!obj.get('notifications').isEmpty() &&
30+
<AccountNotifications
31+
key={key}
32+
hostname={obj.get('hostname')}
33+
notifications={obj.get('notifications')} />
34+
))}
3835
</ReactCSSTransitionGroup>
3936
</div>
4037
);
4138
}
4239
};
4340

4441
export function mapStateToProps(state) {
42+
const hasNotifications = state.notifications.get('response')
43+
.reduce((memo, acc) => memo + acc.get('notifications').size, 0) > 0;
44+
4545
return {
4646
failed: state.notifications.get('failed'),
47-
accountNotifications: state.notifications.get('response')
47+
accountNotifications: state.notifications.get('response'),
48+
hasNotifications
4849
};
4950
};
5051

0 commit comments

Comments
 (0)