Skip to content

Commit

Permalink
This works but it's wonky
Browse files Browse the repository at this point in the history
  • Loading branch information
cibernox committed Dec 1, 2024
1 parent 725ce85 commit 4391d80
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
17 changes: 7 additions & 10 deletions lib/beacon/live_admin/components/properties_sidebar_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defmodule Beacon.LiveAdmin.PropertiesSidebarComponent do
alias Beacon.LiveAdmin.VisualEditor.ClassControl
alias Beacon.LiveAdmin.VisualEditor.OpacityControl
alias Beacon.LiveAdmin.VisualEditor.KeyValueControl
require Logger

def update(%{selected_element_path: nil} = assigns, socket) do
{:ok,
socket
Expand All @@ -14,9 +14,7 @@ require Logger
|> assign(selected_element: nil)}
end

def update(assigns, socket) do
%{page: %{ast: page}, selected_element_path: selected_element_path} = assigns

def update(%{page: %{ast: page}, selected_element_path: selected_element_path} = assigns, socket) do
selected_element =
case VisualEditor.find_element(page, selected_element_path) do
nil ->
Expand All @@ -27,17 +25,16 @@ require Logger
Map.put(selected_element, "path", selected_element_path)
end

Logger.debug("################################")
Logger.debug("################################")
Logger.debug("################################")
Logger.debug("################################")
dbg(assigns)
{:ok,
socket
|> assign(assigns)
|> assign(selected_element: selected_element)}
end

def update(assigns, socket) do
{:ok, assign(socket, assigns)}
end

defp other_attributes(selected_element) do
Enum.filter(selected_element["attrs"], fn {k, _} -> k != "class" end)
end
Expand All @@ -48,7 +45,7 @@ require Logger

def render(assigns) do
~H"""
<div id="properties-sidebar" class="mt-4 w-64 bg-white" data-testid="right-sidebar">
<div id={@id} class="mt-4 w-64 bg-white" data-testid="right-sidebar">
<div :if={@selected_element} class="sticky top-0 overflow-y-auto h-screen">
<div class="border-b text-lg font-medium leading-5 p-4 relative">
<%= @selected_element["tag"] %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ defmodule Beacon.LiveAdmin.VisualEditor.KeyValueControl do
"""
end

# # FIXME: avoid remount to preserve state
# def mount(socket) do
# {:ok,
# socket
# |> assign(edit_name: true, name: "", value: "")}
# end

def update(assigns, socket) do
name = Map.get(assigns, :name, "")
value = Map.get(assigns, :value, "")
Expand All @@ -58,7 +51,7 @@ defmodule Beacon.LiveAdmin.VisualEditor.KeyValueControl do
%{name: name, value: value} = socket.assigns
if value != "" do
send(self(), {:updated_element, {socket.assigns.element["path"], %{"attrs" => %{name => value}}}})
send_update(Beacon.LiveAdmin.PropertiesSidebarComponent, id: "properties-sidebar", add_new_attribute: false)
send_update(Beacon.LiveAdmin.PropertiesSidebarComponent, id: "properties_sidebar", add_new_attribute: false)
end
{:noreply, socket}
end
Expand Down

0 comments on commit 4391d80

Please sign in to comment.