devato / inertia_phoenix Goto Github PK
View Code? Open in Web Editor NEWInertiajs Adapter for Elixir Phoenix
Home Page: https://devato.com
License: MIT License
Inertiajs Adapter for Elixir Phoenix
Home Page: https://devato.com
License: MIT License
Describe the bug
...
put_flash(conn, :info, "Info flash")
|> put_flash(:danger, "Danger flash!")
|> put_flash(:danger, "Another danger flash!")
|> redirect(to: "/about")
...
results in:
{"flash":{"danger":"Another danger flash!","info":"Info flash"}}
Expected behavior
I would expect to see an array of all flashes, and in order that they were added perhaps:
{"flash":[{"info":"Info flash"},{"danger":"Danger flash!"},{"danger":"Another danger flash!"}]}
Not sure if this is a limitation with the way Phoenix handles flashes?
Will have a go at a PR if you see this as a valid issue!
Add shared data that will be loaded on every request for auth and other data.
The plugin dependencies are not compatible with the latest version of phoenix framework.
Is your feature request related to a problem? Please describe.
I find that if I have a controller action like this:
def does_not_exist(conn, _) do
render_inertia(conn, "DoesNotExist", props: %{hello: "world"})
end
Describe the solution you'd like
My Phoenix app renders with a 200 without error, whereas I would prefer to raise error if the template wasn't found, what do you think?
One common challenge with single-page apps is refreshing site assets when they've been changed. Inertia makes this easy by optionally tracking the current version of your site assets. In the event that an asset changes, Inertia will automatically make a hard page visit instead of a normal ajax visit on the next request.
https://inertiajs.com/requests#partial-reloads
The only option allows you to request a subset of the props (data) from the server on subsequent visits to the same page. This feature is called partial reloads, and can be a helpful performance optimization if it's acceptable that some page data becomes stale. For partial reloads to be effective, be sure to use lazy evaluation server-side.
Add proper docs for package using ex_doc
.
Exploring the idea of adding a system for Phoenix routes in JS as they're so often used with frontend pages.
Seems like it would be helpful but maybe it would over-complicate the purpose of this lib.
Curious to hear what others think.
Add a config option for setting the Phoenix layout to be used with Inertia
Looks like we had the same idea at the same time! I started knocking something together on the weekend (https://github.com/totaltrash/test_phoenix_inertia), pulled out the Inertia stuff into a library just now (https://github.com/ifixsystems-au/inertia-phoenix), had a look on Hex, and found you've been busy on the weekend too!
Looking good, pretty excited about Inertia and Elixir (I'm not an Elixir developer, I was just looking for a project to do on the weekend).
I've starting using this in a new project I am working on and during controller testing I made a helper that I add to my conn_case.ex
that maybe other people would find useful? I can add some documentation as a PR if this is something anyone would want. If not, just putting this here in case it helps someone.
def inertia_response(conn, status \\ 200) do
response = Phoenix.ConnTest.html_response(conn, status)
case Regex.run(~r/data-page=\"(.+?)\"/, response) do
[_, injected_data] ->
injected_data |> String.replace(""", "\"") |> Jason.decode!()
_ ->
nil
end
end
Then you can use it a test like:
conn = get(conn, Routes.customer_quotations_path(conn, :index))
response = inertia_response(conn, 200)
Which gives you a map of the inertia injected data on the page:
%{
"component" => "QuotationList",
"props" => %{
"quotations" => [
%{
"completed" => false,
"id" => 1,
"status" => "awaiting_quotation",
"updated_at" => "2020-09-04T02:02:14"
}
]
},
"url" => "/quotations",
"version" => "1"
}
This can be useful to assert the correct component is being rendered, or assert about the props being injected into the component.
https://inertiajs.com/the-protocol#asset-versioning
Finally, in the event that flash session data exists when a 409 Conflict response occurs, the server will automatically reflash this data.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.