Created
October 28, 2020 19:52
-
-
Save mhanberg/9cea198138f0b16396bdcd814ecfb003 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule BifrostWeb.RoutineLive.Show do | |
use BifrostWeb, :live_view | |
alias Bifrost.Health | |
@impl true | |
def mount(_params, _session, socket) do | |
{:ok, assign_breadcrumb(socket, "Routines", Routes.routine_index_path(socket, :index))} | |
end | |
@impl true | |
def handle_params(%{"id" => id}, _, socket) do | |
routine = Health.get_routine!(id) | |
{:noreply, | |
socket | |
|> assign(:page_title, page_title(socket.assigns.live_action)) | |
|> assign(:routine, routine) | |
|> assign_breadcrumb(routine.name)} | |
end | |
defp page_title(:show), do: "Show Routine" | |
defp page_title(:edit), do: "Edit Routine" | |
defp row_class(num) do | |
if rem(num, 2) == 0 do | |
"even" | |
else | |
"odd" | |
end <> " px-4 py-2" | |
end | |
render do | |
flex class: "justify-between items-center px-4 mb-8" do | |
h1 do: @routine.name | |
span do: | |
live_patch("Edit", | |
to: Routes.routine_show_path(@socket, :edit, @routine), | |
class: "link" | |
) | |
end | |
if @live_action in [:edit] do | |
live_modal(@socket, BifrostWeb.RoutineLive.FormComponent, | |
id: @routine.id, | |
title: @page_title, | |
action: @live_action, | |
routine: @routine, | |
return_to: Routes.routine_show_path(@socket, :show, @routine) | |
) | |
end | |
div class: "rounded-lg border-4 border-black divide-y-2 divide-black shadow-lg mx-2" do | |
h2 do: "Exercises", class: "p-4" | |
div class: "p-4" do | |
table items: @routine.exercises, columns: [:name], empty: "No exercises", delete: false | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment