Current section
Files
Jump to
Current section
Files
lib/live_debugger/app/discovery/web/discovery_live.ex
defmodule LiveDebugger.App.Discovery.Web.DiscoveryLive do
@moduledoc """
LiveView page for discovering all active and dead LiveView sessions in the debugged application.
"""
use LiveDebugger.App.Web, :live_view
alias LiveDebugger.App.Discovery.Web.LiveComponents.ActiveLiveViews
alias LiveDebugger.App.Discovery.Web.LiveComponents.DeadLiveViews
alias LiveDebugger.App.Events.UserChangedSettings
alias LiveDebugger.App.Web.Components.Navbar, as: NavbarComponents
alias LiveDebugger.App.Web.Hooks.TracerStatus, as: TracerStatusHook
alias LiveDebugger.App.Web.LiveComponents.TracerStatus
alias LiveDebugger.Bus
alias LiveDebugger.Services.GarbageCollector.Events.TableTrimmed
alias LiveDebugger.Services.ProcessMonitor.Events.LiveViewBorn
alias LiveDebugger.Services.ProcessMonitor.Events.LiveViewDied
@impl true
def mount(_params, _session, socket) do
if connected?(socket) do
Bus.receive_events!()
end
socket
|> TracerStatusHook.init()
|> ok()
end
@impl true
def render(assigns) do
~H"""
<div class="h-full flex-1 min-w-[25rem] grid grid-rows-[auto_1fr]">
<div>
<.live_component module={TracerStatus} id="tracer-status" tracer_started?={@tracer_started?} />
<NavbarComponents.navbar class="flex justify-between">
<NavbarComponents.live_debugger_logo />
<div class="flex items-center gap-2">
<NavbarComponents.garbage_collection_warning />
<NavbarComponents.settings_button return_to={@url} />
</div>
</NavbarComponents.navbar>
</div>
<div class="h-full flex flex-col">
<.live_component module={ActiveLiveViews} id="active-live-views" />
<.live_component module={DeadLiveViews} id="dead-live-views" />
</div>
</div>
"""
end
@impl true
def handle_info(%LiveViewBorn{}, socket) do
ActiveLiveViews.refresh("active-live-views")
{:noreply, socket}
end
def handle_info(%LiveViewDied{}, socket) do
ActiveLiveViews.refresh("active-live-views")
DeadLiveViews.refresh("dead-live-views")
{:noreply, socket}
end
def handle_info(%TableTrimmed{}, socket) do
DeadLiveViews.refresh("dead-live-views")
{:noreply, socket}
end
def handle_info(%UserChangedSettings{key: :dead_liveviews, value: value}, socket) do
send_update(DeadLiveViews, id: "dead-live-views", dead_liveviews?: value)
{:noreply, socket}
end
def handle_info(_, socket), do: {:noreply, socket}
end