From d57232646b9498407fa75050b2017cf269024a8c Mon Sep 17 00:00:00 2001 From: JannikStreek Date: Thu, 19 Dec 2024 10:28:41 +0100 Subject: [PATCH] Extract label filter to own variable instead of using brainstorming (#524) --- lib/mindwendel/brainstormings.ex | 22 ++++++----- .../components/core_components.ex | 2 + .../live/brainstorming_live/show.ex | 13 +++---- .../live/brainstorming_live/show.html.heex | 3 ++ .../live/idea_live/form_component.ex | 2 +- .../live/label_live/captions_component.ex | 23 +++++++---- .../label_live/captions_component.html.heex | 2 +- priv/gettext/de/LC_MESSAGES/default.po | 38 +++++++++---------- priv/gettext/default.pot | 38 +++++++++---------- priv/gettext/en/LC_MESSAGES/default.po | 38 +++++++++---------- test/mindwendel/brainstormings_test.exs | 25 ++++++++++++ .../live/label_live/captions_test.exs | 1 + 12 files changed, 123 insertions(+), 84 deletions(-) diff --git a/lib/mindwendel/brainstormings.ex b/lib/mindwendel/brainstormings.ex index be5dd12a..3a1bb74b 100644 --- a/lib/mindwendel/brainstormings.ex +++ b/lib/mindwendel/brainstormings.ex @@ -93,7 +93,6 @@ defmodule Mindwendel.Brainstormings do :moderating_users, labels: from(idea_label in IdeaLabel, order_by: idea_label.position_order) ]) - |> update_last_accessed_at() {:ok, preloaded_brainstorming} end @@ -156,12 +155,12 @@ defmodule Mindwendel.Brainstormings do ) end - updated_brainstorming = + updated_brainstorming_result = brainstorming |> Brainstorming.changeset(attrs) |> Repo.update() - broadcast(updated_brainstorming, :brainstorming_filter_updated) + broadcast(updated_brainstorming_result, :brainstorming_filter_updated) end def update_brainstorming(%Brainstorming{} = brainstorming, attrs) do @@ -248,6 +247,15 @@ defmodule Mindwendel.Brainstormings do Brainstorming.changeset(brainstorming, attrs) end + @doc """ + Updates the last_accessed_at field of a brainstorming. + + ## Examples + + iex> update_last_accessed_at(brainstorming) + %Brainstorming{last_accessed_at: ...} + + """ def update_last_accessed_at(brainstorming) do Repo.update(Brainstorming.changeset_with_upated_last_accessed_at(brainstorming)) brainstorming @@ -292,13 +300,7 @@ defmodule Mindwendel.Brainstormings do Phoenix.PubSub.broadcast( Mindwendel.PubSub, "brainstormings:" <> brainstorming.id, - {event, - brainstorming - |> Repo.preload([ - :users, - :moderating_users, - labels: from(idea_label in IdeaLabel, order_by: idea_label.position_order) - ]), lanes} + {event, brainstorming.filter_labels_ids, lanes} ) {:ok, brainstorming} diff --git a/lib/mindwendel_web/components/core_components.ex b/lib/mindwendel_web/components/core_components.ex index 06f354d8..3980b022 100644 --- a/lib/mindwendel_web/components/core_components.ex +++ b/lib/mindwendel_web/components/core_components.ex @@ -38,6 +38,7 @@ defmodule MindwendelWeb.CoreComponents do """ attr :id, :string, required: true attr :title, :string, required: false + attr :phx_update, :string, default: "replace" attr :show, :boolean, default: false attr :on_cancel, JS, default: %JS{} slot :inner_block, required: true @@ -53,6 +54,7 @@ defmodule MindwendelWeb.CoreComponents do tabindex="-1" aria-hidden="true" aria-labelledby="{@id}-title" + phx-update={@phx_update} >