-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Patch to Sanne's empty states: Make tile component lv-embeddable
#5891
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| defmodule PlausibleWeb.Components.Site.Feature.ToggleLive do | ||
| @moduledoc """ | ||
| LiveComponent for rendering a user-facing feature toggle in LiveView contexts. | ||
| Instead of using form submission, this component messages itself to handle toggles. | ||
| """ | ||
| use PlausibleWeb, :live_component | ||
|
|
||
| def update(assigns, socket) do | ||
| site = Plausible.Repo.preload(assigns.site, :team) | ||
| current_setting = assigns.feature_mod.enabled?(site) | ||
| disabled? = assigns.feature_mod.check_availability(site.team) !== :ok | ||
|
|
||
| {:ok, | ||
| socket | ||
| |> assign(assigns) | ||
| |> assign(:site, site) | ||
| |> assign(:current_setting, current_setting) | ||
| |> assign(:disabled?, disabled?)} | ||
| end | ||
|
|
||
| def render(assigns) do | ||
| ~H""" | ||
| <div class="mt-4"> | ||
| <div class={@class}> | ||
| <div class="my-2 flex items-center"> | ||
| <button | ||
| type="button" | ||
| phx-click="toggle" | ||
| phx-target={@myself} | ||
| class={[ | ||
| "relative inline-flex flex-shrink-0 h-6 w-11 border-2 border-transparent rounded-full transition-colors ease-in-out duration-200", | ||
| if(@current_setting, do: "bg-indigo-600", else: "bg-gray-200 dark:bg-gray-600"), | ||
| if(@disabled?, do: "cursor-not-allowed") | ||
| ]} | ||
| disabled={@disabled?} | ||
| > | ||
| <span | ||
| aria-hidden="true" | ||
| class={[ | ||
| "inline-block size-5 rounded-full bg-white shadow transform transition ease-in-out duration-200", | ||
| if(@current_setting, do: "translate-x-5", else: "translate-x-0") | ||
| ]} | ||
| /> | ||
| </button> | ||
|
|
||
| <span class={[ | ||
| "ml-2 font-medium leading-5 text-sm", | ||
| if(@disabled?, | ||
| do: "text-gray-500 dark:text-gray-400", | ||
| else: "text-gray-900 dark:text-gray-100" | ||
| ) | ||
| ]}> | ||
| Show in dashboard | ||
| </span> | ||
| </div> | ||
| </div> | ||
|
|
||
| <div :if={@current_setting}> | ||
| {render_slot(@inner_block)} | ||
| </div> | ||
| </div> | ||
| """ | ||
| end | ||
|
|
||
| def handle_event("toggle", _params, socket) do | ||
| site = socket.assigns.site | ||
| feature_mod = socket.assigns.feature_mod | ||
| current_user = socket.assigns.current_user | ||
|
|
||
| case feature_mod.toggle(site, current_user) do | ||
| {:ok, updated_site} -> | ||
| new_setting = Map.fetch!(updated_site, feature_mod.toggle_field()) | ||
|
|
||
| message = | ||
| if new_setting do | ||
| "#{feature_mod.display_name()} are now visible again on your dashboard" | ||
| else | ||
| "#{feature_mod.display_name()} are now hidden from your dashboard" | ||
| end | ||
|
|
||
| {:noreply, | ||
| socket | ||
| |> assign(:site, updated_site) | ||
| |> assign(:current_setting, feature_mod.enabled?(updated_site)) | ||
| |> put_flash(:success, message)} | ||
|
|
||
| {:error, _} -> | ||
| {:noreply, | ||
| socket | ||
| |> put_flash( | ||
| :error, | ||
| "Something went wrong. Failed to toggle #{feature_mod.display_name()} on your dashboard." | ||
| )} | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!💡