This might be useful if the See x new or updated topic would be sticky to top below header so you see immediately while scrolling the topic list. When you click the bar it will jump to top to load the new or updated topics.
The other part (js) which is going to be a click function to jump to the top or scroll to top but I don’t know how to do or what is the best way to do this.
I found this section in template discovery/topics.hbs and discovery/categories.hbs. If modify the <a href to <a href="/" might work (not sure, i didn’t try) but with this every time loading just like clicking the logo.
Yeah, adding a URL will cause navigation since there’s no logic to intercept the event.
The link is calling an Ember action. All actions in Discourse are extendable. So, they act like customization hooks in a way. So how do you modify an action? Well, let’s check what it does first.
Search on Github or locally for the name of the action. Actions are always defined in JS files and referenced in handlebars. We want to see the definition, so we narrow down the search to JS files.
So, are we done? No. this breaks Discourse because you’re fully overriding the action. Clicking the link will now scroll to the list-controls element, but it won’t load the new topics. Why? Because the code in core is no longer being applied. I mean, this stuff
So, how do you fix that? With this simple line
this._super(...arguments);
You don’t have to copy any code from core if you just want to add to it. Do your work, then add that line. All it does is that it makes sure that the code from core applies.
If you test this, you’ll see that almost everything works great, except… the header is overlapping with the list-controls. Why? Because the header is set to sticky.
You can fix this in several ways in JS - calculate the height, get the offset, import a helper from Discourse… etc. I won’t get into those.
The easiest way is CSS with scroll-margin-top, which you can read about here.
In English: When the link is clicked, scroll to the top of list-controls - 2 * the header height, so it doesn’t overlap and has a bit of space below it.
#list-area {
// mobile has a different layout
.alert-info,
.show-more.has-topics {
position: sticky;
// safari is sometimes fussy without the prefix
position: -webkit-sticky;
top: var(--header-offset);
// banner should be on top of content
z-index: z("header");
}
}
.list-controls {
scroll-margin-top: calc(var(--header-offset) * 2);
}
Thank you @Johani! It is very helpful to me and I think I finally understood a lot of thing. I really like your detailed answers because we can learn a lot from them, how things works and of course it works perfectly. Thank you again!