From fc4dc76f422f5fada71580cbcd11cd0935c6cff1 Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 19 May 2016 17:19:49 -0400 Subject: [PATCH] FIX: Progress was broken on mobile --- .../components/topic-progress.js.es6 | 2 +- .../discourse/controllers/topic.js.es6 | 50 +++++++++++-------- .../javascripts/discourse/templates/topic.hbs | 2 + .../discourse/widgets/topic-timeline.js.es6 | 6 +-- 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/app/assets/javascripts/discourse/components/topic-progress.js.es6 b/app/assets/javascripts/discourse/components/topic-progress.js.es6 index a11585b2274..98aa8b2297e 100644 --- a/app/assets/javascripts/discourse/components/topic-progress.js.es6 +++ b/app/assets/javascripts/discourse/components/topic-progress.js.es6 @@ -171,7 +171,7 @@ export default Ember.Component.extend({ } this.set('toPostIndex', postIndex); this.set('expanded', false); - this.sendAction('jumpToPost', postIndex); + this.sendAction('jumpToIndex', postIndex); }, jumpTop() { diff --git a/app/assets/javascripts/discourse/controllers/topic.js.es6 b/app/assets/javascripts/discourse/controllers/topic.js.es6 index e2812f42d4a..ab614e9db09 100644 --- a/app/assets/javascripts/discourse/controllers/topic.js.es6 +++ b/app/assets/javascripts/discourse/controllers/topic.js.es6 @@ -191,9 +191,13 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { if (!post) { return; } const postNumber = post.get('post_number'); - this.set('model.currentPost', postNumber); + const model = this.get('model'); + model.set('currentPost', postNumber); this.send('postChangedRoute', postNumber); - this.appEvents.trigger('topic:current-post-changed', postNumber); + + const postStream = model.get('postStream'); + + this.appEvents.trigger('topic:current-post-changed', postStream.progressIndexOfPost(post)); }, // Called the the topmost visible post on the page changes. @@ -391,25 +395,12 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { } }, + jumpToIndex(index) { + this._jumpToPostId(this.get('model.postStream.stream')[index-1]); + }, + jumpToPost(postNumber) { - const topic = this.get('model'); - const stream = topic.get('postStream'); - const postId = stream.findPostIdForPostNumber(postNumber); - - if (!postId) { - Em.Logger.warn("jump-post code broken - requested an index outside the stream array"); - return; - } - - const post = stream.findLoadedPost(postId); - if (post) { - DiscourseURL.routeTo(topic.urlForPostNumber(post.get('post_number'))); - } else { - // need to load it - stream.findPostsByIds([postId]).then(arr => { - DiscourseURL.routeTo(topic.urlForPostNumber(arr[0].get('post_number'))); - }); - } + this._jumpToPostId(this.get('model.postStream').findPostIdForPostNumber(postNumber)); }, jumpTop() { @@ -647,6 +638,25 @@ export default Ember.Controller.extend(SelectedPostsCount, BufferedContent, { } }, + _jumpToPostId(postId) { + if (!postId) { + Ember.Logger.warn("jump-post code broken - requested an index outside the stream array"); + return; + } + + const topic = this.get('model'); + const postStream = topic.get('postStream'); + const post = postStream.findLoadedPost(postId); + if (post) { + DiscourseURL.routeTo(topic.urlForPostNumber(post.get('post_number'))); + } else { + // need to load it + postStream.findPostsByIds([postId]).then(arr => { + DiscourseURL.routeTo(topic.urlForPostNumber(arr[0].get('post_number'))); + }); + } + }, + togglePinnedState() { this.send('togglePinnedForUser'); }, diff --git a/app/assets/javascripts/discourse/templates/topic.hbs b/app/assets/javascripts/discourse/templates/topic.hbs index aa46c38f445..7f307113ffb 100644 --- a/app/assets/javascripts/discourse/templates/topic.hbs +++ b/app/assets/javascripts/discourse/templates/topic.hbs @@ -76,12 +76,14 @@ loading=model.postStream.loading jumpTop="jumpTop" jumpToPost="jumpToPost" + jumpToIndex="jumpToIndex" jumpBottom="jumpBottom" replyToPost="replyToPost"}} {{else}} {{topic-progress topic=model jumpTop="jumpTop" jumpToPost="jumpToPost" + jumpToIndex="jumpToIndex" jumpBottom="jumpBottom"}} {{/if}} {{conditional-loading-spinner condition=model.postStream.loadingAbove}} diff --git a/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6 b/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6 index 97b69788c43..590601138fa 100644 --- a/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6 +++ b/app/assets/javascripts/discourse/widgets/topic-timeline.js.es6 @@ -90,7 +90,7 @@ createWidget('timeline-scrollarea', { const { attrs } = this; const percentage = this.state.percentage; const postStream = attrs.topic.get('postStream'); - const total = attrs.topic.get('highest_post_number'); + const total = postStream.get('filteredPostsCount'); let current = Math.round(total * percentage); if (current < 1) { current = 1; } @@ -157,13 +157,13 @@ createWidget('timeline-scrollarea', { commit() { const position = this.position(); - this.sendWidgetAction('jumpToPost', position.current); + this.sendWidgetAction('jumpToIndex', position.current); }, topicCurrentPostChanged(postNumber) { // If the post number didn't change keep our scroll position if (postNumber !== this.state.scrolledPost) { - const total = this.attrs.topic.get('highest_post_number'); + const total = this.attrs.topic.get('postStream.filteredPostsCount'); const perc = postNumber === 1 ? 0.0 : parseFloat(postNumber) / total; this.state.percentage = perc; }