Raw edit notes
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
defmodule MusicLibraryWeb.NotesComponent do
|
||||
use MusicLibraryWeb, :live_component
|
||||
|
||||
alias MusicLibrary.Records
|
||||
|
||||
def open(id), do: Fluxon.open_dialog(id)
|
||||
|
||||
@impl true
|
||||
def update(assigns, socket) do
|
||||
changeset =
|
||||
assigns.record
|
||||
|> Records.change_record()
|
||||
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(assigns)
|
||||
|> assign(:form, to_form(changeset))}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<div>
|
||||
<.sheet
|
||||
id={@sheet_id}
|
||||
placement="right"
|
||||
class="min-w-xs sm:min-w-sm"
|
||||
>
|
||||
<.simple_form
|
||||
for={@form}
|
||||
id="record-notes-form"
|
||||
phx-target={@myself}
|
||||
phx-change="validate"
|
||||
phx-auto-recover="recover_form"
|
||||
phx-submit="save"
|
||||
>
|
||||
<.textarea class="w-full h-96" field={@form[:notes]} label={gettext("Notes")} />
|
||||
<:actions>
|
||||
<div class="w-full md:flex md:justify-center">
|
||||
<.button
|
||||
variant="solid"
|
||||
class="w-full md:w-auto"
|
||||
phx-disable-with={gettext("Saving...")}
|
||||
>
|
||||
{gettext("Save")}
|
||||
</.button>
|
||||
</div>
|
||||
</:actions>
|
||||
</.simple_form>
|
||||
</.sheet>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("validate", %{"record" => record_params}, socket) do
|
||||
changeset = Records.change_record(socket.assigns.record, record_params)
|
||||
{:noreply, assign(socket, form: to_form(changeset, action: :validate))}
|
||||
end
|
||||
|
||||
def handle_event("save", %{"record" => record_params}, socket) do
|
||||
case Records.update_record(socket.assigns.record, record_params) do
|
||||
{:ok, _record} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_toast(:info, gettext("Record updated successfully"))}
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
{:noreply, assign(socket, form: to_form(changeset))}
|
||||
end
|
||||
end
|
||||
|
||||
def handle_event("recover_form", params, socket) do
|
||||
handle_event("validate", params, socket)
|
||||
end
|
||||
end
|
||||
@@ -25,6 +25,18 @@
|
||||
</p>
|
||||
</div>
|
||||
<div class="min-w-12 text-right">
|
||||
<button
|
||||
class="text-xs md:text-sm text-zinc-700 dark:text-zinc-300"
|
||||
phx-click={MusicLibraryWeb.NotesComponent.open("record-notes-sheet")}
|
||||
>
|
||||
<span class="sr-only">{gettext("Open Notes")}</span>
|
||||
<.icon
|
||||
name="hero-pencil-square"
|
||||
class="-mt-1 h-5 w-5"
|
||||
aria-hidden="true"
|
||||
data-slot="icon"
|
||||
/>
|
||||
</button>
|
||||
<button
|
||||
:if={@record.selected_release_id}
|
||||
class="text-xs md:text-sm text-zinc-700 dark:text-zinc-300"
|
||||
@@ -320,6 +332,13 @@
|
||||
record={@record}
|
||||
/>
|
||||
|
||||
<.live_component
|
||||
id="record-notes"
|
||||
sheet_id="record-notes-sheet"
|
||||
module={MusicLibraryWeb.NotesComponent}
|
||||
record={@record}
|
||||
/>
|
||||
|
||||
<.structured_modal
|
||||
:if={@live_action == :edit}
|
||||
id="record-modal"
|
||||
|
||||
@@ -155,17 +155,20 @@ msgstr ""
|
||||
msgid "Record imported successfully"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/notes_component.ex
|
||||
#: lib/music_library_web/components/record_form_component.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Record updated successfully"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/notes_component.ex
|
||||
#: lib/music_library_web/components/record_form_component.ex
|
||||
#: lib/music_library_web/live/artist_live/form_component.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Save"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/notes_component.ex
|
||||
#: lib/music_library_web/components/record_form_component.ex
|
||||
#: lib/music_library_web/live/artist_live/form_component.ex
|
||||
#: lib/music_library_web/live/online_store_template_live/form_component.ex
|
||||
@@ -1310,3 +1313,13 @@ msgstr ""
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "No records released on this day."
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/notes_component.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Notes"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/collection_live/show.html.heex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Open Notes"
|
||||
msgstr ""
|
||||
|
||||
@@ -155,17 +155,20 @@ msgstr ""
|
||||
msgid "Record imported successfully"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/notes_component.ex
|
||||
#: lib/music_library_web/components/record_form_component.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Record updated successfully"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/notes_component.ex
|
||||
#: lib/music_library_web/components/record_form_component.ex
|
||||
#: lib/music_library_web/live/artist_live/form_component.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Save"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/notes_component.ex
|
||||
#: lib/music_library_web/components/record_form_component.ex
|
||||
#: lib/music_library_web/live/artist_live/form_component.ex
|
||||
#: lib/music_library_web/live/online_store_template_live/form_component.ex
|
||||
@@ -1310,3 +1313,13 @@ msgstr ""
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "No records released on this day."
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/notes_component.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Notes"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/collection_live/show.html.heex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Open Notes"
|
||||
msgstr ""
|
||||
|
||||
Reference in New Issue
Block a user