FIX: Progress was broken on mobile

This commit is contained in:
Robin Ward 2016-05-19 17:19:49 -04:00
parent a8251b3036
commit fc4dc76f42
No known key found for this signature in database
GPG Key ID: 0E091E2B4ED1B83D
4 changed files with 36 additions and 24 deletions

View File

@ -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() {

View File

@ -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');
},

View File

@ -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}}

View File

@ -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;
}