From 8226fca6edbbeda0b841467b7f9ba7520553c19c Mon Sep 17 00:00:00 2001 From: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com> Date: Thu, 2 Feb 2023 14:02:51 -0600 Subject: [PATCH] DEV: Update glimmer topic timeline visibility state when a post is created (#20145) # Problem Creating a post on a topic, where the timeline is not shown by default, does not update the visibility state dynamically. You must refresh the page to have the timeline appear. # Solution This PR hooks into the `post-stream:posted` app event and checks if we can now display the timeline after a post has been created. This will update the visibility state dynamically. --- .../discourse/app/components/topic-timeline/container.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/topic-timeline/container.js b/app/assets/javascripts/discourse/app/components/topic-timeline/container.js index 3d62f950af1..ec57c368dcd 100644 --- a/app/assets/javascripts/discourse/app/components/topic-timeline/container.js +++ b/app/assets/javascripts/discourse/app/components/topic-timeline/container.js @@ -45,6 +45,7 @@ export default class TopicTimelineScrollArea extends Component { this.appEvents.on("composer:opened", this.calculatePosition); this.appEvents.on("composer:resized", this.calculatePosition); this.appEvents.on("composer:closed", this.calculatePosition); + this.appEvents.on("post-stream:posted", this.calculatePosition); } this.calculatePosition(); @@ -55,8 +56,7 @@ export default class TopicTimelineScrollArea extends Component { return true; } - const streamLength = this.args.model.postStream?.stream?.length; - if (streamLength === 1) { + if (this.total === 1) { const postsWrapper = document.querySelector(".posts-wrapper"); if (postsWrapper && postsWrapper.offsetHeight < 1000) { return false; @@ -302,6 +302,7 @@ export default class TopicTimelineScrollArea extends Component { this.appEvents.off("composer:resized", this.calculatePosition); this.appEvents.off("composer:closed", this.calculatePosition); this.appEvents.off("topic:current-post-scrolled", this.postScrolled); + this.appEvents.off("post-stream:posted", this.calculatePosition); } }