I’m currently moving over an app from Turbolinks to Turbo.
I’m struggling to figure out the best way to migrate a common pattern I have in my current Turbolinks setup:
- I have infinite scroll set up with the Pagy gem and it grabs the next page via a
GETrequest - I have many filter menus, which filter down results via a form using
method: :get, responding withformat.js - After the filter button is pressed, the paginated filtered results replace the current set, and scrolling down triggers the
jsresponse, which appends the new records, updates theinfinite-scrolldiv, and triggers a few other DOM changes.
With the migration:
- In order to get the forms to work with Turbo, I’ve had to change them to submit via a
POSTrequest and respond withformat.turbo_stream - The
turbo-streamresponse updates the target div with the first page of results and an updatedinfinite-scrolldiv - Now infinite scroll fails with 404s because a
GETroute no longer exists
Here’s what I need to happen:
- When I click to filter a list, the first page of results are returned and the
infinite-scrolldiv is updated to load the second page - Scrolling down eventually triggers the second page to append to the first page, the current
infinite-scrolldiv is then removed and updated or replaced with one for the third page.
What would be the idiomatic way to do this using Pagy and Hotwire?
Is there a way to trigger a Stimulus controller after my Rails controller has finished processing? If there is, I might be able to just move over the JS I already have that’s working well.
I’m hoping for high-level tips on which direction to take but if I’ve not given enough information or seeing particular parts of the code would be helpful, just let me know. Thank you very much!