|
| 1 | +defmodule LiveDebuggerWeb.SettingsLive do |
| 2 | + @moduledoc """ |
| 3 | + LiveView for the settings page. |
| 4 | + """ |
| 5 | + |
| 6 | + use LiveDebuggerWeb, :live_view |
| 7 | + |
| 8 | + alias LiveDebuggerWeb.Components.Navbar |
| 9 | + alias LiveDebuggerWeb.Helpers.RoutesHelper |
| 10 | + |
| 11 | + @impl true |
| 12 | + def render(assigns) do |
| 13 | + ~H""" |
| 14 | + <div class="flex-1 min-w-[25rem] grid grid-rows-[auto_1fr]"> |
| 15 | + <Navbar.navbar class="flex"> |
| 16 | + <Navbar.return_link return_link={RoutesHelper.live_views_dashboard()} /> |
| 17 | + <Navbar.live_debugger_logo /> |
| 18 | + </Navbar.navbar> |
| 19 | + <div class="flex-1 max-lg:p-8 pt-8 lg:w-[60rem] lg:m-auto"> |
| 20 | + <div class="flex items-center justify-between"> |
| 21 | + <.h1>Settings</.h1> |
| 22 | + </div> |
| 23 | +
|
| 24 | + <%!-- Upper section --%> |
| 25 | + <div class="mt-6 bg-surface-0-bg rounded shadow-custom border border-default-border"> |
| 26 | + <%!-- Appearance --%> |
| 27 | + <div class="p-6"> |
| 28 | + <p class="font-semibold mb-3">Appearance</p> |
| 29 | + <div class="flex gap-2"> |
| 30 | + <.dark_mode_button /> |
| 31 | + <.light_mode_button /> |
| 32 | + </div> |
| 33 | + </div> |
| 34 | + <%!-- Checkboxes --%> |
| 35 | + <div class="p-6 border-t border-default-border flex flex-col gap-3"> |
| 36 | + <.settings_switch |
| 37 | + label="Enable DeadView mode" |
| 38 | + description="When enabled, LiveDebugger won't redirect to new LiveView after page redirect or reload, allowing you to browse assigns and traces of dead LiveViews." |
| 39 | + checked={false} |
| 40 | + phx-click="update" |
| 41 | + phx-value-setting="deadview_mode" |
| 42 | + /> |
| 43 | +
|
| 44 | + <.settings_switch |
| 45 | + label="Enable global tracing" |
| 46 | + description="Enabling this feature may have a negative impact on application performance." |
| 47 | + checked={false} |
| 48 | + phx-click="update" |
| 49 | + phx-value-setting="global_tracing" |
| 50 | + /> |
| 51 | +
|
| 52 | + <.settings_switch |
| 53 | + label="Refresh tracing on reload" |
| 54 | + description="Enabling this feature may have a negative impact on application performance." |
| 55 | + checked={false} |
| 56 | + phx-click="update" |
| 57 | + phx-value-setting="refresh_tracing_on_reload" |
| 58 | + /> |
| 59 | + </div> |
| 60 | + </div> |
| 61 | +
|
| 62 | + <%!-- Lower section --%> |
| 63 | + <div class="mt-6 bg-surface-0-bg rounded shadow-custom border border-default-border"> |
| 64 | + <%!-- Restart button --%> |
| 65 | + <div class="p-6 flex flex-col md:flex-row justify-between md:items-center gap-4"> |
| 66 | + <div class="flex flex-col gap-1"> |
| 67 | + <p class="font-semibold">Restart LiveDebugger</p> |
| 68 | + <p class="text-secondary-text"> |
| 69 | + Use this option if LiveDebugger appears to stop responding or not working properly. |
| 70 | + </p> |
| 71 | + </div> |
| 72 | + <.button variant="secondary" phx-click="restart">Restart LiveDebugger</.button> |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + </div> |
| 76 | + </div> |
| 77 | + """ |
| 78 | + end |
| 79 | + |
| 80 | + @impl true |
| 81 | + def handle_event("update", %{"setting" => _setting}, socket) do |
| 82 | + {:noreply, socket} |
| 83 | + end |
| 84 | + |
| 85 | + @impl true |
| 86 | + def handle_event("restart", _, socket) do |
| 87 | + {:noreply, socket} |
| 88 | + end |
| 89 | + |
| 90 | + attr(:label, :string, required: true) |
| 91 | + attr(:description, :string, required: true) |
| 92 | + attr(:checked, :boolean, default: false) |
| 93 | + attr(:rest, :global) |
| 94 | + |
| 95 | + defp settings_switch(assigns) do |
| 96 | + ~H""" |
| 97 | + <div class="flex items-center"> |
| 98 | + <.toggle_switch checked={@checked} wrapper_class="pr-3 py-0" {@rest} /> |
| 99 | + <div class="flex flex-col gap-0.5"> |
| 100 | + <p class="font-semibold"><%= @label %></p> |
| 101 | + <p class="text-secondary-text"><%= @description %></p> |
| 102 | + </div> |
| 103 | + </div> |
| 104 | + """ |
| 105 | + end |
| 106 | + |
| 107 | + defp dark_mode_button(assigns) do |
| 108 | + ~H""" |
| 109 | + <.mode_button |
| 110 | + id="dark-mode-switch" |
| 111 | + icon="icon-moon" |
| 112 | + text="Dark" |
| 113 | + class="dark:hidden text-button-secondary-content bg-button-secondary-bg hover:bg-button-secondary-bg-hover border border-default-border" |
| 114 | + phx-hook="ToggleTheme" |
| 115 | + /> |
| 116 | + <.mode_button |
| 117 | + icon="icon-moon" |
| 118 | + text="Dark" |
| 119 | + class="hidden dark:flex text-button-primary-content bg-button-primary-bg" |
| 120 | + /> |
| 121 | + """ |
| 122 | + end |
| 123 | + |
| 124 | + defp light_mode_button(assigns) do |
| 125 | + ~H""" |
| 126 | + <.mode_button |
| 127 | + id="light-mode-switch" |
| 128 | + icon="icon-sun" |
| 129 | + text="Light" |
| 130 | + class="hidden dark:flex text-button-secondary-content bg-button-secondary-bg hover:bg-button-secondary-bg-hover border border-default-border" |
| 131 | + phx-hook="ToggleTheme" |
| 132 | + /> |
| 133 | + <.mode_button |
| 134 | + icon="icon-sun" |
| 135 | + text="Light" |
| 136 | + class="dark:hidden text-button-primary-content bg-button-primary-bg" |
| 137 | + /> |
| 138 | + """ |
| 139 | + end |
| 140 | + |
| 141 | + attr(:icon, :string, required: true) |
| 142 | + attr(:text, :string, required: true) |
| 143 | + attr(:class, :string, default: "") |
| 144 | + attr(:rest, :global) |
| 145 | + |
| 146 | + defp mode_button(assigns) do |
| 147 | + ~H""" |
| 148 | + <button |
| 149 | + class={[ |
| 150 | + "flex items-center justify-center gap-2 py-2 px-4 rounded", |
| 151 | + @class |
| 152 | + ]} |
| 153 | + {@rest} |
| 154 | + > |
| 155 | + <.icon name={@icon} class="w-5 h-5" /> |
| 156 | + <p><%= @text %></p> |
| 157 | + </button> |
| 158 | + """ |
| 159 | + end |
| 160 | +end |
0 commit comments