Skip to content

Instantly share code, notes, and snippets.

@ohadlevy
Created March 26, 2017 14:29
Show Gist options
  • Save ohadlevy/ea3e2e17aad226031a9ff9dcdbb6619f to your computer and use it in GitHub Desktop.
Save ohadlevy/ea3e2e17aad226031a9ff9dcdbb6619f to your computer and use it in GitHub Desktop.
diff --git a/app/controllers/notification_recipients_controller.rb b/app/controllers/notification_recipients_controller.rb
index 4b25877..ae32929 100644
--- a/app/controllers/notification_recipients_controller.rb
+++ b/app/controllers/notification_recipients_controller.rb
@@ -7,12 +7,11 @@ class NotificationRecipientsController < Api::V2::BaseController
def index
@notifications = NotificationRecipient.
where(:user_id => User.current.id, :notification_id => Notification.active).
- order(:created_at).
+ order(created_at: :desc).
eager_load(:notification, :notification_blueprint)
render :json => {
- :notifications => @notifications.paginate(paginate_options).map(&:payload),
- :total => @notifications.count
+ :notifications => @notifications.paginate(paginate_options).map(&:payload)
}
end
diff --git a/app/views/home/_user_dropdown.html.erb b/app/views/home/_user_dropdown.html.erb
index 5178117..9e6dd22 100644
--- a/app/views/home/_user_dropdown.html.erb
+++ b/app/views/home/_user_dropdown.html.erb
@@ -13,5 +13,4 @@
</ul>
</li>
- <%= mount_react_component('NotificationDrawer','#notifications_container',{:url => notification_recipients_path}.to_json) %>
-
+<%= mount_react_component('NotificationDrawer','#notifications_container',{:url => notification_recipients_path}.to_json) %>
diff --git a/package.json b/package.json
index fc99467..6fb5aa4 100644
--- a/package.json
+++ b/package.json
@@ -55,7 +55,6 @@
"jquery.cookie": "~1.4.1",
"jstz": "~1.0.7",
"lodash": "~4.15.0",
- "moment": "^2.17.1",
"multiselect": "~0.9.12",
"react": "^15.1.0",
"react-bootstrap": "^0.30.0",
diff --git a/webpack/assets/javascripts/react_app/API.js b/webpack/assets/javascripts/react_app/API.js
index 2d942fd..ad27cd0 100644
--- a/webpack/assets/javascripts/react_app/API.js
+++ b/webpack/assets/javascripts/react_app/API.js
@@ -5,7 +5,7 @@ export default {
$.ajaxPrefilter(function (options, originalOptions, jqXHR) {
jqXHR.originalRequestOptions = originalOptions;
});
- return $.getJSON(url);
+ return $.getJSON(`${url}?per_page=100`);
},
markNotificationAsRead(id) {
const data = JSON.stringify({'seen': true});
diff --git a/webpack/assets/javascripts/react_app/components/notifications/NotificationDrawerToggle.js b/webpack/assets/javascripts/react_app/components/notifications/NotificationDrawerToggle.js
deleted file mode 100644
index d69f818..0000000
--- a/webpack/assets/javascripts/react_app/components/notifications/NotificationDrawerToggle.js
+++ /dev/null
@@ -1,68 +0,0 @@
-import React, { Component } from 'react';
-import helpers from '../../common/helpers';
-import NotificationsStore from '../../stores/NotificationsStore';
-import NotificationActions from '../../actions/NotificationActions';
-import { ACTIONS } from '../../constants';
-import _ from 'lodash';
-
-class NotificationDrawerToggle extends Component {
- constructor(props) {
- super(props);
- this.state = { isLoaded: false, drawerOpen: false, hasUnreadNotifications: false};
- helpers.bindMethods(this, ['onChange', 'onClick']);
- }
-
- componentDidMount() {
- NotificationsStore.addChangeListener(this.onChange);
- NotificationActions.getNotifications(this.props.url);
- }
-
- componentWillUnmount() {
- NotificationsStore.removeChangeListener(this.onChange);
- }
-
- onChange(actionType) {
- switch (actionType) {
- case ACTIONS.RECEIVED_NOTIFICATIONS: {
- const notifications = NotificationsStore.getNotifications();
-
- const newState = {
- hasUnreadNotifications: _.some(notifications, group =>
- _.some(group, notification => !notification.seen)),
- isLoaded: true
- };
-
- this.setState(newState);
- break;
- }
- case ACTIONS.NOTIFICATIONS_DRAWER_TOGGLE: {
- this.setState({
- drawerOpen: NotificationsStore.getIsDrawerOpen()
- });
- break;
- }
- default:
- break;
- }
- }
-
- onClick() {
- NotificationActions.toggleNotificationDrawer();
- }
-
- iconType() {
- return this.state.hasUnreadNotifications ? 'fa-bell' : 'fa-bell-o';
- }
-
- render() {
- return (
- <a className="nav-item-iconic drawer-pf-trigger-icon" onClick={this.onClick}>
- <span className={'fa ' + this.iconType()}
- data-placement="bottom"
- title={__('Notifications')}></span>
- </a>
- );
- }
-}
-
-export default NotificationDrawerToggle;
diff --git a/webpack/assets/javascripts/react_app/components/notifications/drawer/notification.js b/webpack/assets/javascripts/react_app/components/notifications/drawer/notification.js
index e0a87c7..053acdf 100644
--- a/webpack/assets/javascripts/react_app/components/notifications/drawer/notification.js
+++ b/webpack/assets/javascripts/react_app/components/notifications/drawer/notification.js
@@ -1,6 +1,5 @@
import React from 'react';
import Icon from '../../common/Icon';
-import moment from 'moment';
import NotificationDropdown from './NotificationDropdown';
import '../../../common/commonStyles.css';
@@ -19,7 +18,7 @@ const Notification = (
onMarkAsRead
}
) => {
- const created = moment.utc(created_at);
+ const created = new Date(created_at);
const title = __('Click to mark as read').toString();
const tooltip = {
title: title,
@@ -41,8 +40,8 @@ const Notification = (
<div className="notification-text-container">
{markup}
<div className="drawer-pf-notification-info">
- <span className="date">{created.format('M/D/YY')}</span>
- <span className="time">{created.format('hh:mm:ss A')}</span>
+ <span className="date">{created.toLocaleDateString()}</span>
+ <span className="time">{created.toLocaleTimeString()}</span>
</div>
</div>
{actions.links && <NotificationDropdown links={actions.links} id={id} />}
diff --git a/webpack/assets/javascripts/react_app/components/notifications/drawer/notificationGroup.js b/webpack/assets/javascripts/react_app/components/notifications/drawer/notificationGroup.js
index cb56736..d21b9cd 100644
--- a/webpack/assets/javascripts/react_app/components/notifications/drawer/notificationGroup.js
+++ b/webpack/assets/javascripts/react_app/components/notifications/drawer/notificationGroup.js
@@ -1,6 +1,5 @@
import React from 'react';
import Notification from './notification';
-import { orderBy, reverse } from 'lodash';
export default (
{
@@ -32,7 +31,7 @@ export default (
isExpanded &&
<div className="panel-body">
{
- reverse(orderBy(notifications, 'created_at')).map(
+ notifications.map(
notification => (
<Notification
key={notification.id}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment