Skip to content

Commit

Permalink
fix new idea modal issues with filters and reloads
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Dec 23, 2024
1 parent 470fdd4 commit 62e9859
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
35 changes: 16 additions & 19 deletions lib/mindwendel_web/live/brainstorming_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,22 @@
lanes={@lanes}
/>

<div id="testerer" phx-update="ignore">
<.modal
:if={@live_action in [:new_idea]}
id="idea-modal"
show
on_cancel={JS.patch(~p"/brainstormings/#{@brainstorming.id}")}
title={gettext("New idea")}
>
<.live_component
module={MindwendelWeb.IdeaLive.FormComponent}
id={:new}
action={:new}
brainstorming_id={@brainstorming.id}
filtered_labels={@filtered_labels}
current_user={@current_user}
idea={@idea}
/>
</.modal>
</div>
<.modal
:if={@live_action in [:new_idea]}
id="idea-modal"
show
on_cancel={JS.patch(~p"/brainstormings/#{@brainstorming.id}")}
title={gettext("New idea")}
>
<.live_component
module={MindwendelWeb.IdeaLive.FormComponent}
id={:new}
action={:new}
brainstorming_id={@brainstorming.id}
current_user={@current_user}
idea={@idea}
/>
</.modal>

<.modal
:if={@live_action in [:show_idea]}
Expand Down
8 changes: 7 additions & 1 deletion lib/mindwendel_web/live/idea_live/form_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ defmodule MindwendelWeb.IdeaLive.FormComponent do
alias MIME
alias Mindwendel.Ideas
alias Mindwendel.Attachments
alias Mindwendel.Brainstormings
alias Mindwendel.IdeaLabels

@whitelisted_file_extensions ~w(.jpg .jpeg .gif .png .pdf)
Expand Down Expand Up @@ -89,12 +90,17 @@ defmodule MindwendelWeb.IdeaLive.FormComponent do
defp save_idea(socket, :new, idea_params) do
tmp_attachments = prepare_attachments(socket)

# This is a workaround to get the filtered labels for the idea without (!) passing them as a parameter to the form component.
# Unfortunatly, passing either the brainstorming or filter labels directly triggers a re-render of the form component when changing the filter labels and results in a stuck bootstrapmodal.
{:ok, brainstorming} = Brainstormings.get_brainstorming(socket.assigns.brainstorming_id)
filtered_labels = brainstorming.filter_labels_ids

idea_params_merged =
idea_params
|> Map.put("user_id", socket.assigns.current_user.id)
|> Map.put(
"idea_labels",
IdeaLabels.get_idea_labels(socket.assigns.filtered_labels)
IdeaLabels.get_idea_labels(filtered_labels)
)
|> Map.put("tmp_attachments", tmp_attachments)

Expand Down

0 comments on commit 62e9859

Please sign in to comment.