+ <%!-- entry.progress will update automatically for in-flight entries --%>
+
- <%!-- a regular click event whose handler will invoke Phoenix.LiveView.cancel_upload/3 --%>
-
+ <%!-- a regular click event whose handler will invoke Phoenix.LiveView.cancel_upload/3 --%>
+
+
<%!-- Phoenix.Component.upload_errors/2 returns a list of error atoms --%>
<%= for err <- upload_errors(@upload, entry) do %>
diff --git a/lib/chiya_web/components/core_components.ex b/lib/chiya_web/components/core_components.ex
index 8113a4c..6a1a27a 100644
--- a/lib/chiya_web/components/core_components.ex
+++ b/lib/chiya_web/components/core_components.ex
@@ -69,7 +69,11 @@ defmodule ChiyaWeb.CoreComponents do
phx-remove={hide_modal(@id)}
class="relative z-50 hidden"
>
-
diff --git a/lib/chiya_web/controllers/page_html/note.html.heex b/lib/chiya_web/controllers/page_html/note.html.heex
index d9a91ee..1f86eba 100644
--- a/lib/chiya_web/controllers/page_html/note.html.heex
+++ b/lib/chiya_web/controllers/page_html/note.html.heex
@@ -27,10 +27,14 @@
-
+
+ <%= image.content %>
-
<% end %>
diff --git a/lib/chiya_web/exim.ex b/lib/chiya_web/exim.ex
index 010a328..9313d69 100644
--- a/lib/chiya_web/exim.ex
+++ b/lib/chiya_web/exim.ex
@@ -1,12 +1,12 @@
defmodule ChiyaWeb.Exim do
- alias Chiya.Notes.Note
+ alias Chiya.Notes.Note
- defp frontmatter(%Note{name: title, channels: channels}) do
- channels_raw = Enum.map_join(channels, "], [", fn c -> "\"#{c.name}\"" end)
- "title: \"#{title}\"\ncategories: [#{channels_raw}]"
- end
+ defp frontmatter(%Note{name: title, channels: channels}) do
+ channels_raw = Enum.map_join(channels, "], [", fn c -> "\"#{c.name}\"" end)
+ "title: \"#{title}\"\ncategories: [#{channels_raw}]"
+ end
- def export_note(%Note{content: content} = note) do
- "---\n#{frontmatter(note)}\n---\n#{content}"
- end
-end
\ No newline at end of file
+ def export_note(%Note{content: content} = note) do
+ "---\n#{frontmatter(note)}\n---\n#{content}"
+ end
+end
diff --git a/lib/chiya_web/live/note_show_live.ex b/lib/chiya_web/live/note_show_live.ex
index 3c4c104..eb06d75 100644
--- a/lib/chiya_web/live/note_show_live.ex
+++ b/lib/chiya_web/live/note_show_live.ex
@@ -2,6 +2,7 @@ defmodule ChiyaWeb.NoteShowLive do
use ChiyaWeb, :live_view
alias Chiya.Notes
+ alias Chiya.Notes.NoteImage
@impl true
def render(assigns) do
@@ -41,28 +42,39 @@ defmodule ChiyaWeb.NoteShowLive do
<%= for image <- @note.images do %>
-
+
-
-
- Delete image
-
-
-
-
-
-
-
+ <.modal id={"image-edit-modal-#{image.id}"}>
+ <.simple_form
+ :let={f}
+ for={to_form(Notes.change_note_image(image))}
+ id={"image-edit-form-#{image.id}"}
+ phx-submit="update_edit_image"
+ phx-change="validate_edit_image"
+ >
+ <.input field={f[:id]} type="hidden" value={image.id} />
+ <.input field={f[:content]} type="textarea" label="Content" />
+ <.input field={f[:featured]} type="checkbox" label="Featured" />
+
+ <:actions>
+ <.button type="submit" phx-click={hide_modal("image-edit-modal-#{image.id}")}>
+ Save
+
+ <.button
+ phx-click="delete_image"
+ phx-value-id={image.id}
+ data-confirm="Are you sure?"
+ >
+ Delete Image
+
+
+
+
<% end %>
@@ -95,12 +107,13 @@ defmodule ChiyaWeb.NoteShowLive do
@impl true
def mount(%{"id" => note_id}, _session, socket) do
- image_changeset = Notes.change_note_image(%Chiya.Notes.NoteImage{})
+ image_changeset = Notes.change_note_image(%NoteImage{})
{:ok,
socket
|> assign(:note, Notes.get_note_preloaded!(note_id))
|> assign(:uploaded_files, [])
+ |> assign(:image_edit_form, to_form(image_changeset))
|> assign(:image_form, to_form(image_changeset))
|> allow_upload(:note_images, accept: ~w(.jpg .jpeg .gif .png), max_entries: 100)}
end
@@ -133,6 +146,23 @@ defmodule ChiyaWeb.NoteShowLive do
|> assign(:note, Notes.get_note_preloaded!(socket.assigns.note.id))}
end
+ def handle_event("validate_edit_image", assigns, socket) do
+ {:noreply,
+ socket
+ |> assign(
+ :image_edit_form,
+ to_form(Notes.change_note_image(%NoteImage{}, assigns))
+ )}
+ end
+
+ def handle_event("update_edit_image", %{"id" => id} = assigns, socket) do
+ id
+ |> Notes.get_note_image!()
+ |> Notes.update_note_image(assigns)
+
+ {:noreply, socket}
+ end
+
@impl Phoenix.LiveView
def handle_event("delete_image", %{"id" => id}, socket) do
:ok =
diff --git a/priv/repo/migrations/20230401085952_add_featured_flag_to_note_image.exs b/priv/repo/migrations/20230401085952_add_featured_flag_to_note_image.exs
new file mode 100644
index 0000000..e278a83
--- /dev/null
+++ b/priv/repo/migrations/20230401085952_add_featured_flag_to_note_image.exs
@@ -0,0 +1,9 @@
+defmodule Chiya.Repo.Migrations.AddFeaturedFlagToNoteImage do
+ use Ecto.Migration
+
+ def change do
+ alter table(:note_images) do
+ add :featured, :boolean
+ end
+ end
+end