Github user robertkowalski commented on a diff in the pull request:
https://github.com/apache/couchdb-fauxton/pull/544#discussion_r41139507
--- Diff: app/addons/fauxton/components.react.jsx ---
@@ -334,13 +354,246 @@ function (app, FauxtonAPI, React, ZeroClipboard) {
});
+ var NotificationCenterButton = React.createClass({
+ getInitialState: function () {
+ return {
+ visible: true
+ };
+ },
+
+ hide: function () {
+ this.setState({ visible: false });
+ },
+
+ show: function () {
+ this.setState({ visible: true });
+ },
+
+ render: function () {
+ var classes = 'fonticon fonticon-bell' + ((!this.state.visible) ? '
hide' : '');
+ return (
+ <div className={classes}
onClick={Actions.showNotificationCenter}></div>
+ );
+ }
+ });
+
+ var NotificationCenterPanel = React.createClass({
+
+ getInitialState: function () {
+ return this.getStoreState();
+ },
+
+ getStoreState: function () {
+ return {
+ isVisible: notificationStore.isNotificationCenterVisible(),
+ filter: notificationStore.getNotificationFilter(),
+ notifications: notificationStore.getNotifications()
+ };
+ },
+
+ componentDidMount: function () {
+ notificationStore.on('change', this.onChange, this);
+ },
+
+ componentWillUnmount: function () {
+ notificationStore.off('change', this.onChange);
+ },
+
+ onChange: function () {
+ if (this.isMounted()) {
+ this.setState(this.getStoreState());
+ }
+ },
+
+ getNotifications: function () {
+ if (!this.state.notifications.length) {
+ return (
+ <li className="no-notifications">No notifications.</li>
+ );
+ }
+
+ return _.map(this.state.notifications, function (notification, i) {
+ return (
+ <NotificationRow
+ isVisible={this.state.isVisible}
+ item={notification}
+ filter={this.state.filter}
+ key={notification.notificationId}
+ />
+ );
+ }, this);
+ },
+
+ selectFilter: function (e) {
+ var filter = $(e.target).closest('li').data('filter');
+ Actions.selectNotificationFilter(filter);
+ },
+
+ render: function () {
+ var panelClasses = 'notification-center-panel flex-layout flex-col';
+ if (this.state.isVisible) {
+ panelClasses += ' visible';
+ }
+
+ var filterClasses = {
+ all: 'flex-body',
+ success: 'flex-body',
+ error: 'flex-body',
+ info: 'flex-body'
+ };
+ filterClasses[this.state.filter] += ' selected';
+
+ var maskClasses = 'notification-page-mask' + ((this.state.isVisible)
? ' visible' : '');
+ return (
+ <div>
+ <div className={panelClasses}>
+
+ <header className="flex-layout flex-row">
+ <span className="fonticon fonticon-bell"></span>
+ <h1 className="flex-body">Notifications</h1>
+ <button type="button" aria-hidden="true"
onClick={Actions.hideNotificationCenter}>Ã</button>
+ </header>
+
+ <ul className="notification-filter flex-layout flex-row"
onClick={this.selectFilter}>
+ <li className={filterClasses.all} data-filter="all"
title="All notifications">All</li>
+ <li className={filterClasses.success} data-filter="success"
title="Success notifications">
+ <span className="fonticon fonticon-ok-circled"></span>
+ </li>
+ <li className={filterClasses.error} data-filter="error"
title="Error notifications">
+ <span className="fonticon
fonticon-attention-circled"></span>
+ </li>
+ <li className={filterClasses.info} data-filter="info"
title="Info notifications">
+ <span className="fonticon fonticon-info-circled"></span>
+ </li>
+ </ul>
--- End diff --
on possible way to solve this. just add the event handler on all three
nodes, react will take care of the memory management / delegation internally:
```html
<ul className="notification-filter flex-layout flex-row">
<li onClick={this.selectFilter.bind(this, 'all')}
className={filterClasses.all} title="All notifications">All</li>
[...]
```
this also removes the need for jquery and accessing the dom directly, what
we should really avoid
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---