From b6e137632a6a71d0a5eb37c58f8053ac55cf35e1 Mon Sep 17 00:00:00 2001 From: Schuwi Date: Wed, 17 Sep 2025 17:57:40 +0200 Subject: [PATCH] feat(elixir): add component list focus mode --- .../live/components_live.ex | 347 +++++++++++++----- 1 file changed, 263 insertions(+), 84 deletions(-) diff --git a/lib/components_elixir_web/live/components_live.ex b/lib/components_elixir_web/live/components_live.ex index b230e1f..533bae6 100644 --- a/lib/components_elixir_web/live/components_live.ex +++ b/lib/components_elixir_web/live/components_live.ex @@ -35,6 +35,7 @@ defmodule ComponentsElixirWeb.ComponentsLive do |> assign(:form, nil) |> assign(:show_image_modal, false) |> assign(:modal_image_url, nil) + |> assign(:focused_component_id, nil) |> allow_upload(:image, accept: ~w(.jpg .jpeg .png .gif), max_entries: 1, @@ -207,6 +208,19 @@ defmodule ComponentsElixirWeb.ComponentsLive do |> assign(:modal_image_url, nil)} end + def handle_event("toggle_focus", %{"id" => id}, socket) do + component_id = String.to_integer(id) + + new_focused_id = + if socket.assigns.focused_component_id == component_id do + nil # Unfocus if clicking on the same component + else + component_id # Focus on the new component + end + + {:noreply, assign(socket, :focused_component_id, new_focused_id)} + end + def handle_event("prevent_close", _params, socket) do {:noreply, socket} end @@ -675,26 +689,14 @@ defmodule ComponentsElixirWeb.ComponentsLive do