thesis-phoenix icon indicating copy to clipboard operation
thesis-phoenix copied to clipboard

LiveView support?

Open mayel opened this issue 4 years ago • 2 comments

Wondering if there are any plans to support using Thesis in LiveViews and LiveComponents? Thanks :)

mayel avatar Dec 05 '20 11:12 mayel

i'm using it in a LiveView-Context in my project, but you have to go with a controller to inject the necessary data to the live-view-session, a bit hacky, but it works:

in the controller:

defmodule ThermostatController do
  ...
  import Phoenix.LiveView.Controller

  def show(conn, %{"id" => thermostat_id}) do
   for_thesis=
          %{ assigns:
              Map.take(
                conn.assigns,
                ~w(thesis_content thesis_dynamic_page thesis_editable thesis_page)a
              )
              |> Map.put(:thesis_editable, MyProject.ThesisAuth.page_is_editable?(conn))
          }
          |> Map.merge(Map.take(conn, ~w(request_path)a))
        
        
    live_render(conn, ThermostatLive, session: %{
      "thermostat_id" => id,
      "current_user_id" => get_session(conn, :user_id),
      "for_thesis" => for_thesis,
    })
  end
end

in the live-view-mount:

  def mount(_params, session, socket) do
   ...
   {:ok, assign( socket, :thesis_conn, session["for_thesis"] )}
  end

in the .leex template:

<div phx-update="ignore">
  <%= Thesis.View.thesis_editor(@thesis_conn) %>
</div>

<%= Thesis.View.content(@thesis_conn, "home-title", :text) do %>
      My Text
<% end %>

mavuio avatar Dec 12 '20 19:12 mavuio

Thanks @werkzeugh ! I got something similar to work, but indeed would be better to get proper integration specifically for LV.

mayel avatar Dec 12 '20 20:12 mayel