From cd603ed773840eda083bcc08127164242c18fa85 Mon Sep 17 00:00:00 2001 From: Inhji Date: Mon, 19 Jun 2023 21:49:41 +0200 Subject: [PATCH] add toggle featured button for images --- lib/chiya_web/live/note_show_live.ex | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/chiya_web/live/note_show_live.ex b/lib/chiya_web/live/note_show_live.ex index 9cb5d4f..45dd324 100644 --- a/lib/chiya_web/live/note_show_live.ex +++ b/lib/chiya_web/live/note_show_live.ex @@ -60,13 +60,21 @@ defmodule ChiyaWeb.NoteShowLive do
- <.button phx-click="delete_image" phx-value-id={image.id} data-confirm="Are you sure?"> - Delete Image - + /> +
+ <.button phx-click="delete_image" phx-value-id={image.id} data-confirm="Are you sure?"> + <.icon name="hero-trash" /> + + <.button phx-click="toggle_favorite" phx-value-id={image.id}> + <.icon name="hero-star-solid" /> + +
<% end %> @@ -138,6 +146,7 @@ defmodule ChiyaWeb.NoteShowLive do |> assign(:note, Notes.get_note_preloaded!(socket.assigns.note.id))} end + @impl Phoenix.LiveView def handle_event("validate_edit_image", assigns, socket) do {:noreply, socket @@ -147,6 +156,7 @@ defmodule ChiyaWeb.NoteShowLive do )} end + @impl Phoenix.LiveView def handle_event("update_edit_image", %{"id" => id} = assigns, socket) do id |> Notes.get_note_image!() @@ -164,6 +174,14 @@ defmodule ChiyaWeb.NoteShowLive do {:noreply, assign(socket, :note, Notes.get_note_preloaded!(socket.assigns.note.id))} end + @impl Phoenix.LiveView + def handle_event("toggle_favorite", %{"id" => id}, socket) do + image = Notes.get_note_image!(id) + Notes.update_note_image(image, %{featured: !image.featured}) + + {:noreply, assign(socket, :note, Notes.get_note_preloaded!(socket.assigns.note.id))} + end + defp note_links(notes), do: Enum.map_join(notes, ", ", fn n -> n.name end) defp note_tags(tags), do: Enum.map_join(tags, ", ", fn t -> t.name end) end