improve note form, fix missing tags & refs when creating note

This commit is contained in:
Inhji 2023-07-20 20:39:32 +02:00
parent 250091d25f
commit e25499eac6
5 changed files with 13 additions and 12 deletions

View file

@ -202,6 +202,8 @@ defmodule Chiya.Notes do
%Note{} %Note{}
|> Note.changeset(attrs) |> Note.changeset(attrs)
|> Repo.insert() |> Repo.insert()
|> Chiya.Tags.TagUpdater.update_tags(attrs)
|> Chiya.Notes.References.update_references(attrs)
end end
@doc """ @doc """

View file

@ -9,7 +9,9 @@ defmodule Chiya.Tags.TagUpdater do
alias Chiya.Notes.Note alias Chiya.Notes.Note
def update_tags({:ok, %Note{} = note}, attrs) do def update_tags({:ok, %Note{} = note}, attrs) do
update_tags(note, attrs) note
|> Notes.preload_note()
|> update_tags(attrs)
{:ok, note} {:ok, note}
end end

View file

@ -1,5 +1,5 @@
<.header> <.header>
<%= @note.name %> Edit Note “<%= @note.name %>
<:actions> <:actions>
<.link href={~p"/admin/notes/#{@note.id}"}> <.link href={~p"/admin/notes/#{@note.id}"}>
<.button><.icon name="hero-arrow-left" /> Back to Note</.button> <.button><.icon name="hero-arrow-left" /> Back to Note</.button>
@ -7,14 +7,10 @@
</:actions> </:actions>
</.header> </.header>
<.note_form <.note_form
changeset={@changeset} changeset={@changeset}
action={~p"/admin/notes/#{@note}"} action={~p"/admin/notes/#{@note}"}
channels={@channels} channels={@channels}
selected_channels={@selected_channels} selected_channels={@selected_channels}
tags={@tags} tags={@tags}
/> />
<.back navigate={~p"/admin/notes/#{@note.id}"}>Back to note</.back>

View file

@ -1,6 +1,11 @@
<.header> <.header>
New Note New Note
<:subtitle>Use this form to manage note records in your database.</:subtitle> <:subtitle>Use this form to manage note records in your database.</:subtitle>
<:actions>
<.link href={~p"/admin/notes"}>
<.button><.icon name="hero-arrow-left" /> Back to Notes</.button>
</.link>
</:actions>
</.header> </.header>
<.note_form <.note_form
@ -9,6 +14,4 @@
channels={@channels} channels={@channels}
tags={@tags} tags={@tags}
selected_channels={@selected_channels} selected_channels={@selected_channels}
/> />
<.back navigate={~p"/admin/notes"}>Back to notes</.back>

View file

@ -102,8 +102,6 @@ defmodule ChiyaWeb.NoteShowLive do
<.button phx-disable-with="Changing...">Add Images</.button> <.button phx-disable-with="Changing...">Add Images</.button>
</:actions> </:actions>
</.simple_form> </.simple_form>
<.back navigate={~p"/admin/notes"}>Back to notes</.back>
""" """
end end