This commit is contained in:
parent
3d54c998fd
commit
69c178855d
2 changed files with 19 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -19,6 +19,13 @@
|
|||
<div class="font-bold"><%= exam.subject %></div>
|
||||
<div class="font-sm"><%= exam.date %></div>
|
||||
</div>
|
||||
<button
|
||||
phx-click="edit"
|
||||
phx-value-id={exam.id}
|
||||
class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-3 rounded-md"
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
<button
|
||||
phx-click="remove"
|
||||
phx-value-id={exam.id}
|
||||
|
|
Loading…
Reference in a new issue