diff --git a/lib/mindwendel_web/live/brainstorming_live/share_component.ex b/lib/mindwendel_web/live/brainstorming_live/share_component.ex index 288d910b..84f0885b 100644 --- a/lib/mindwendel_web/live/brainstorming_live/share_component.ex +++ b/lib/mindwendel_web/live/brainstorming_live/share_component.ex @@ -4,26 +4,24 @@ defmodule MindwendelWeb.BrainstormingLive.ShareComponent do alias Mindwendel.Permissions def handle_event("toggle_url_secret", _value, socket) do - %{brainstorming: brainstorming, uri: uri, current_user: current_user} = socket.assigns + %{ + brainstorming_id: brainstorming_id, + uri: uri, + admin_uri: admin_uri, + current_user: current_user, + activated_uri_type: activated_uri_type + } = socket.assigns - if Permissions.has_moderating_permission(brainstorming.id, current_user) do - new_uri = create_download_link(brainstorming, uri) - {:noreply, assign(socket, :uri, new_uri)} - else - {:noreply, socket} - end - end + if Permissions.has_moderating_permission(brainstorming_id, current_user) do + toggled_activated_uri = if activated_uri_type == :uri, do: :admin_uri, else: :uri + active_uri = if toggled_activated_uri == :uri, do: uri, else: admin_uri - def secret_in_uri(uri) do - uri |> String.split("#") |> length == 2 - end - - defp create_download_link(brainstorming, uri) do - if secret_in_uri(uri) do - url_fragments = String.split(uri, "#") - List.first(url_fragments) + {:noreply, + socket + |> assign(:activated_uri_type, toggled_activated_uri) + |> assign(:active_uri, active_uri)} else - "#{uri}##{brainstorming.admin_url_id}" + {:noreply, socket} end end end diff --git a/lib/mindwendel_web/live/brainstorming_live/share_component.html.heex b/lib/mindwendel_web/live/brainstorming_live/share_component.html.heex index ae66b9b0..214472f2 100644 --- a/lib/mindwendel_web/live/brainstorming_live/share_component.html.heex +++ b/lib/mindwendel_web/live/brainstorming_live/share_component.html.heex @@ -8,7 +8,7 @@ id="brainstorming-link-input-readonly" readonly="true" type="text" - value={@uri} + value={@active_uri} />
- <%= if has_moderating_permission(@brainstorming.id, @current_user) do %> + <%= if has_moderating_permission(@brainstorming_id, @current_user) do %> <.input name="admin_url_id" type="checkbox" @@ -39,7 +39,7 @@ id="brainstorming-link-toggle-admin-secret" phx-click="toggle_url_secret" phx-target={@myself} - checked={secret_in_uri(@uri)} + checked={@activated_uri_type == :admin_uri} label={gettext("Give moderating permissions")} /> <% end %> @@ -50,7 +50,11 @@
-
@@ -60,8 +64,8 @@ @@ -71,8 +75,8 @@ diff --git a/lib/mindwendel_web/live/brainstorming_live/show.html.heex b/lib/mindwendel_web/live/brainstorming_live/show.html.heex index ddf34a61..dac9d6d4 100644 --- a/lib/mindwendel_web/live/brainstorming_live/show.html.heex +++ b/lib/mindwendel_web/live/brainstorming_live/show.html.heex @@ -84,24 +84,25 @@ lanes={@lanes} /> - <.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} - phx-update="ignore" - brainstorming_id={@brainstorming.id} - filtered_labels={@filtered_labels} - current_user={@current_user} - idea={@idea} - /> - +
+ <.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 :if={@live_action in [:show_idea]} @@ -181,10 +182,12 @@ module={MindwendelWeb.BrainstormingLive.ShareComponent} id={:share} action={:share} - phx-update="ignore" - brainstorming={@brainstorming} + brainstorming_id={@brainstorming.id} current_user={@current_user} uri={url(~p"/brainstormings/#{@brainstorming.id}")} + admin_uri={url(~p"/brainstormings/#{@brainstorming.id}/##{@brainstorming.admin_url_id}")} + active_uri={url(~p"/brainstormings/#{@brainstorming.id}")} + activated_uri_type={:uri} />