mirror of
https://github.com/flarum/core.git
synced 2025-07-27 19:50:20 +02: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 {
|
export default class NotificationDiscussionRenamed extends Notification {
|
||||||
view() {
|
view() {
|
||||||
var notification = this.props.notification;
|
var notification = this.props.notification;
|
||||||
var discussion = notification.subject();
|
|
||||||
|
|
||||||
return super.view({
|
return super.view({
|
||||||
href: app.route('discussion.near', {
|
href: app.route.discussion(notification.subject(), notification.content().postNumber),
|
||||||
id: discussion.id(),
|
|
||||||
slug: discussion.slug(),
|
|
||||||
near: notification.content().number
|
|
||||||
}),
|
|
||||||
config: m.route,
|
|
||||||
title: notification.content().oldTitle,
|
|
||||||
icon: 'pencil',
|
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;
|
var notification = this.props.notification;
|
||||||
|
|
||||||
return m('div.notification.notification-'+dasherize(notification.contentType()), {
|
return m('div.notification.notification-'+dasherize(notification.contentType()), {
|
||||||
classNames: !notification.isRead() ? 'unread' : '',
|
className: !notification.isRead() ? 'unread' : '',
|
||||||
onclick: this.read.bind(this)
|
onclick: this.read.bind(this)
|
||||||
}, m('a', {href: args.href, config: args.config}, [
|
}, m('a', {href: args.href, config: args.config || m.route}, [
|
||||||
avatar(notification.sender()),
|
avatar(notification.sender()), ' ',
|
||||||
m('h3.notification-title', args.title),
|
icon(args.icon+' icon'), ' ',
|
||||||
m('div.notification-info', [
|
m('span.content', args.content), ' ',
|
||||||
icon(args.icon), ' ',
|
|
||||||
args.content, ' ',
|
|
||||||
humanTime(notification.time())
|
humanTime(notification.time())
|
||||||
])
|
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -7,6 +7,7 @@ import ActionButton from 'flarum/components/action-button';
|
|||||||
import ItemList from 'flarum/utils/item-list';
|
import ItemList from 'flarum/utils/item-list';
|
||||||
import Separator from 'flarum/components/separator';
|
import Separator from 'flarum/components/separator';
|
||||||
import LoadingIndicator from 'flarum/components/loading-indicator';
|
import LoadingIndicator from 'flarum/components/loading-indicator';
|
||||||
|
import Discussion from 'flarum/models/discussion';
|
||||||
|
|
||||||
export default class UserNotifications extends Component {
|
export default class UserNotifications extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@@ -18,6 +19,21 @@ export default class UserNotifications extends Component {
|
|||||||
view() {
|
view() {
|
||||||
var user = this.props.user;
|
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({
|
return DropdownButton.component({
|
||||||
className: 'notifications',
|
className: 'notifications',
|
||||||
buttonClass: 'btn btn-default btn-rounded btn-naked btn-icon'+(user.unreadNotificationsCount() ? ' unread' : ''),
|
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('h4', 'Notifications')
|
||||||
]),
|
]),
|
||||||
m('ul.notifications-list', app.cache.notifications
|
m('div.notifications-content', groups.length
|
||||||
? app.cache.notifications.map(notification => {
|
? 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()];
|
var NotificationComponent = app.notificationComponentRegistry[notification.contentType()];
|
||||||
return NotificationComponent ? m('li', NotificationComponent.component({notification})) : '';
|
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() : ''
|
this.loading() ? LoadingIndicator.component() : ''
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
load() {
|
load() {
|
||||||
if (!app.cache.notifications) {
|
if (!app.cache.notifications || this.props.user.unreadNotificationsCount()) {
|
||||||
var component = this;
|
var component = this;
|
||||||
this.loading(true);
|
this.loading(true);
|
||||||
m.redraw();
|
m.redraw();
|
||||||
|
@@ -44,6 +44,7 @@
|
|||||||
text-transform: uppercase;
|
text-transform: uppercase;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
color: @fl-body-muted-color;
|
||||||
}
|
}
|
||||||
& .btn {
|
& .btn {
|
||||||
float: right;
|
float: right;
|
||||||
@@ -51,12 +52,10 @@
|
|||||||
margin-right: -5px;
|
margin-right: -5px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.notifications-list {
|
.notifications-content {
|
||||||
list-style: none;
|
|
||||||
margin: 0;
|
|
||||||
padding: 0;
|
|
||||||
max-height: 600px;
|
max-height: 600px;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
padding-bottom: 10px;
|
||||||
}
|
}
|
||||||
.no-notifications {
|
.no-notifications {
|
||||||
color: @fl-body-muted-color;
|
color: @fl-body-muted-color;
|
||||||
@@ -64,10 +63,32 @@
|
|||||||
padding: 50px 0;
|
padding: 50px 0;
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
.notification-group {
|
||||||
|
border-top: 1px solid @fl-body-secondary-color;
|
||||||
|
margin-top: -1px;
|
||||||
|
|
||||||
|
&:not(:last-child) {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.notification-group-header {
|
||||||
|
font-weight: bold;
|
||||||
|
color: @fl-body-heading-color !important;
|
||||||
|
padding: 8px 15px;
|
||||||
|
display: block;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
}
|
||||||
|
.notifications-list {
|
||||||
|
list-style: none;
|
||||||
|
margin: 0;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
.notification {
|
.notification {
|
||||||
& > a {
|
& > a {
|
||||||
display: block;
|
display: block;
|
||||||
padding: 15px 15px 15px 75px;
|
padding: 8px 15px 8px 75px;
|
||||||
color: @fl-body-muted-color;
|
color: @fl-body-muted-color;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|
||||||
@@ -80,26 +101,27 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
& .avatar {
|
& .avatar {
|
||||||
|
.avatar-size(24px);
|
||||||
float: left;
|
float: left;
|
||||||
margin-left: -60px;
|
margin: -2px 0 -2px -60px;
|
||||||
}
|
}
|
||||||
}
|
& .icon {
|
||||||
.notification-title {
|
float: left;
|
||||||
color: @fl-body-heading-color;
|
margin-left: -23px;
|
||||||
font-size: 13px;
|
|
||||||
font-weight: bold;
|
|
||||||
margin: 0 0 6px;
|
|
||||||
line-height: 1.5em;
|
|
||||||
}
|
|
||||||
.notification-info {
|
|
||||||
font-size: 12px;
|
|
||||||
|
|
||||||
& .fa {
|
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
margin-top: 2px;
|
||||||
}
|
}
|
||||||
& .username {
|
& .username {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
& .content {
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
|
& time {
|
||||||
|
font-size: 11px;
|
||||||
|
font-weight: bold;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@media @phone {
|
@media @phone {
|
||||||
.notification {
|
.notification {
|
||||||
|
Reference in New Issue
Block a user