defmodule ToweropsWeb.Live.Components.StatusTitleComponent do @moduledoc """ LiveComponent that subscribes to organization alert changes and updates the page title emoji. """ use ToweropsWeb, :live_component alias ToweropsWeb.Helpers.StatusHelpers def mount(socket) do {:ok, socket} end def update(%{organization_id: org_id}, socket) do if connected?(socket) do Phoenix.PubSub.subscribe(Towerops.PubSub, "organization:#{org_id}:alerts") end {:ok, assign(socket, :organization_id, org_id)} end def handle_info({:alert_changed, _org_id}, socket) do # Get the organization from the parent socket org_id = socket.assigns.organization_id organization = Towerops.Organizations.get_organization!(org_id) if organization do emoji = StatusHelpers.status_emoji(organization) # Push event to JavaScript hook to update the browser title {:noreply, push_event(socket, "update_status_emoji", %{emoji: emoji})} else {:noreply, socket} end end def render(assigns) do ~H""" """ end end