Modals
Modals are easy. Let us imagine the following urls:
/seats
- This shows a stadium map of available seats./seats/1
- This shows the status of a single seat as a modal over the mapof seats.
Visually, the only difference between the two pages is the modal. So we model our application as such.
In /seats/index.json.props
In /seats/show.json.props
In packs/application.js
, change your component mapping to use your ShowIndex
component as your identifier's component:
and in Modal
component's render:
and add a UJS visit attribute to get the SPA modal effect with history change and back button support!
In SeatsIndex.js
, change the a
tags like so.
Optimize it!
The above solution will load the entirety of the show.json.props
. That may not be what we want as some parts of the template may be slow.
Instead, we can make it more efficient by loading just the modal contents.
The change above uses Breezy's copy feature to
Copy the current page,
/seats
and use it as a placeholder for/seats/1
Navigate to that page optimistically (as defined in our
identifierToComponentMapping
)Query
show.json.props
and walk to thedata
node, then to theseat
node,and return that.
Immutably graft it to the placeholder in
/seats/1
in the same location.React will render with the modal contents.
Last updated
Was this helpful?