Skip to content

Commit

Permalink
UX: Timeline should jump to the bottom of the post in single-post top…
Browse files Browse the repository at this point in the history
…ics (#10503)
  • Loading branch information
hnb-ku committed Aug 25, 2020
1 parent 80b92cf commit 66aa94c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 5 additions & 1 deletion app/assets/javascripts/discourse/app/controllers/topic.js
Expand Up @@ -721,8 +721,12 @@ export default Controller.extend(bufferedProperty("model"), {
},

jumpBottom() {
// When a topic only has one lengthy post
const jumpEnd = this.model.highest_post_number === 1 ? true : false;

DiscourseURL.routeTo(this.get("model.lastPostUrl"), {
skipIfOnScreen: false
skipIfOnScreen: false,
jumpEnd
});
},

Expand Down
11 changes: 6 additions & 5 deletions app/assets/javascripts/discourse/app/lib/url.js
Expand Up @@ -35,6 +35,11 @@ const SERVER_SIDE_ONLY = [
/^\/invites\//
];

// The amount of height (in pixles) that we factor in when jumpEnd is called so
// that we show a little bit of the post text even on mobile devices instead of
// scrolling to "suggested topics".
const JUMP_END_BUFFER = 250;

export function rewritePath(path) {
const params = path.split("?");

Expand Down Expand Up @@ -110,13 +115,9 @@ const DiscourseURL = EmberObject.extend({
let holderHeight = $holder.height();
let windowHeight = $(window).height() - offsetCalculator();

// scroll to the bottom of the post and if the post is yuge we go back up the
// timeline by a small % of the post height so we can see the bottom of the text.
//
// otherwise just jump to the top of the post using the lock & holder method.
if (holderHeight > windowHeight) {
$(window).scrollTop(
$holder.offset().top + (holderHeight - holderHeight / 10)
$holder.offset().top + (holderHeight - JUMP_END_BUFFER)
);
_transitioning = false;
return;
Expand Down

1 comment on commit 66aa94c

@discoursebot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/scroll-to-bottom-of-a-topic-with-1-post/161173/8

Please sign in to comment.