mirror of
https://github.com/flarum/framework.git
synced 2025-06-01 21:13:24 +08:00
New look for notifications
This commit is contained in:
@ -4,18 +4,11 @@ import username from 'flarum/helpers/username';
|
||||
export default class NotificationDiscussionRenamed extends Notification {
|
||||
view() {
|
||||
var notification = this.props.notification;
|
||||
var discussion = notification.subject();
|
||||
|
||||
return super.view({
|
||||
href: app.route('discussion.near', {
|
||||
id: discussion.id(),
|
||||
slug: discussion.slug(),
|
||||
near: notification.content().number
|
||||
}),
|
||||
config: m.route,
|
||||
title: notification.content().oldTitle,
|
||||
href: app.route.discussion(notification.subject(), notification.content().postNumber),
|
||||
icon: 'pencil',
|
||||
content: ['Renamed by ', username(notification.sender())]
|
||||
content: [username(notification.sender()), ' renamed']
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -9,16 +9,13 @@ export default class Notification extends Component {
|
||||
var notification = this.props.notification;
|
||||
|
||||
return m('div.notification.notification-'+dasherize(notification.contentType()), {
|
||||
classNames: !notification.isRead() ? 'unread' : '',
|
||||
className: !notification.isRead() ? 'unread' : '',
|
||||
onclick: this.read.bind(this)
|
||||
}, m('a', {href: args.href, config: args.config}, [
|
||||
avatar(notification.sender()),
|
||||
m('h3.notification-title', args.title),
|
||||
m('div.notification-info', [
|
||||
icon(args.icon), ' ',
|
||||
args.content, ' ',
|
||||
humanTime(notification.time())
|
||||
])
|
||||
}, m('a', {href: args.href, config: args.config || m.route}, [
|
||||
avatar(notification.sender()), ' ',
|
||||
icon(args.icon+' icon'), ' ',
|
||||
m('span.content', args.content), ' ',
|
||||
humanTime(notification.time())
|
||||
]));
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ import ActionButton from 'flarum/components/action-button';
|
||||
import ItemList from 'flarum/utils/item-list';
|
||||
import Separator from 'flarum/components/separator';
|
||||
import LoadingIndicator from 'flarum/components/loading-indicator';
|
||||
import Discussion from 'flarum/models/discussion';
|
||||
|
||||
export default class UserNotifications extends Component {
|
||||
constructor(props) {
|
||||
@ -18,6 +19,21 @@ export default class UserNotifications extends Component {
|
||||
view() {
|
||||
var user = this.props.user;
|
||||
|
||||
var groups = [];
|
||||
if (app.cache.notifications) {
|
||||
var groupsObject = {};
|
||||
app.cache.notifications.forEach(notification => {
|
||||
var subject = notification.subject();
|
||||
var discussion = subject instanceof Discussion ? subject : (subject.discussion && subject.discussion());
|
||||
var key = discussion ? discussion.id() : 0;
|
||||
groupsObject[key] = groupsObject[key] || {discussion: discussion, notifications: []};
|
||||
groupsObject[key].notifications.push(notification);
|
||||
});
|
||||
for (var i in groupsObject) {
|
||||
groups.push(groupsObject[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return DropdownButton.component({
|
||||
className: 'notifications',
|
||||
buttonClass: 'btn btn-default btn-rounded btn-naked btn-icon'+(user.unreadNotificationsCount() ? ' unread' : ''),
|
||||
@ -37,19 +53,27 @@ export default class UserNotifications extends Component {
|
||||
}),
|
||||
m('h4', 'Notifications')
|
||||
]),
|
||||
m('ul.notifications-list', app.cache.notifications
|
||||
? app.cache.notifications.map(notification => {
|
||||
var NotificationComponent = app.notificationComponentRegistry[notification.contentType()];
|
||||
return NotificationComponent ? m('li', NotificationComponent.component({notification})) : '';
|
||||
m('div.notifications-content', groups.length
|
||||
? groups.map(group => {
|
||||
return m('div.notification-group', [
|
||||
group.discussion ? m('a.notification-group-header', {
|
||||
href: app.route.discussion(group.discussion),
|
||||
config: m.route
|
||||
}, group.discussion.title()) : m('div.notification-group-header', app.config['forum_title']),
|
||||
m('ul.notifications-list', group.notifications.map(notification => {
|
||||
var NotificationComponent = app.notificationComponentRegistry[notification.contentType()];
|
||||
return NotificationComponent ? m('li', NotificationComponent.component({notification})) : '';
|
||||
}))
|
||||
])
|
||||
})
|
||||
: (!this.loading() ? m('li.no-notifications', 'No Notifications') : '')),
|
||||
: (!this.loading() ? m('div.no-notifications', 'No Notifications') : '')),
|
||||
this.loading() ? LoadingIndicator.component() : ''
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
load() {
|
||||
if (!app.cache.notifications) {
|
||||
if (!app.cache.notifications || this.props.user.unreadNotificationsCount()) {
|
||||
var component = this;
|
||||
this.loading(true);
|
||||
m.redraw();
|
||||
|
Reference in New Issue
Block a user