defmodule CanneryWeb.LiveHelpers do @moduledoc """ Contains common helper functions for liveviews """ import Phoenix.LiveView import Phoenix.LiveView.Helpers alias Cannery.Accounts alias Phoenix.LiveView.JS def assign_defaults(socket, %{"user_token" => user_token} = _session) do socket |> assign_new(:current_user, fn -> Accounts.get_user_by_session_token(user_token) end) end def assign_defaults(socket, _session) do socket end @doc """ Renders a live component inside a modal. The rendered modal receives a `:return_to` option to properly update the URL when the modal is closed. ## Examples <.modal return_to={Routes.<%= schema.singular %>_index_path(Endpoint, :index)}> <.live_component module={<%= inspect context.web_module %>.<%= inspect Module.concat(schema.web_namespace, schema.alias) %>Live.FormComponent} id={@<%= schema.singular %>.id || :new} title={@page_title} action={@live_action} return_to={Routes.<%= schema.singular %>_index_path(Endpoint, :index)} <%= schema.singular %>: @<%= schema.singular %> /> """ def modal(assigns) do ~H"""