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} />