Skip to content
This repository has been archived by the owner on Mar 10, 2021. It is now read-only.

LiveView support? #172

Open
mayel opened this issue Dec 5, 2020 · 2 comments
Open

LiveView support? #172

mayel opened this issue Dec 5, 2020 · 2 comments

Comments

@mayel
Copy link

mayel commented Dec 5, 2020

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

@mavuio
Copy link

mavuio commented Dec 12, 2020

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 %>

@mayel
Copy link
Author

mayel commented Dec 12, 2020

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants