Skip to content

Commit

Permalink
refactored component
Browse files Browse the repository at this point in the history
  • Loading branch information
JannikStreek committed Nov 19, 2024
1 parent 796b341 commit bd3d851
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 30 deletions.
12 changes: 10 additions & 2 deletions lib/mindwendel_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,11 @@ defmodule MindwendelWeb.CoreComponents do
attr :errors, :list, default: []
attr :checked, :boolean, doc: "the checked flag for checkbox inputs"
attr :prompt, :string, default: nil, doc: "the prompt for select inputs"
attr :options, :list, doc: "the options to pass to Phoenix.HTML.Form.options_for_select/2"

attr :options, :list,
default: [],
doc: "the options to pass to Phoenix.HTML.Form.options_for_select/2"

attr :multiple, :boolean, default: false, doc: "the multiple flag for select inputs"

attr :rest, :global,
Expand All @@ -305,7 +309,11 @@ defmodule MindwendelWeb.CoreComponents do
end)

~H"""
<div class="form-check form-check-inline">
<div class={[
"form-check",
@options == [] && "form-check-inline",
@options == ["switch"] && "form-switch"
]}>
<label class="form-check-label">
<input type="hidden" name={@name} value="false" disabled={@rest[:disabled]} />
<input
Expand Down
9 changes: 6 additions & 3 deletions lib/mindwendel_web/live/brainstorming_live/share_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ defmodule MindwendelWeb.BrainstormingLive.ShareComponent do
end
end

defp create_download_link(brainstorming, uri) do
url_fragments = String.split(uri, "#")
def secret_in_uri(uri) do
uri |> String.split("#") |> length == 2
end

if length(url_fragments) == 2 do
defp create_download_link(brainstorming, uri) do
if secret_in_uri(uri) do
url_fragments = String.split(uri, "#")
List.first(url_fragments)
else
"#{uri}##{brainstorming.admin_url_id}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,16 @@
</div>
<div class="input-group mt-3">
<%= if has_moderating_permission(@brainstorming, @current_user) do %>
<div class="form-check form-switch">
<input
class="form-check-input"
id="brainstorming-link-toggle-admin-secret"
phx-click="toggle_url_secret"
phx-target={@myself}
checked={if @uri |> String.split("#") |> length == 2, do: true, else: false}
type="checkbox"
/>
<label class="form-check-label" for="brainstorming-link-toggle-admin-secret">
<%= gettext("Give moderating permissions") %>
</label>
</div>
<.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)}
label={gettext("Give moderating permissions")}
/>
<% end %>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions priv/gettext/de/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ msgstr "Teilen"
msgid "Share brainstorming"
msgstr "Teile Dein Brainstorming"

#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:82
#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:79
#, elixir-autogen, elixir-format
msgid "Download as png"
msgstr "Download als PNG"

#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:71
#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:68
#, elixir-autogen, elixir-format
msgid "Download as svg"
msgstr "Download als SVG"
Expand Down Expand Up @@ -327,7 +327,7 @@ msgstr "Nutzern das Verschieben und Sortieren von Ideen erlauben"
msgid "Back"
msgstr "Zurück"

#: lib/mindwendel_web/components/core_components.ex:514
#: lib/mindwendel_web/components/core_components.ex:522
#, elixir-autogen, elixir-format
msgid "Actions"
msgstr ""
Expand Down Expand Up @@ -565,7 +565,7 @@ msgstr "Datenschutzerklärung"
msgid "Idea details"
msgstr "Detailansicht"

#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:45
#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:43
#, elixir-autogen, elixir-format
msgid "Give moderating permissions"
msgstr "Änderungen erlauben"
8 changes: 4 additions & 4 deletions priv/gettext/default.pot
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ msgstr ""
msgid "Share brainstorming"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:82
#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:79
#, elixir-autogen, elixir-format
msgid "Download as png"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:71
#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:68
#, elixir-autogen, elixir-format
msgid "Download as svg"
msgstr ""
Expand Down Expand Up @@ -326,7 +326,7 @@ msgstr ""
msgid "Back"
msgstr ""

#: lib/mindwendel_web/components/core_components.ex:514
#: lib/mindwendel_web/components/core_components.ex:522
#, elixir-autogen, elixir-format
msgid "Actions"
msgstr ""
Expand Down Expand Up @@ -564,7 +564,7 @@ msgstr ""
msgid "Idea details"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:45
#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:43
#, elixir-autogen, elixir-format
msgid "Give moderating permissions"
msgstr ""
8 changes: 4 additions & 4 deletions priv/gettext/en/LC_MESSAGES/default.po
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,12 @@ msgstr "Share"
msgid "Share brainstorming"
msgstr "Share brainstorming"

#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:82
#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:79
#, elixir-autogen, elixir-format
msgid "Download as png"
msgstr "Download as png"

#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:71
#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:68
#, elixir-autogen, elixir-format
msgid "Download as svg"
msgstr "Download as svg"
Expand Down Expand Up @@ -327,7 +327,7 @@ msgstr "Allow users to change the order of ideas"
msgid "Back"
msgstr ""

#: lib/mindwendel_web/components/core_components.ex:514
#: lib/mindwendel_web/components/core_components.ex:522
#, elixir-autogen, elixir-format
msgid "Actions"
msgstr ""
Expand Down Expand Up @@ -565,7 +565,7 @@ msgstr ""
msgid "Idea details"
msgstr ""

#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:45
#: lib/mindwendel_web/live/brainstorming_live/share_component.html.heex:43
#, elixir-autogen, elixir-format
msgid "Give moderating permissions"
msgstr ""

0 comments on commit bd3d851

Please sign in to comment.