FIX: bookmark topic was not working intuitively
- explicitly call out "clear bookmarks" - correct keyboard shortcuts - properly remove bookmarks when toggeling
This commit is contained in:
@@ -17,7 +17,6 @@ var PATH_BINDINGS = {
|
||||
},
|
||||
|
||||
CLICK_BINDINGS = {
|
||||
'f': '#topic-footer-buttons button.bookmark', // bookmark topic
|
||||
'm m': 'div.notification-options li[data-id="0"] a', // mark topic as muted
|
||||
'm r': 'div.notification-options li[data-id="1"] a', // mark topic as regular
|
||||
'm t': 'div.notification-options li[data-id="2"] a', // mark topic as tracking
|
||||
@@ -50,7 +49,8 @@ var PATH_BINDINGS = {
|
||||
'command+f': 'showBuiltinSearch',
|
||||
'?': 'showHelpModal', // open keyboard shortcut help
|
||||
'q': 'quoteReply',
|
||||
'b': 'toggleBookmark'
|
||||
'b': 'toggleBookmark',
|
||||
'f': 'toggleBookmarkTopic'
|
||||
};
|
||||
|
||||
|
||||
@@ -70,6 +70,16 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
||||
this.sendToTopicListItemView('toggleBookmark');
|
||||
},
|
||||
|
||||
toggleBookmarkTopic: function(){
|
||||
var topic = this.currentTopic();
|
||||
// BIG hack, need a cleaner way
|
||||
if(topic && $('.posts-wrapper').length > 0) {
|
||||
topic.toggleBookmark();
|
||||
} else {
|
||||
this.sendToTopicListItemView('toggleBookmark');
|
||||
}
|
||||
},
|
||||
|
||||
quoteReply: function(){
|
||||
$('.topic-post.selected button.create').click();
|
||||
// lazy but should work for now
|
||||
@@ -170,6 +180,16 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
||||
}
|
||||
},
|
||||
|
||||
currentTopic: function(){
|
||||
var topicController = this.container.lookup('controller:topic');
|
||||
if(topicController) {
|
||||
var topic = topicController.get('model');
|
||||
if(topic){
|
||||
return topic;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
sendToSelectedPost: function(action){
|
||||
var container = this.container;
|
||||
// TODO: We should keep track of the post without a CSS class
|
||||
|
||||
@@ -413,15 +413,27 @@ Discourse.Post = Discourse.Model.extend({
|
||||
},
|
||||
|
||||
toggleBookmark: function() {
|
||||
var self = this;
|
||||
var self = this,
|
||||
bookmarkedTopic;
|
||||
|
||||
this.toggleProperty("bookmarked");
|
||||
if (this.get("post_number") === 1) { this.toggleProperty("topic.bookmarked"); }
|
||||
|
||||
return Discourse.Post.updateBookmark(this.get('id'), this.get('bookmarked')).catch(function() {
|
||||
self.toggleProperty("bookmarked");
|
||||
if (this.get("post_number") === 1) { this.toggleProperty("topic.bookmarked"); }
|
||||
});
|
||||
if(this.get("bookmarked") && !this.get("topic.bookmarked")) {
|
||||
this.set("topic.bookmarked", true);
|
||||
bookmarkedTopic = true;
|
||||
}
|
||||
|
||||
// need to wait to hear back from server (stuff may not be loaded)
|
||||
|
||||
return Discourse.Post.updateBookmark(this.get('id'), this.get('bookmarked'))
|
||||
.then(function(result){
|
||||
self.set("topic.bookmarked", result.topic_bookmarked);
|
||||
})
|
||||
.catch(function(e) {
|
||||
self.toggleProperty("bookmarked");
|
||||
if (bookmarkedTopic) {self.set("topic.bookmarked", false); }
|
||||
throw e;
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -183,18 +183,48 @@ const Topic = Discourse.Model.extend({
|
||||
}.property('word_count'),
|
||||
|
||||
toggleBookmark() {
|
||||
const self = this, firstPost = this.get("postStream.posts")[0];
|
||||
const self = this,
|
||||
stream = this.get('postStream'),
|
||||
posts = Em.get(stream, 'posts'),
|
||||
firstPost = posts &&
|
||||
posts[0] &&
|
||||
posts[0].get('post_number') === 1 &&
|
||||
posts[0],
|
||||
bookmark = !self.get('bookmarked');
|
||||
|
||||
var path = bookmark ? '/bookmark' : '/remove_bookmarks';
|
||||
var unbookmarkedPosts = [],
|
||||
bookmarkedPost;
|
||||
|
||||
this.toggleProperty('bookmarked');
|
||||
if (this.get("postStream.firstPostPresent")) { firstPost.toggleProperty("bookmarked"); }
|
||||
|
||||
if (bookmark && firstPost) {
|
||||
firstPost.set('bookmarked', true);
|
||||
bookmarkedPost = firstPost;
|
||||
}
|
||||
|
||||
return Discourse.ajax('/t/' + this.get('id') + '/bookmark', {
|
||||
if (!bookmark && posts) {
|
||||
posts.forEach(function(post){
|
||||
if(post.get('bookmarked')){
|
||||
post.set('bookmarked', false);
|
||||
unbookmarkedPosts.push(post);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return Discourse.ajax('/t/' + this.get('id') + path, {
|
||||
type: 'PUT',
|
||||
data: { bookmarked: self.get('bookmarked') },
|
||||
}).catch(function(error) {
|
||||
|
||||
self.toggleProperty('bookmarked');
|
||||
if (self.get("postStream.firstPostPresent")) { firstPost.toggleProperty('bookmarked'); }
|
||||
|
||||
if(bookmarkedPost) {
|
||||
bookmarkedPost.set('bookmarked', false);
|
||||
}
|
||||
|
||||
unbookmarkedPosts.forEach(function(p){
|
||||
p.set('bookmarked', true);
|
||||
});
|
||||
|
||||
let showGenericError = true;
|
||||
if (error && error.responseText) {
|
||||
@@ -207,6 +237,8 @@ const Topic = Discourse.Model.extend({
|
||||
if(showGenericError){
|
||||
bootbox.alert(I18n.t('generic_error'));
|
||||
}
|
||||
|
||||
throw error;
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
@@ -2,9 +2,12 @@ import ButtonView from 'discourse/views/button';
|
||||
|
||||
export default ButtonView.extend({
|
||||
classNames: ['bookmark'],
|
||||
textKey: 'bookmarked.title',
|
||||
attributeBindings: ['disabled'],
|
||||
|
||||
textKey: function() {
|
||||
return this.get('controller.bookmarked') ? 'bookmarked.clear_bookmarks' : 'bookmarked.title';
|
||||
}.property('controller.bookmarked'),
|
||||
|
||||
rerenderTriggers: ['controller.bookmarked'],
|
||||
|
||||
helpKey: function() {
|
||||
|
||||
Reference in New Issue
Block a user