UX: navigate to staged posts faster right away

stop with the blue unread circle on new posts
This commit is contained in:
Sam 2015-03-06 14:16:47 +11:00
parent 34294ca748
commit de107a60c2
3 changed files with 36 additions and 11 deletions

View File

@ -216,7 +216,9 @@ export default DiscourseController.extend({
}
}
return composer.save({
var staged = false,
disableJumpReply = Discourse.User.currentProp('disable_jump_reply');
var promise = composer.save({
imageSizes: this.get('view').imageSizes(),
editReason: this.get("editReason")
}).then(function(opts) {
@ -236,8 +238,8 @@ export default DiscourseController.extend({
currentUser.set('reply_count', currentUser.get('reply_count') + 1);
}
if ((!composer.get('replyingToTopic')) || (!Discourse.User.currentProp('disable_jump_reply'))) {
if (opts.post) {
if (!composer.get('replyingToTopic') || !disableJumpReply) {
if (opts.post && !staged) {
Discourse.URL.routeTo(opts.post.get('url'));
}
}
@ -245,6 +247,18 @@ export default DiscourseController.extend({
composer.set('disableDrafts', false);
bootbox.alert(error);
});
staged = composer.get('stagedPost');
Em.run.schedule('afterRender', function() {
if (staged && !disableJumpReply) {
var postNumber = staged.get('post_number');
Discourse.URL.jumpToPost(postNumber, {skipIfOnScreen: true});
self.appEvents.trigger('post:highlight', postNumber);
}
});
return promise;
},
/**

View File

@ -429,7 +429,8 @@ Discourse.Composer = Discourse.Model.extend({
reply: null,
post: null,
title: null,
editReason: null
editReason: null,
stagedPost: false
});
},
@ -518,6 +519,7 @@ Discourse.Composer = Discourse.Model.extend({
admin: currentUser.get('admin'),
yours: true,
newPost: true,
read: true
});
this.serialize(_create_serializer, createdPost);
@ -532,6 +534,7 @@ Discourse.Composer = Discourse.Model.extend({
});
}
var state = null;
// If we're in a topic, we can append the post instantly.
if (postStream) {
@ -545,16 +548,18 @@ Discourse.Composer = Discourse.Model.extend({
// Furthermore calculating cooked is very complicated, especially since
// we would need to handle oneboxes and other bits that are not even in the
// engine, staging will just cause a blank post to render
if (!_.isEmpty(createdPost.get('cooked')) && !postStream.stagePost(createdPost, currentUser)) {
if (!_.isEmpty(createdPost.get('cooked'))) {
state = postStream.stagePost(createdPost, currentUser);
if(state === "alreadyStaging"){
return;
}
// If we can't stage the post, return and don't save. We're likely currently
// staging a post.
return;
}
}
var composer = this;
return new Ember.RSVP.Promise(function(resolve, reject) {
var promise = new Ember.RSVP.Promise(function(resolve, reject) {
composer.set('composeState', SAVING);
createdPost.save(function(result) {
@ -613,6 +618,10 @@ Discourse.Composer = Discourse.Model.extend({
reject(parsedError);
});
});
composer.set("stagedPost", state === "staged" && createdPost);
return promise;
},
getCookedHtml: function() {

View File

@ -295,7 +295,8 @@ const PostStream = Ember.Object.extend({
**/
stagePost(post, user) {
// We can't stage two posts simultaneously
if (this.get('stagingPost')) { return false; }
if (this.get('stagingPost')) { return "alreadyStaging"; }
this.set('stagingPost', true);
const topic = this.get('topic');
@ -317,9 +318,10 @@ const PostStream = Ember.Object.extend({
if (this.get('loadedAllPosts')) {
this.appendPost(post);
this.get('stream').addObject(post.get('id'));
return "staged";
}
return true;
return "offScreen";
},
// Commit the post we staged. Call this after a save succeeds.