FEATURE: add a Dismiss link to user menu that dismisses all notifications
This commit is contained in:
parent
8f560f0bf4
commit
814502f7bb
|
@ -1,6 +1,7 @@
|
||||||
import { createWidget } from 'discourse/widgets/widget';
|
import { createWidget } from 'discourse/widgets/widget';
|
||||||
import { h } from 'virtual-dom';
|
import { h } from 'virtual-dom';
|
||||||
import { formatUsername } from 'discourse/lib/utilities';
|
import { formatUsername } from 'discourse/lib/utilities';
|
||||||
|
import { ajax } from 'discourse/lib/ajax';
|
||||||
|
|
||||||
let extraGlyphs;
|
let extraGlyphs;
|
||||||
|
|
||||||
|
@ -87,6 +88,46 @@ createWidget('user-menu-links', {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
createWidget('user-menu-dismiss-link', {
|
||||||
|
tagName: 'div.dismiss-link',
|
||||||
|
buildKey: () => 'user-menu-dismiss-link',
|
||||||
|
|
||||||
|
defaultState() {
|
||||||
|
return { showDismiss: false };
|
||||||
|
},
|
||||||
|
|
||||||
|
html() {
|
||||||
|
if (this.state.showDismiss) {
|
||||||
|
return h('ul.menu-links',
|
||||||
|
h('li',
|
||||||
|
this.attach('link', {
|
||||||
|
action: 'dismissNotifications',
|
||||||
|
className: 'dismiss',
|
||||||
|
icon: 'check',
|
||||||
|
label: 'user.dismiss'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
showDismissLink() {
|
||||||
|
this.state.showDismiss = true;
|
||||||
|
this.scheduleRerender();
|
||||||
|
},
|
||||||
|
|
||||||
|
dismissNotifications() {
|
||||||
|
ajax('/notifications/mark-read', { method: 'PUT' }).then(() => {
|
||||||
|
userNotifications.notificationsChanged();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let userNotifications = null,
|
||||||
|
dismissLink = null;
|
||||||
|
|
||||||
export default createWidget('user-menu', {
|
export default createWidget('user-menu', {
|
||||||
tagName: 'div.user-menu',
|
tagName: 'div.user-menu',
|
||||||
|
|
||||||
|
@ -96,16 +137,26 @@ export default createWidget('user-menu', {
|
||||||
|
|
||||||
panelContents() {
|
panelContents() {
|
||||||
const path = this.currentUser.get('path');
|
const path = this.currentUser.get('path');
|
||||||
|
userNotifications = this.attach('user-notifications', { path });
|
||||||
|
dismissLink = this.attach('user-menu-dismiss-link');
|
||||||
|
|
||||||
return [this.attach('user-menu-links', { path }),
|
return [
|
||||||
this.attach('user-notifications', { path }),
|
this.attach('user-menu-links', { path }),
|
||||||
h('div.logout-link', [
|
userNotifications,
|
||||||
h('ul.menu-links',
|
h('div.logout-link', [
|
||||||
h('li', this.attach('link', { action: 'logout',
|
h('ul.menu-links',
|
||||||
className: 'logout',
|
h('li',
|
||||||
icon: 'sign-out',
|
this.attach('link', {
|
||||||
label: 'user.log_out' })))
|
action: 'logout',
|
||||||
])];
|
className: 'logout',
|
||||||
|
icon: 'sign-out',
|
||||||
|
label: 'user.log_out'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
)
|
||||||
|
]),
|
||||||
|
dismissLink
|
||||||
|
];
|
||||||
},
|
},
|
||||||
|
|
||||||
html() {
|
html() {
|
||||||
|
@ -117,5 +168,9 @@ export default createWidget('user-menu', {
|
||||||
|
|
||||||
clickOutside() {
|
clickOutside() {
|
||||||
this.sendWidgetAction('toggleUserMenu');
|
this.sendWidgetAction('toggleUserMenu');
|
||||||
|
},
|
||||||
|
|
||||||
|
notificationsLoaded() {
|
||||||
|
dismissLink.showDismissLink();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -50,6 +50,9 @@ export default createWidget('user-notifications', {
|
||||||
}).finally(() => {
|
}).finally(() => {
|
||||||
state.loading = false;
|
state.loading = false;
|
||||||
state.loaded = true;
|
state.loaded = true;
|
||||||
|
if (state.notifications.get('length') > 0) {
|
||||||
|
this.sendWidgetAction('notificationsLoaded');
|
||||||
|
}
|
||||||
this.scheduleRerender();
|
this.scheduleRerender();
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -257,6 +257,13 @@
|
||||||
/* as a big ol' click target, don't let text inside be selected */
|
/* as a big ol' click target, don't let text inside be selected */
|
||||||
@include unselectable;
|
@include unselectable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.logout-link, .dismiss-link {
|
||||||
|
display: inline-block;
|
||||||
|
}
|
||||||
|
.dismiss-link {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.notifications .logout {
|
.notifications .logout {
|
||||||
|
|
|
@ -590,6 +590,7 @@ en:
|
||||||
enable: "Enable Notifications"
|
enable: "Enable Notifications"
|
||||||
currently_disabled: ""
|
currently_disabled: ""
|
||||||
each_browser_note: "Note: You have to change this setting on every browser you use."
|
each_browser_note: "Note: You have to change this setting on every browser you use."
|
||||||
|
dismiss: 'Dismiss'
|
||||||
dismiss_notifications: "Dismiss All"
|
dismiss_notifications: "Dismiss All"
|
||||||
dismiss_notifications_tooltip: "Mark all unread notifications as read"
|
dismiss_notifications_tooltip: "Mark all unread notifications as read"
|
||||||
first_notification: "Your first notification! Select it to begin."
|
first_notification: "Your first notification! Select it to begin."
|
||||||
|
|
|
@ -11,6 +11,7 @@ widgetTest('basics', {
|
||||||
assert.ok(this.$('.user-bookmarks-link').length);
|
assert.ok(this.$('.user-bookmarks-link').length);
|
||||||
assert.ok(this.$('.user-preferences-link').length);
|
assert.ok(this.$('.user-preferences-link').length);
|
||||||
assert.ok(this.$('.notifications').length);
|
assert.ok(this.$('.notifications').length);
|
||||||
|
assert.ok(this.$('.dismiss-link').length);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue