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