From ab11131df6dd825b55d28fa7a3fb80ca8e055898 Mon Sep 17 00:00:00 2001
From: Adam Piontek <adam@73k.us>
Date: Sat, 20 Mar 2021 23:09:19 -0400
Subject: [PATCH] tidying shifts files

---
 .../live/shift_live/form_component.ex         | 55 -------------------
 .../live/shift_live/form_component.html.leex  | 42 --------------
 lib/shift73k_web/live/shift_live/index.ex     | 18 ------
 .../live/shift_live/index.html.leex           | 20 +------
 lib/shift73k_web/live/shift_live/show.ex      | 21 -------
 .../live/shift_live/show.html.leex            | 52 ------------------
 lib/shift73k_web/router.ex                    |  5 --
 7 files changed, 2 insertions(+), 211 deletions(-)
 delete mode 100644 lib/shift73k_web/live/shift_live/form_component.ex
 delete mode 100644 lib/shift73k_web/live/shift_live/form_component.html.leex
 delete mode 100644 lib/shift73k_web/live/shift_live/show.ex
 delete mode 100644 lib/shift73k_web/live/shift_live/show.html.leex

diff --git a/lib/shift73k_web/live/shift_live/form_component.ex b/lib/shift73k_web/live/shift_live/form_component.ex
deleted file mode 100644
index 7fdd917c..00000000
--- a/lib/shift73k_web/live/shift_live/form_component.ex
+++ /dev/null
@@ -1,55 +0,0 @@
-defmodule Shift73kWeb.ShiftLive.FormComponent do
-  use Shift73kWeb, :live_component
-
-  alias Shift73k.Shifts
-
-  @impl true
-  def update(%{shift: shift} = assigns, socket) do
-    changeset = Shifts.change_shift(shift)
-
-    {:ok,
-     socket
-     |> assign(assigns)
-     |> assign(:changeset, changeset)}
-  end
-
-  @impl true
-  def handle_event("validate", %{"shift" => shift_params}, socket) do
-    changeset =
-      socket.assigns.shift
-      |> Shifts.change_shift(shift_params)
-      |> Map.put(:action, :validate)
-
-    {:noreply, assign(socket, :changeset, changeset)}
-  end
-
-  def handle_event("save", %{"shift" => shift_params}, socket) do
-    save_shift(socket, socket.assigns.action, shift_params)
-  end
-
-  defp save_shift(socket, :edit, shift_params) do
-    case Shifts.update_shift(socket.assigns.shift, shift_params) do
-      {:ok, _shift} ->
-        {:noreply,
-         socket
-         |> put_flash(:info, "Shift updated successfully")
-         |> push_redirect(to: socket.assigns.return_to)}
-
-      {:error, %Ecto.Changeset{} = changeset} ->
-        {:noreply, assign(socket, :changeset, changeset)}
-    end
-  end
-
-  defp save_shift(socket, :new, shift_params) do
-    case Shifts.create_shift(shift_params) do
-      {:ok, _shift} ->
-        {:noreply,
-         socket
-         |> put_flash(:info, "Shift created successfully")
-         |> push_redirect(to: socket.assigns.return_to)}
-
-      {:error, %Ecto.Changeset{} = changeset} ->
-        {:noreply, assign(socket, changeset: changeset)}
-    end
-  end
-end
diff --git a/lib/shift73k_web/live/shift_live/form_component.html.leex b/lib/shift73k_web/live/shift_live/form_component.html.leex
deleted file mode 100644
index 756d9abc..00000000
--- a/lib/shift73k_web/live/shift_live/form_component.html.leex
+++ /dev/null
@@ -1,42 +0,0 @@
-<h2><%= @title %></h2>
-
-<%= f = form_for @changeset, "#",
-  id: "shift-form",
-  phx_target: @myself,
-  phx_change: "validate",
-  phx_submit: "save" %>
-
-  <%= label f, :subject %>
-  <%= text_input f, :subject %>
-  <%= error_tag f, :subject %>
-
-  <%= label f, :location %>
-  <%= text_input f, :location %>
-  <%= error_tag f, :location %>
-
-  <%= label f, :description %>
-  <%= textarea f, :description %>
-  <%= error_tag f, :description %>
-
-  <%= label f, :time_zone %>
-  <%= text_input f, :time_zone %>
-  <%= error_tag f, :time_zone %>
-
-  <%= label f, :date %>
-  <%= date_select f, :date %>
-  <%= error_tag f, :date %>
-
-  <%= label f, :time_zone %>
-  <%= text_input f, :time_zone %>
-  <%= error_tag f, :time_zone %>
-
-  <%= label f, :time_start %>
-  <%= time_select f, :time_start %>
-  <%= error_tag f, :time_start %>
-
-  <%= label f, :time_end %>
-  <%= time_select f, :time_end %>
-  <%= error_tag f, :time_end %>
-
-  <%= submit "Save", phx_disable_with: "Saving..." %>
-</form>
diff --git a/lib/shift73k_web/live/shift_live/index.ex b/lib/shift73k_web/live/shift_live/index.ex
index 7a03e55b..7e7c6513 100644
--- a/lib/shift73k_web/live/shift_live/index.ex
+++ b/lib/shift73k_web/live/shift_live/index.ex
@@ -11,8 +11,6 @@ defmodule Shift73kWeb.ShiftLive.Index do
     socket
     |> assign_defaults(session)
     |> live_okreply()
-
-    # {:ok, assign(socket, :shifts, list_shifts())}
   end
 
   @impl true
@@ -23,8 +21,6 @@ defmodule Shift73kWeb.ShiftLive.Index do
 
     if Roles.can?(current_user, shift, live_action) do
       socket
-      # |> assign_shift_templates()
-      # |> assign_modal_close_handlers()
       |> init_today(Timex.today())
       |> assign_date_range()
       |> assign_known_shifts()
@@ -37,20 +33,6 @@ defmodule Shift73kWeb.ShiftLive.Index do
       |> redirect(to: "/")
       |> live_noreply()
     end
-
-    # {:noreply, apply_action(socket, socket.assigns.live_action, params)}
-  end
-
-  defp apply_action(socket, :edit, %{"id" => id}) do
-    socket
-    |> assign(:page_title, "Edit Shift")
-    |> assign(:shift, Shifts.get_shift!(id))
-  end
-
-  defp apply_action(socket, :new, _params) do
-    socket
-    |> assign(:page_title, "New Shift")
-    |> assign(:shift, %Shift{})
   end
 
   defp apply_action(socket, :index, _params) do
diff --git a/lib/shift73k_web/live/shift_live/index.html.leex b/lib/shift73k_web/live/shift_live/index.html.leex
index 6e427687..afb3a992 100644
--- a/lib/shift73k_web/live/shift_live/index.html.leex
+++ b/lib/shift73k_web/live/shift_live/index.html.leex
@@ -1,18 +1,8 @@
-<%= if @live_action in [:new, :edit] do %>
-  <%= live_modal @socket, Shift73kWeb.ShiftLive.FormComponent,
-    id: @shift.id || :new,
-    title: @page_title,
-    action: @live_action,
-    shift: @shift,
-    return_to: Routes.shift_index_path(@socket, :index) %>
-<% end %>
-
-
 <div class="row justify-content-start justify-content-sm-center">
   <div class="col-md-10 col-xl-10">
 
 <h2 class="mb-3 mb-sm-0">
-  <%= icon_div @socket, "bi-calendar2-date", [class: "icon baseline"] %>
+  <%= icon_div @socket, "bi-card-list", [class: "icon baseline"] %>
   My Shifts
 </h2>
 
@@ -40,7 +30,6 @@
 
 <dl>
 <%= for day <- Enum.to_list(@date_range) do %>
-  <% Date.day_of_week(day, @current_user.week_start_at) |> IO.inspect(label: "day in date_range") %>
   <%= if Date.day_of_week(day, @current_user.week_start_at) == 1 do %>
   <div class="border-top mt-4 mb-4"></div>
   <% end %>
@@ -69,8 +58,6 @@
             </div>
             <div style="font-size: smaller;"><%= shift.description %></div>
             <div style="font-size: smaller;">
-              <span><%= live_redirect "Show", to: Routes.shift_show_path(@socket, :show, shift) %></span>
-              <span><%= live_patch "Edit", to: Routes.shift_index_path(@socket, :edit, shift) %></span>
               <span><%= link "Delete", to: "#", phx_click: "delete", phx_value_id: shift.id, data: [confirm: "Are you sure?"] %></span>
             </div>
           </div>
@@ -80,14 +67,11 @@
     </dd>
 
   <% else %>
-    <dd><em>No shift scheduled</em></dd>
+    <dd><em>Nothing scheduled</em></dd>
   <% end %>
 <% end %>
 </dl>
 
 
-<span><%= live_patch "New Shift", to: Routes.shift_index_path(@socket, :new) %></span>
-
-
   </div>
 </div>
diff --git a/lib/shift73k_web/live/shift_live/show.ex b/lib/shift73k_web/live/shift_live/show.ex
deleted file mode 100644
index 40b3424b..00000000
--- a/lib/shift73k_web/live/shift_live/show.ex
+++ /dev/null
@@ -1,21 +0,0 @@
-defmodule Shift73kWeb.ShiftLive.Show do
-  use Shift73kWeb, :live_view
-
-  alias Shift73k.Shifts
-
-  @impl true
-  def mount(_params, _session, socket) do
-    {:ok, socket}
-  end
-
-  @impl true
-  def handle_params(%{"id" => id}, _, socket) do
-    {:noreply,
-     socket
-     |> assign(:page_title, page_title(socket.assigns.live_action))
-     |> assign(:shift, Shifts.get_shift!(id))}
-  end
-
-  defp page_title(:show), do: "Show Shift"
-  defp page_title(:edit), do: "Edit Shift"
-end
diff --git a/lib/shift73k_web/live/shift_live/show.html.leex b/lib/shift73k_web/live/shift_live/show.html.leex
deleted file mode 100644
index c30c705f..00000000
--- a/lib/shift73k_web/live/shift_live/show.html.leex
+++ /dev/null
@@ -1,52 +0,0 @@
-<h1>Show Shift</h1>
-
-<%= if @live_action in [:edit] do %>
-  <%= live_modal @socket, Shift73kWeb.ShiftLive.FormComponent,
-    id: @shift.id,
-    title: @page_title,
-    action: @live_action,
-    shift: @shift,
-    return_to: Routes.shift_show_path(@socket, :show, @shift) %>
-<% end %>
-
-<ul>
-
-  <li>
-    <strong>Subject:</strong>
-    <%= @shift.subject %>
-  </li>
-
-  <li>
-    <strong>Location:</strong>
-    <%= @shift.location %>
-  </li>
-
-  <li>
-    <strong>Description:</strong>
-    <%= @shift.description %>
-  </li>
-
-  <li>
-    <strong>Date:</strong>
-    <%= @shift.date %>
-  </li>
-
-  <li>
-    <strong>Time zone:</strong>
-    <%= @shift.time_zone %>
-  </li>
-
-  <li>
-    <strong>Time start:</strong>
-    <%= @shift.time_start %>
-  </li>
-
-  <li>
-    <strong>Time end:</strong>
-    <%= @shift.time_end %>
-  </li>
-
-</ul>
-
-<span><%= live_patch "Edit", to: Routes.shift_show_path(@socket, :edit, @shift), class: "button" %></span>
-<span><%= live_redirect "Back", to: Routes.shift_index_path(@socket, :index) %></span>
diff --git a/lib/shift73k_web/router.ex b/lib/shift73k_web/router.ex
index 13ede71b..115b8a3b 100644
--- a/lib/shift73k_web/router.ex
+++ b/lib/shift73k_web/router.ex
@@ -98,11 +98,6 @@ defmodule Shift73kWeb.Router do
     live "/assign", ShiftAssignLive.Index, :index
 
     live "/shifts", ShiftLive.Index, :index
-    live "/shifts/new", ShiftLive.Index, :new
-    live "/shifts/:id/edit", ShiftLive.Index, :edit
-
-    live "/shifts/:id", ShiftLive.Show, :show
-    live "/shifts/:id/show/edit", ShiftLive.Show, :edit
   end
 
   # scope "/", Shift73kWeb do