From 429f2542fc2bbf6b57eea9fac7341b1b73dc8005 Mon Sep 17 00:00:00 2001 From: inhji Date: Wed, 2 Aug 2023 13:37:16 +0200 Subject: [PATCH 1/4] lib/chiya_web/controllers/page_html/bookmarks.html.heex aktualisiert --- lib/chiya_web/controllers/page_html/bookmarks.html.heex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/chiya_web/controllers/page_html/bookmarks.html.heex b/lib/chiya_web/controllers/page_html/bookmarks.html.heex index 7a0438a..beb37ca 100644 --- a/lib/chiya_web/controllers/page_html/bookmarks.html.heex +++ b/lib/chiya_web/controllers/page_html/bookmarks.html.heex @@ -5,8 +5,8 @@ -
-
+
+
<.note_list notes={@notes} layout={@channel.layout} show_content={false} />
From 2e8adf57048235d43fdb5fa14d37859341fc0750 Mon Sep 17 00:00:00 2001 From: Inhji Date: Wed, 2 Aug 2023 20:41:31 +0200 Subject: [PATCH 2/4] fix adding the same tag twice --- lib/chiya/tags/tag_updater.ex | 10 ++++++++-- test/chiya/tag_updater_test.exs | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/chiya/tags/tag_updater.ex b/lib/chiya/tags/tag_updater.ex index b5c334e..1649ba4 100644 --- a/lib/chiya/tags/tag_updater.ex +++ b/lib/chiya/tags/tag_updater.ex @@ -70,7 +70,10 @@ defmodule Chiya.Tags.TagUpdater do end defp add_tags(note, tags) do - Enum.each(tags, &add_tag(note, &1)) + tags + |> Enum.uniq() + |> Enum.each(&add_tag(note, &1)) + note end @@ -102,7 +105,10 @@ defmodule Chiya.Tags.TagUpdater do end defp remove_tags(note, tags) do - Enum.each(tags, &remove_tag(note, &1)) + tags + |> Enum.uniq() + |> Enum.each(&remove_tag(note, &1)) + note end diff --git a/test/chiya/tag_updater_test.exs b/test/chiya/tag_updater_test.exs index 02885af..940499a 100644 --- a/test/chiya/tag_updater_test.exs +++ b/test/chiya/tag_updater_test.exs @@ -53,5 +53,14 @@ defmodule Chiya.TagUpdaterTest do tag = List.first(note.tags) assert tag.name == "foo" end + + test "with the same tag twice only adds unique tags" do + note = note_fixture() + assert note.tags == [] + + TagUpdater.update_tags(note, "foo,foo") + note = Chiya.Notes.get_note_preloaded!(note.id) + assert Enum.count(note.tags) == 1 + end end end From 931734ca7dc038c54a8a76b9bb2f85dfcfddc7fd Mon Sep 17 00:00:00 2001 From: Inhji Date: Wed, 2 Aug 2023 20:48:41 +0200 Subject: [PATCH 3/4] add bookmarks to bookmark channel --- lib/chiya_web/indie/micropub.ex | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/lib/chiya_web/indie/micropub.ex b/lib/chiya_web/indie/micropub.ex index bf3f02d..effae15 100644 --- a/lib/chiya_web/indie/micropub.ex +++ b/lib/chiya_web/indie/micropub.ex @@ -6,9 +6,8 @@ defmodule ChiyaWeb.Indie.Micropub do def create_note(type, properties) do settings = Chiya.Site.get_settings() - channel_id = settings.micropub_channel_id - with {:ok, note_attrs} <- get_create_attrs(type, properties, channel_id), + with {:ok, note_attrs} <- get_create_attrs(type, properties, settings), {:ok, note} <- Chiya.Notes.create_note(note_attrs) do create_photos(note, properties) @@ -79,18 +78,13 @@ defmodule ChiyaWeb.Indie.Micropub do ) end - defp get_create_attrs(type, properties, channel_id) do + defp get_create_attrs(type, properties, settings) do {:ok, post_type} = Props.get_post_type(properties) Logger.info("Creating a #{type}/#{post_type}..") - channel = - if channel_id, - do: Chiya.Channels.get_channel(channel_id), - else: nil - case post_type do - :note -> get_note_attrs(properties, channel) - :bookmark -> get_bookmark_attrs(properties, channel) + :note -> get_note_attrs(properties, settings.micropub_channel_id) + :bookmark -> get_bookmark_attrs(properties, settings.bookmark_channel_id) _ -> {:error, :insufficient_scope} end end @@ -163,22 +157,22 @@ defmodule ChiyaWeb.Indie.Micropub do end end - defp get_note_attrs(properties, channel) do + defp get_note_attrs(properties, channel_id) do attrs = properties |> get_base_attrs() - |> get_channel(channel) + |> get_channel(channel_id) {:ok, attrs} end - defp get_bookmark_attrs(properties, channel) do + defp get_bookmark_attrs(properties, channel_id) do url = Props.get_bookmarked_url(properties) attrs = properties |> get_base_attrs() - |> get_channel(channel) + |> get_channel(channel_id) |> Map.put_new(:url, url) |> Map.put_new(:kind, :bookmark) @@ -205,9 +199,9 @@ defmodule ChiyaWeb.Indie.Micropub do attrs end - def get_channel(attrs, channel) do - if channel, - do: Map.put(attrs, :channels, [channel]), + def get_channel(attrs, channel_id) do + if channel_id, + do: Map.put(attrs, :channels, [Chiya.Channels.get_channel(channel_id)]), else: attrs end From 2d162ac0aa30f573b2f85215bd3787f12240379c Mon Sep 17 00:00:00 2001 From: Inhji Date: Wed, 2 Aug 2023 20:48:45 +0200 Subject: [PATCH 4/4] mix format --- lib/chiya_web/components/public_components.ex | 18 ++++++------- lib/chiya_web/controllers/note_controller.ex | 8 +++--- .../controllers/page_html/bookmarks.html.heex | 26 ++++++++++++------- ...729160000_add_bookmark_channel_setting.exs | 2 +- 4 files changed, 30 insertions(+), 24 deletions(-) diff --git a/lib/chiya_web/components/public_components.ex b/lib/chiya_web/components/public_components.ex index 7e82a5e..3074271 100644 --- a/lib/chiya_web/components/public_components.ex +++ b/lib/chiya_web/components/public_components.ex @@ -76,13 +76,13 @@ defmodule ChiyaWeb.PublicComponents do <%= for tag <- @note.tags do %> <%= if assigns.linked do %> - - <%= tag.name %> - + + <%= tag.name %> + <% else %> - - <%= tag.name %> - + + <%= tag.name %> + <% end %> <.dot class="text-theme-base/50 last:hidden" /> <% end %> @@ -162,9 +162,9 @@ defmodule ChiyaWeb.PublicComponents do <% end %> <%= if not Enum.empty?(note.tags) do %> - - <.tags note={note} linked={false} /> - + + <.tags note={note} linked={false} /> + <% end %> <% end %> diff --git a/lib/chiya_web/controllers/note_controller.ex b/lib/chiya_web/controllers/note_controller.ex index b2d8127..33669c6 100644 --- a/lib/chiya_web/controllers/note_controller.ex +++ b/lib/chiya_web/controllers/note_controller.ex @@ -11,8 +11,8 @@ defmodule ChiyaWeb.NoteController do conn |> with_channels() - |> render(:index, - notes: notes, + |> render(:index, + notes: notes, page_title: "Notes" ) end @@ -22,8 +22,8 @@ defmodule ChiyaWeb.NoteController do conn |> with_channels() - |> render(:index, - notes: notes, + |> render(:index, + notes: notes, page_title: "Notes" ) end diff --git a/lib/chiya_web/controllers/page_html/bookmarks.html.heex b/lib/chiya_web/controllers/page_html/bookmarks.html.heex index beb37ca..f05c91f 100644 --- a/lib/chiya_web/controllers/page_html/bookmarks.html.heex +++ b/lib/chiya_web/controllers/page_html/bookmarks.html.heex @@ -12,16 +12,22 @@
    - <%= for {letter, tag_group} <- @tags do %> -
  • - <%= letter %> - - <%= for tag <- tag_group do %> - <%= tag.name %> - <% end %> - -
  • - <% end %> + <%= for {letter, tag_group} <- @tags do %> +
  • + + <%= letter %> + + + <%= for tag <- tag_group do %> + + <%= tag.name %> + + <% end %> +
  • + <% end %>
diff --git a/priv/repo/migrations/20230729160000_add_bookmark_channel_setting.exs b/priv/repo/migrations/20230729160000_add_bookmark_channel_setting.exs index 03d4100..2cd28c8 100644 --- a/priv/repo/migrations/20230729160000_add_bookmark_channel_setting.exs +++ b/priv/repo/migrations/20230729160000_add_bookmark_channel_setting.exs @@ -6,4 +6,4 @@ defmodule Chiya.Repo.Migrations.AddBookmarkChannelSetting do add :bookmark_channel_id, references(:channels, on_delete: :nothing) end end -end \ No newline at end of file +end