FIX: Jumping to new posts was broken

This commit is contained in:
Robin Ward 2016-02-12 12:37:00 -05:00
parent 560e910c6c
commit d08007f505
4 changed files with 19 additions and 21 deletions

View file

@ -1,3 +1,4 @@
import DiscourseURL from 'discourse/lib/url';
import { keyDirty } from 'discourse/widgets/widget';
import MountWidget from 'discourse/components/mount-widget';
@ -129,6 +130,17 @@ export default MountWidget.extend({
$(window).bind('scroll.post-stream', debouncedScroll);
this._scrollTriggered();
this.appEvents.on('post-stream:posted', staged => {
const disableJumpReply = this.currentUser.get('disable_jump_reply');
this.queueRerender(() => {
if (staged && !disableJumpReply) {
const postNumber = staged.get('post_number');
DiscourseURL.jumpToPost(postNumber, { skipIfOnScreen: true });
}
});
});
this.$().on('mouseenter.post-stream', 'button.widget-button', e => {
$('button.widget-button').removeClass('d-hover');
$(e.target).addClass('d-hover');
@ -154,6 +166,7 @@ export default MountWidget.extend({
this.$().off('mouseenter.post-stream');
this.$().off('mouseleave.post-stream');
this.appEvents.off('post-stream:refresh');
this.appEvents.off('post-stream:posted');
}
});

View file

@ -263,7 +263,6 @@ export default Ember.Controller.extend({
}
var staged = false;
const disableJumpReply = Discourse.User.currentProp('disable_jump_reply');
// TODO: This should not happen in model
const imageSizes = {};
@ -290,6 +289,9 @@ export default Ember.Controller.extend({
}
self.appEvents.trigger('post-stream:refresh');
if (result.responseJson.action === "create_post") {
self.appEvents.trigger('post:highlight', result.payload.post_number);
}
self.close();
const currentUser = Discourse.User.current();
@ -299,14 +301,6 @@ export default Ember.Controller.extend({
currentUser.set('reply_count', currentUser.get('reply_count') + 1);
}
// TODO disableJumpReply is super crude, it needs to provide some sort
// of notification to the end user
if (!composer.get('replyingToTopic') || !disableJumpReply) {
const post = result.target;
if (post && !staged) {
DiscourseURL.routeTo(post.get('url'));
}
}
}).catch(function(error) {
composer.set('disableDrafts', false);
self.appEvents.one('composer:opened', () => bootbox.alert(error));
@ -317,18 +311,10 @@ export default Ember.Controller.extend({
staged = composer.get('stagedPost');
}
Em.run.schedule('afterRender', function() {
if (staged && !disableJumpReply) {
const postNumber = staged.get('post_number');
DiscourseURL.jumpToPost(postNumber, { skipIfOnScreen: true });
self.appEvents.trigger('post:highlight', postNumber);
}
});
this.appEvents.trigger('post-stream:posted', staged);
this.messageBus.pause();
promise.finally(function(){
self.messageBus.resume();
});
promise.finally(() => this.messageBus.resume());
return promise;
},

View file

@ -363,7 +363,6 @@ export default RestModel.extend({
// Commit the post we staged. Call this after a save succeeds.
commitPost(post) {
if (this.get('topic.id') === post.get('topic_id')) {
if (this.get('loadedAllPosts')) {
this.appendPost(post);

View file

@ -185,7 +185,7 @@ function highlight(postNumber) {
});
}
listenForViewEvent(TopicView, 'post:highlight', function(postNumber) {
listenForViewEvent(TopicView, 'post:highlight', postNumber => {
Ember.run.scheduleOnce('afterRender', null, highlight, postNumber);
});