UX: Timeline should jump to the bottom of the post in single-post topics (#10503)

UX: Timeline should jump to the bottom of the post in single-post topics (#10503)

diff --git a/app/assets/javascripts/discourse/app/controllers/topic.js b/app/assets/javascripts/discourse/app/controllers/topic.js
index 6337c8d..a1cdb9a 100644
--- a/app/assets/javascripts/discourse/app/controllers/topic.js
+++ b/app/assets/javascripts/discourse/app/controllers/topic.js
@@ -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
       });
     },
 
diff --git a/app/assets/javascripts/discourse/app/lib/url.js b/app/assets/javascripts/discourse/app/lib/url.js
index aa7fbb7..a7e5dcc 100644
--- a/app/assets/javascripts/discourse/app/lib/url.js
+++ b/app/assets/javascripts/discourse/app/lib/url.js
@@ -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("?");
 
@@ -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;

GitHub sha: 66aa94c5

1 Like

This commit appears in #10503 which was approved by eviltrout. It was merged by hnb-ku.

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