From 145ee10f40dd9c2946f5f0cb98fec31c63a038da Mon Sep 17 00:00:00 2001 From: cpradio Date: Fri, 17 Jun 2016 14:39:45 -0400 Subject: [PATCH] FIX: Correct the topic notification keyboard shortcuts --- .../topic-notifications-button.js.es6 | 5 ++++ .../discourse/lib/keyboard-shortcuts.js.es6 | 24 +++++++++++++++---- .../widgets/topic-notifications-button.js.es6 | 8 +++++++ 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/assets/javascripts/discourse/components/topic-notifications-button.js.es6 b/app/assets/javascripts/discourse/components/topic-notifications-button.js.es6 index df4553a4735..e39f45fd9b8 100644 --- a/app/assets/javascripts/discourse/components/topic-notifications-button.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-notifications-button.js.es6 @@ -11,5 +11,10 @@ export default MountWidget.extend({ @observes('topic.details.notification_level') _triggerRerender() { this.queueRerender(); + }, + + didInsertElement() { + this._super(); + this.dispatch('topic-notifications-button:keyboard-trigger', 'topic-notifications-button'); } }); diff --git a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 index 9ef9f2e1709..70af9c9526c 100644 --- a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 +++ b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 @@ -32,10 +32,10 @@ const bindings = { 'j': {handler: 'selectDown', anonymous: true}, 'k': {handler: 'selectUp', anonymous: true}, 'l': {click: '.topic-post.selected button.toggle-like'}, - 'm m': {click: 'div.notification-options li[data-id="0"] a'}, // mark topic as muted - 'm r': {click: 'div.notification-options li[data-id="1"] a'}, // mark topic as regular - 'm t': {click: 'div.notification-options li[data-id="2"] a'}, // mark topic as tracking - 'm w': {click: 'div.notification-options li[data-id="3"] a'}, // mark topic as watching + 'm m': {handler: 'setTrackingToMuted'}, // mark topic as muted + 'm r': {handler: 'setTrackingToRegular'}, // mark topic as regular + 'm t': {handler: 'setTrackingToTracking'}, // mark topic as tracking + 'm w': {handler: 'setTrackingToWatching'}, // mark topic as watching 'o,enter': {click: '.topic-list tr.selected a.title', anonymous: true}, // open selected topic 'p': {handler: 'showCurrentUser'}, 'q': {handler: 'quoteReply'}, @@ -179,6 +179,22 @@ export default { this.container.lookup('controller:application').send('showKeyboardShortcutsHelp'); }, + setTrackingToMuted(event) { + this.appEvents.trigger('topic-notifications-button:keyboard-trigger', {type: 'notification', id: 0, event}); + }, + + setTrackingToRegular(event) { + this.appEvents.trigger('topic-notifications-button:keyboard-trigger', {type: 'notification', id: 1, event}); + }, + + setTrackingToTracking(event) { + this.appEvents.trigger('topic-notifications-button:keyboard-trigger', {type: 'notification', id: 2, event}); + }, + + setTrackingToWatching(event) { + this.appEvents.trigger('topic-notifications-button:keyboard-trigger', {type: 'notification', id: 3, event}); + }, + sendToTopicListItemView(action) { const elem = $('tr.selected.topic-list-item.ember-view')[0]; if (elem) { diff --git a/app/assets/javascripts/discourse/widgets/topic-notifications-button.js.es6 b/app/assets/javascripts/discourse/widgets/topic-notifications-button.js.es6 index 66223ebb40f..de8e538ee14 100644 --- a/app/assets/javascripts/discourse/widgets/topic-notifications-button.js.es6 +++ b/app/assets/javascripts/discourse/widgets/topic-notifications-button.js.es6 @@ -86,5 +86,13 @@ export default createWidget('topic-notifications-button', { notificationLevelChanged(id) { this.state.expanded = false; return this.attrs.topic.get('details').updateNotifications(id); + }, + + topicNotificationsButtonKeyboardTrigger(msg) { + switch(msg.type) { + case 'notification': + this.notificationLevelChanged(msg.id); + break; + } } });