Skip to content

Commit

Permalink
fix share modal from sudden closing
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Dec 23, 2024
1 parent e634420 commit 470fdd4
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 46 deletions.
32 changes: 15 additions & 17 deletions lib/mindwendel_web/live/brainstorming_live/share_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
id="brainstorming-link-input-readonly"
readonly="true"
type="text"
value={@uri}
value={@active_uri}
/>
<button
class="btn btn-outline-secondary"
Expand All @@ -23,23 +23,23 @@
class="btn btn-outline-secondary"
data-native-sharing-button-share-data-text={gettext("Join my brainstorming")}
data-native-sharing-button-share-data-title={gettext("Mindwendel Brainstorming")}
data-native-sharing-button-share-data-url={@uri}
data-native-sharing-button-share-data-url={@active_uri}
id="brainstorming-link-share-button"
phx-hook="NativeSharingButton"
>
<i class="bi-share-fill"></i>
</button>
</div>
<div class="input-group mt-3">
<%= 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"
options={["switch"]}
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 %>
Expand All @@ -50,7 +50,11 @@

<div class="row mb-3">
<div class="d-flex justify-content-center">
<div data-qr-code-url={@uri} id="brainstorming-link-qr-code-canvas" phx-hook="QrCodeCanvas">
<div
data-qr-code-url={@active_uri}
id="brainstorming-link-qr-code-canvas"
phx-hook="QrCodeCanvas"
>
</div>
</div>
</div>
Expand All @@ -60,8 +64,8 @@
<a
class="btn btn-primary"
data-qr-code-file-extension="svg"
data-qr-code-filename={@uri}
data-qr-code-url={@uri}
data-qr-code-filename={@active_uri}
data-qr-code-url={@active_uri}
id="brainstorming-link-qr-code-download-as-svg-button"
phx-hook="QrCodeDownloadButton"
>
Expand All @@ -71,8 +75,8 @@
<a
class="btn btn-primary"
data-qr-code-file-extension="png"
data-qr-code-filename={@uri}
data-qr-code-url={@uri}
data-qr-code-filename={@active_uri}
data-qr-code-url={@active_uri}
id="brainstorming-link-qr-code-download-as-png-button"
phx-hook="QrCodeDownloadButton"
>
Expand Down
43 changes: 23 additions & 20 deletions lib/mindwendel_web/live/brainstorming_live/show.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -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>
<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 [:show_idea]}
Expand Down Expand Up @@ -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}
/>
</.modal>
</div>
Expand Down

0 comments on commit 470fdd4

Please sign in to comment.