@@ -6,6 +6,7 @@ defmodule LiveDebuggerWeb.Components.Navbar do
66 use LiveDebuggerWeb , :component
77
88 alias LiveDebuggerWeb.Helpers.RoutesHelper
9+ alias LiveDebugger.Utils.Parsers
910
1011 @ doc """
1112 Renders base navbar component.
@@ -83,27 +84,22 @@ defmodule LiveDebuggerWeb.Components.Navbar do
8384 When button is clicked, it will trigger a `find-successor` event with the PID of the LiveView.
8485 """
8586 attr ( :id , :string , required: true )
86- attr ( :connected? , :boolean , required: true , doc: "Whether LiveView is connected." )
87- attr ( :pid , :string , required: true , doc: "The PID of the LiveView." )
87+ attr ( :lv_process , :map , required: true , doc: "The LiveView process." )
8888 attr ( :rest , :global )
8989
90- def connected ( assigns ) do
90+ def connected ( % { lv_process: % { ok?: true } } = assigns ) do
91+ connected? = assigns . lv_process . result . alive?
92+ status = if ( connected? , do: :connected , else: :disconnected )
93+
94+ assigns = assign ( assigns , status: status , connected?: connected? )
95+
9196 ~H"""
92- < . tooltip
93- id = { @ id }
94- position = "bottom "
95- content = {
96- if ( @ connected? ,
97- do: "LiveView process is alive." ,
98- else: "LiveView process is dead. You can still debug the last state."
99- )
100- }
101- >
97+ < . tooltip id = { @ id } position = "bottom " content = { tooltip_content ( @ connected? ) } >
10298 < div id = { @ id } class = "flex items-center gap-1 text-xs text-primary ml-1 " >
103- < . status_icon connected? = { @ connected? } />
99+ < . status_icon status = { @ status } />
104100 <%= if @ connected? do %>
105101 < span class = "font-medium " > Monitored PID </ span >
106- <%= @ pid %>
102+ <%= Parsers . pid_to_string ( @ lv_process . result . pid ) %>
107103 <% else %>
108104 < span class = "font-medium " > Disconnected</ span >
109105 < . button phx-click = "find-successor " variant = "secondary " size = "sm " > Continue</ . button >
@@ -113,19 +109,42 @@ defmodule LiveDebuggerWeb.Components.Navbar do
113109 """
114110 end
115111
116- attr ( :connected? , :boolean , required: true )
112+ def connected ( assigns ) do
113+ ~H"""
114+ < div id = { @ id } class = "flex items-center gap-1 text-xs text-primary ml-1 " >
115+ < . status_icon status = { :loading } />
116+ < span class = "font-medium " > Loading LiveView process...</ span >
117+ </ div >
118+ """
119+ end
120+
121+ attr ( :status , :atom , required: true , values: [ :connected , :disconnected , :loading ] )
117122
118123 defp status_icon ( assigns ) do
124+ assigns =
125+ case ( assigns . status ) do
126+ :connected ->
127+ assign ( assigns , icon: "icon-check-small" , class: "bg-[--swm-green-100]" )
128+
129+ :disconnected ->
130+ assign ( assigns , icon: "icon-cross-small" , class: "bg-[--swm-pink-100]" )
131+
132+ :loading ->
133+ assign ( assigns , icon: nil , class: "bg-[--swm-yellow-100] animate-pulse" )
134+ end
135+
119136 ~H"""
120- < div class = { [
121- "w-4 h-4 rounded-full flex items-center justify-center" ,
122- if ( @ connected? , do: "bg-[--swm-green-100]" , else: "bg-[--swm-pink-100]" )
123- ] } >
124- < . icon
125- name = { if ( @ connected? , do: "icon-check-small" , else: "icon-cross-small" ) }
126- class = "bg-white w-4 h-4 "
127- />
137+ < div class = { [ "w-4 h-4 rounded-full flex items-center justify-center" , @ class ] } >
138+ < . icon :if = { @ icon } name = { @ icon } class = "bg-white w-4 h-4 " />
128139 </ div >
129140 """
130141 end
142+
143+ defp tooltip_content ( true ) do
144+ "LiveView process is alive"
145+ end
146+
147+ defp tooltip_content ( false ) do
148+ "LiveView process is dead - you can still debug the last state"
149+ end
131150end
0 commit comments