diff --git a/lib/chiya/notes/note.ex b/lib/chiya/notes/note.ex index b5f9dbe..42c14ab 100644 --- a/lib/chiya/notes/note.ex +++ b/lib/chiya/notes/note.ex @@ -8,7 +8,11 @@ defmodule Chiya.Notes.Note do @derive {Jason.Encoder, only: [:id, :name, :content, :slug, :channels]} schema "notes" do field :content, :string - field :kind, Ecto.Enum, values: [:post, :bookmark], default: :post + + field :kind, Ecto.Enum, + values: [:post, :bookmark], + default: :post + field :name, :string field :published_at, :naive_datetime field :slug, NoteSlug.Type diff --git a/lib/chiya/notes/note_import.ex b/lib/chiya/notes/note_import.ex index 66627b0..7204fa2 100644 --- a/lib/chiya/notes/note_import.ex +++ b/lib/chiya/notes/note_import.ex @@ -1,13 +1,13 @@ defmodule Chiya.Notes.NoteImport do - import Ecto.Changeset + import Ecto.Changeset - defstruct [:file] + defstruct [:file] - @types %{file: :string} + @types %{file: :string} - def change_note_import(params) do - {%Chiya.Notes.NoteImport{}, @types} - |> cast(params, Map.keys(@types)) - |> validate_required(:file) - end -end \ No newline at end of file + def change_note_import(params) do + {%Chiya.Notes.NoteImport{}, @types} + |> cast(params, Map.keys(@types)) + |> validate_required(:file) + end +end diff --git a/lib/chiya/notes/references.ex b/lib/chiya/notes/references.ex index 2a24e37..d50d152 100644 --- a/lib/chiya/notes/references.ex +++ b/lib/chiya/notes/references.ex @@ -75,7 +75,6 @@ defmodule Chiya.Notes.References do end) end - def update_references({:ok, note}, attrs) do new_reference_slugs = get_reference_ids(attrs["content"]) old_reference_slugs = Enum.map(note.links_from, fn n -> n.slug end) diff --git a/lib/chiya_web/components/core_components.ex b/lib/chiya_web/components/core_components.ex index 8437182..0a0400f 100644 --- a/lib/chiya_web/components/core_components.ex +++ b/lib/chiya_web/components/core_components.ex @@ -321,8 +321,11 @@ defmodule ChiyaWeb.CoreComponents do attr :prompt, :string, default: nil, doc: "the prompt for select inputs" attr :options, :list, doc: "the options to pass to Phoenix.HTML.Form.options_for_select/2" attr :multiple, :boolean, default: false, doc: "the multiple flag for select inputs" - attr :rest, :global, include: ~w(autocomplete accept cols disabled form max maxlength min minlength + + attr :rest, :global, + include: ~w(autocomplete accept cols disabled form max maxlength min minlength pattern placeholder readonly required rows size step) + slot :inner_block def input(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do diff --git a/lib/chiya_web/components/layouts/public.html.heex b/lib/chiya_web/components/layouts/public.html.heex index 4cbcab6..ae5dcab 100644 --- a/lib/chiya_web/components/layouts/public.html.heex +++ b/lib/chiya_web/components/layouts/public.html.heex @@ -16,4 +16,4 @@
<.flash_group flash={@flash} /> <%= @inner_content %> -
\ No newline at end of file + diff --git a/lib/chiya_web/components/layouts/root_public.html.heex b/lib/chiya_web/components/layouts/root_public.html.heex index 1ff835e..fa52f29 100644 --- a/lib/chiya_web/components/layouts/root_public.html.heex +++ b/lib/chiya_web/components/layouts/root_public.html.heex @@ -32,10 +32,12 @@ <%= raw(@settings.custom_html) %> - + diff --git a/lib/chiya_web/controllers/admin_html/home.html.heex b/lib/chiya_web/controllers/admin_html/home.html.heex index b4c2cbe..50d7163 100644 --- a/lib/chiya_web/controllers/admin_html/home.html.heex +++ b/lib/chiya_web/controllers/admin_html/home.html.heex @@ -1,11 +1,11 @@
- +
-

Welcome back,

-

<%= @current_user.email %>

+

Welcome back,

+

<%= @current_user.email %>

<.link href={~p"/user"}> <.button>Profile @@ -13,7 +13,10 @@
- + <.icon name="hero-document-plus" /> New Note -
\ No newline at end of file + diff --git a/lib/chiya_web/controllers/channel_html/index.html.heex b/lib/chiya_web/controllers/channel_html/index.html.heex index e04944e..880f14f 100644 --- a/lib/chiya_web/controllers/channel_html/index.html.heex +++ b/lib/chiya_web/controllers/channel_html/index.html.heex @@ -10,7 +10,9 @@ <.table id="channels" rows={@channels} row_click={&JS.navigate(~p"/admin/channels/#{&1}")}> <:col :let={channel} label="Name"><%= channel.name %> - <:col :let={channel} label="Visibility"><%= Chiya.Channels.Channel.icon(channel) %> <%= channel.visibility %> + <:col :let={channel} label="Visibility"> + <%= Chiya.Channels.Channel.icon(channel) %> <%= channel.visibility %> + <:col :let={channel} label="Notes"><%= Enum.count(channel.notes) %> <:col :let={channel} label="Slug"><%= channel.slug %> <:action :let={channel}> diff --git a/lib/chiya_web/controllers/note_html/edit_image.html.heex b/lib/chiya_web/controllers/note_html/edit_image.html.heex index c8461a5..e804f60 100644 --- a/lib/chiya_web/controllers/note_html/edit_image.html.heex +++ b/lib/chiya_web/controllers/note_html/edit_image.html.heex @@ -3,7 +3,11 @@ <:subtitle>Use this form to manage note image records in your database. -<.simple_form :let={f} for={@changeset} action={~p"/admin/notes/#{@image.note.id}/image/#{@image.id}"}> +<.simple_form + :let={f} + for={@changeset} + action={~p"/admin/notes/#{@image.note.id}/image/#{@image.id}"} +> <.error :if={@changeset.action}> Oops, something went wrong! Please check the errors below. @@ -17,5 +21,4 @@ - -<.back navigate={~p"/admin/notes/#{@image.note_id}"}>Back to notes \ No newline at end of file +<.back navigate={~p"/admin/notes/#{@image.note_id}"}>Back to notes diff --git a/lib/chiya_web/controllers/note_html/import.html.heex b/lib/chiya_web/controllers/note_html/import.html.heex index 67bcee0..c284a55 100644 --- a/lib/chiya_web/controllers/note_html/import.html.heex +++ b/lib/chiya_web/controllers/note_html/import.html.heex @@ -8,7 +8,7 @@ <.input field={f[:file]} type="file" label="Markdown file" accept="text/markdown, text/plain" /> - + <:actions> <.button>Import Note diff --git a/lib/chiya_web/controllers/note_html/index.html.heex b/lib/chiya_web/controllers/note_html/index.html.heex index 120b173..858c9f8 100644 --- a/lib/chiya_web/controllers/note_html/index.html.heex +++ b/lib/chiya_web/controllers/note_html/index.html.heex @@ -12,9 +12,20 @@
- All + + All + <%= for channel <- @channels do %> - <%= channel.name %> (<%= Enum.count(channel.notes) %>) + + <%= channel.name %> + (<%= Enum.count(channel.notes) %>) + <% end %>
diff --git a/lib/chiya_web/controllers/page_html/channel.html.heex b/lib/chiya_web/controllers/page_html/channel.html.heex index 6afd766..668ed3a 100644 --- a/lib/chiya_web/controllers/page_html/channel.html.heex +++ b/lib/chiya_web/controllers/page_html/channel.html.heex @@ -17,4 +17,4 @@ <% end %> - \ No newline at end of file + diff --git a/lib/chiya_web/controllers/page_html/note.html.heex b/lib/chiya_web/controllers/page_html/note.html.heex index 022baa5..deef784 100644 --- a/lib/chiya_web/controllers/page_html/note.html.heex +++ b/lib/chiya_web/controllers/page_html/note.html.heex @@ -4,12 +4,14 @@ <%= @note.name %>

- Published + Published + · - Last Updated + Last Updated + <%= if @current_user do %> - · - Edit + · + Edit <% end %>

@@ -23,10 +25,18 @@
<%= for image <- @note.images do %> - - + + <% end %>
<% end %> - \ No newline at end of file + diff --git a/lib/chiya_web/live/note_show_live.ex b/lib/chiya_web/live/note_show_live.ex index 388a4c1..0faac86 100644 --- a/lib/chiya_web/live/note_show_live.ex +++ b/lib/chiya_web/live/note_show_live.ex @@ -29,7 +29,9 @@ defmodule ChiyaWeb.NoteShowLive do <.list> - <:item title="Published at"><%= pretty_date(@note.published_at) %> (<%= from_now(@note.published_at) %>) + <:item title="Published at"> + <%= pretty_date(@note.published_at) %> (<%= from_now(@note.published_at) %>) + <:item title="Channels"><%= @channels %> <:item title="Kind"><%= @note.kind %> <:item title="Url"><%= @note.url %> @@ -48,11 +50,7 @@ defmodule ChiyaWeb.NoteShowLive do class="rounded-lg border border-theme-dim w-28" src={ChiyaWeb.Uploaders.NoteImage.url({image.path, image}, :thumb_dithered)} /> - <.button - phx-click="delete_image" - phx-value-id={image.id} - data-confirm="Are you sure?" - > + <.button phx-click="delete_image" phx-value-id={image.id} data-confirm="Are you sure?"> Delete Image @@ -140,7 +138,7 @@ defmodule ChiyaWeb.NoteShowLive do id |> Notes.get_note_image!() |> Notes.update_note_image(assigns) - + {:noreply, socket} end @@ -154,6 +152,6 @@ defmodule ChiyaWeb.NoteShowLive do end defp note_links(notes) do - Enum.map_join(notes, ", ",fn n -> n.name end) + Enum.map_join(notes, ", ", fn n -> n.name end) end end diff --git a/priv/repo/migrations/20230409135158_fix_note_image_reference.exs b/priv/repo/migrations/20230409135158_fix_note_image_reference.exs index 6f67cb6..a853eef 100644 --- a/priv/repo/migrations/20230409135158_fix_note_image_reference.exs +++ b/priv/repo/migrations/20230409135158_fix_note_image_reference.exs @@ -2,14 +2,16 @@ defmodule Chiya.Repo.Migrations.FixNoteImageReference do use Ecto.Migration def up do - drop constraint :note_images, "note_images_note_id_fkey" + drop constraint(:note_images, "note_images_note_id_fkey") + alter table(:note_images) do modify :note_id, references(:notes, on_delete: :delete_all) end end def down do - drop constraint :note_images, "note_images_note_id_fkey" + drop constraint(:note_images, "note_images_note_id_fkey") + alter table(:note_images) do modify :note_id, references(:notes, on_delete: :nothing) end