diff --git a/lib/exmr_web/live/exam_live/index.ex b/lib/exmr_web/live/exam_live/index.ex index 42716de..3326460 100644 --- a/lib/exmr_web/live/exam_live/index.ex +++ b/lib/exmr_web/live/exam_live/index.ex @@ -10,6 +10,8 @@ defmodule ExmrWeb.ExamLive.Index do socket |> assign(:exams, Exams.list_exams()) |> assign(:sort_by, "date") + |> assign(:live_action, :index) + |> assign(exam: %{}) {:ok, socket} end @@ -65,6 +67,16 @@ defmodule ExmrWeb.ExamLive.Index do {:noreply, assign(socket, exams: exams, sort_by: sort_by)} end + def handle_event("edit", %{"id" => id}, socket) do + exam = Exams.get_exam!(id) + + socket = + socket + |> assign(live_action: :edit, exam: exam) + + {:noreply, socket} + end + defp sort_items(items, "subject") do Enum.sort_by(items, & &1.subject) end diff --git a/lib/exmr_web/live/exam_live/index.html.heex b/lib/exmr_web/live/exam_live/index.html.heex index 8f9eb3a..a376ce0 100644 --- a/lib/exmr_web/live/exam_live/index.html.heex +++ b/lib/exmr_web/live/exam_live/index.html.heex @@ -19,6 +19,13 @@