Skip to content
This repository has been archived by the owner on Dec 8, 2023. It is now read-only.

Commit

Permalink
add selector sender to parent for saving config, based on #44, #4, #60
Browse files Browse the repository at this point in the history
  • Loading branch information
shahryarjb committed Mar 22, 2023
1 parent c6a65c8 commit 755cc50
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
17 changes: 9 additions & 8 deletions lib/mishka_template_creator/components/blocks/config_selector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ defmodule MishkaTemplateCreator.Components.ConfigSelector do
id={"select_search-#{@id}"}
name="select_search"
type="search"
phx-click="click"
phx-target={@myself}
autocomplete="off"
/>
Expand Down Expand Up @@ -73,10 +71,6 @@ defmodule MishkaTemplateCreator.Components.ConfigSelector do
end

@impl true
def handle_event("click", %{"value" => _value}, socket) do
{:noreply, socket}
end

def handle_event("query", %{"select_search" => value, "myself" => myself}, socket) do
form_configs = socket.assigns.selected_setting.form_configs

Expand All @@ -102,8 +96,15 @@ defmodule MishkaTemplateCreator.Components.ConfigSelector do
{:noreply, socket}
end

def handle_event("save", params, socket) do
IO.inspect(params)
def handle_event("save", %{"extra_config" => extra_config, "config" => config}, socket) do
%{block_id: block_id, block_type: block_type} = socket.assigns.selected_setting

send(
self(),
{"add_element_config",
%{block_id: block_id, block_type: block_type, extra_config: extra_config, config: config}}
)

{:noreply, socket}
end

Expand Down
17 changes: 9 additions & 8 deletions lib/mishka_template_creator_web/live/template_creator_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule MishkaTemplateCreatorWeb.TemplateCreatorLive do
use Phoenix.LiveView
import MishkaTemplateCreatorWeb.MishkaCoreComponent

@impl true
def render(assigns) do
~H"""
<.dashboard
Expand All @@ -16,13 +17,15 @@ defmodule MishkaTemplateCreatorWeb.TemplateCreatorLive do

# TODO: create multi layout sections and store in a Genserver or ETS
# TODO: create multisection in a layout and store them under the layout
@impl true
def mount(_params, _, socket) do
new_socket =
assign(socket, elemens: [], selected_block: nil, submit: true, selected_setting: nil)

{:ok, new_socket}
end

@impl true
def handle_event(
"dropped_element",
%{"index" => index, "type" => type, "parent" => parent, "parent_id" => parent_id},
Expand Down Expand Up @@ -144,14 +147,6 @@ defmodule MishkaTemplateCreatorWeb.TemplateCreatorLive do
{:noreply, assign(socket, :selected_setting, nil)}
end

def handle_event("save_config", _params, socket) do
{:noreply, socket}
end

def handle_event("search_config", _params, socket) do
{:noreply, socket}
end

def handle_event(
"change_order",
%{
Expand All @@ -169,6 +164,12 @@ defmodule MishkaTemplateCreatorWeb.TemplateCreatorLive do
{:noreply, assign(socket, elemens: elemens)}
end

@impl true
def handle_info({"add_element_config", selected_config}, socket) do
IO.inspect(selected_config)
{:noreply, socket}
end

def update_elements(nil, socket, _, _), do: {:noreply, socket}

def update_elements(new_element, socket, parent, event) do
Expand Down

0 comments on commit 755cc50

Please sign in to comment.