I feel like I’m probably missing something obvious here, but I can’t figure it out. I have a theme component that loads up some widgets, and I’m using the following code to re-render them after the user navigates to a new page (borrowed from category banners)
However, this code waits until after the new page has loaded to update the widget. What I’m hoping to do is hide my widget content as soon as someone clicks a link to another page, similar to how the native discourse functionality is to hide things and show a loading spinner immediately on click.
I see in app\assets\javascripts\discourse\app\templates\discovery.hbs that the div container observes a “loading” var, but I can’t figure out where that comes from and how to “tap in” to that or observe the loading state in my widget.
Appreciative of any answers or simply pointing me in the right general direction.
I have a number of widgets I’ve built for certain category pages, and I’d ideally like to hide them immediately when someone navigates away from a page. Here’s a 45 second loom video demo of what I’m going for: Loom | Free Screen & Video Recording Software
@hawm I’m not sure that the queue re-render is what I need here, as this isn’t really about re-rendering my widgets, but rather about giving my widgets awareness of whether or not the global Discourse app is loading a new page.
Yes, of course. I am not struggling with the if/then syntax; what I’m asking is if there’s a way that I can check if Discourse is currently loading a new page.
The loading variable comes from the discovery route that I mentioned above, the widget attached to plugin-outlet may not able to access it since it doesn’t pass as an argument, it depends on the definition of plugin-outlet.
I managed to finally find a solution. Spent sooooooooooo long on this and IMO it’s worth merging into core because honestly it feels like it should already exist anyway in core.
I added the code below to my theme component; what it does is adds a “loading” class to the body as soon as routing starts, and then removes it as soon as routing is complete. Maybe this would be simple/obvious for folks who know ember, but it took me an obscenely long time (and trying a million things + reading through all threads on here I could find) to figure out.
With this core code in place, I can add loading spinners and such to my different widgets that will have their css and visibility be driven by whether or not the body tag has the loading css class.