Skip to content

Commit

Permalink
prepare move & indent nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
sorax committed May 21, 2024
1 parent 80fccbe commit 2cbbf8a
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 27 deletions.
50 changes: 25 additions & 25 deletions assets/js/hooks/events/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,30 +127,30 @@ export function keydown(event: KeyboardEvent) {
this.pushEvent("delete_node", nextNode);
break;

// case "Tab":
// event.preventDefault();

// if (event.shiftKey) {
// if (node.parent_id) {
// // outdent
// node.prev_id = node.parent_id;
// node.parent_id = undefined;
// updateItem(node, container);

// focusItem(item);
// this.pushEvent("update_node", node);
// }
// } else {
// if (node.prev_id) {
// // indent
// node.parent_id = node.prev_id;
// node.prev_id = undefined; // TODO: prev_id should be the id of the last child of the parent node
// updateItem(node, container);

// focusItem(item);
// this.pushEvent("update_node", node);
// }
// }
// break;
case "Tab":
event.preventDefault();

if (event.shiftKey) {
// outdent
// if (node.parent_id) {
// node.prev_id = node.parent_id;
// node.parent_id = undefined;
// updateItem(node, container);

// focusItem(item);
// this.pushEvent("update_node", node);
// }
} else {
// indent
if (node.prev_id) {
node.parent_id = node.prev_id;
node.prev_id = undefined; // TODO: prev_id should be the id of the last child of the parent node
updateItem(node, container);

// focusItem(item);
this.pushEvent("move_node", node);
}
}
break;
}
}
21 changes: 20 additions & 1 deletion lib/radiator/outline/event_consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ defmodule Radiator.Outline.EventConsumer do

alias Radiator.EventStore
alias Radiator.Outline
alias Radiator.Outline.Command.{ChangeNodeContentCommand, DeleteNodeCommand, InsertNodeCommand}

alias Radiator.Outline.Command.{
ChangeNodeContentCommand,
DeleteNodeCommand,
InsertNodeCommand,
MoveNodeCommand
}

alias Radiator.Outline.Dispatch
alias Radiator.Outline.Event.{NodeContentChangedEvent, NodeDeletedEvent, NodeInsertedEvent}
alias Radiator.Outline.NodeRepository
Expand Down Expand Up @@ -41,6 +48,18 @@ defmodule Radiator.Outline.EventConsumer do
|> handle_change_node_content_result(command)
end

defp process_command(
%MoveNodeCommand{
node_id: _node_id,
parent_node_id: _parent_node_id,
prev_node_id: _prev_node_id
} = _command
) do
# node_id
# |> Outline.update_node_content(content)
# |> handle_change_node_content_result(command)
end

defp process_command(%DeleteNodeCommand{node_id: node_id} = command) do
case NodeRepository.get_node(node_id) do
nil -> Logger.error("Could not remove node. Node not found.")
Expand Down
16 changes: 15 additions & 1 deletion lib/radiator_web/live/episode_live/index.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ defmodule RadiatorWeb.EpisodeLive.Index do
|> reply(:noreply)
end

# seperate update content & move node in frontent/js
def handle_event("update_node", %{"uuid" => uuid, "content" => content}, socket) do
user = socket.assigns.current_user

Expand All @@ -68,6 +67,21 @@ defmodule RadiatorWeb.EpisodeLive.Index do
|> reply(:noreply)
end

def handle_event("move_node", %{"uuid" => uuid} = node, socket) do
user = socket.assigns.current_user

Dispatch.move_node(
uuid,
node["parent_id"],
node["prev_id"],
user.id,
generate_event_id(socket.id)
)

socket
|> reply(:noreply)
end

def handle_event("delete_node", %{"uuid" => uuid}, socket) do
user = socket.assigns.current_user

Expand Down

0 comments on commit 2cbbf8a

Please sign in to comment.