feat(exams): add editing exams
Some checks are pending
Checks / check (push) Waiting to run

This commit is contained in:
Vladimir Rubin 2024-11-27 18:02:28 +02:00
parent 3d54c998fd
commit 69c178855d
Signed by: vavakado
GPG key ID: CAB744727F36B524
2 changed files with 19 additions and 0 deletions

View file

@ -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

View file

@ -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}