fix: issue #20 cmd-J panel tab strip visibility and output panel parity
This commit is contained in:
@@ -182,6 +182,7 @@ defmodule BDS.Desktop.ShellLive do
|
||||
|> assign(:shell_overlay, nil)
|
||||
|> assign(:git_run, nil)
|
||||
|> assign(:output_entries, [])
|
||||
|> assign(:collapsed_task_groups, MapSet.new())
|
||||
|> assign(:panel_post_links, %{backlinks: [], outlinks: []})
|
||||
|> assign(:panel_git_entries, [])
|
||||
|> assign(:auto_save_timers, %{})
|
||||
@@ -226,6 +227,38 @@ defmodule BDS.Desktop.ShellLive do
|
||||
{:noreply, refresh_layout(socket, workbench)}
|
||||
end
|
||||
|
||||
# Copy-all for the Output panel: entries are stored newest-first, so flip
|
||||
# them back to chronological order before joining (old-app behavior).
|
||||
def handle_event("copy_output", _params, socket) do
|
||||
text =
|
||||
socket.assigns.output_entries
|
||||
|> Enum.reverse()
|
||||
|> Enum.map_join("\n\n", & &1.message)
|
||||
|
||||
{:noreply, push_event(socket, "clipboard", %{text: text})}
|
||||
end
|
||||
|
||||
def handle_event("toggle_task_group", %{"group" => group_id}, socket) do
|
||||
collapsed = socket.assigns[:collapsed_task_groups] || MapSet.new()
|
||||
|
||||
collapsed =
|
||||
if MapSet.member?(collapsed, group_id),
|
||||
do: MapSet.delete(collapsed, group_id),
|
||||
else: MapSet.put(collapsed, group_id)
|
||||
|
||||
{:noreply, assign(socket, :collapsed_task_groups, collapsed)}
|
||||
end
|
||||
|
||||
def handle_event("cancel_task", %{"id" => task_id}, socket) do
|
||||
_ = BDS.Tasks.cancel_task(task_id)
|
||||
|
||||
task_status =
|
||||
BDS.Tasks.status_snapshot()
|
||||
|> BDS.Desktop.ShellLive.TaskLocalization.localize_task_status(socket.assigns.page_language)
|
||||
|
||||
{:noreply, assign(socket, :task_status, task_status)}
|
||||
end
|
||||
|
||||
def handle_event("open_sidebar_item", %{"route" => _route, "id" => _id} = params, socket) do
|
||||
{:noreply, open_sidebar_item(socket, params, :preview)}
|
||||
end
|
||||
@@ -860,33 +893,66 @@ defmodule BDS.Desktop.ShellLive do
|
||||
end
|
||||
|
||||
defp import_blogmark(socket, project_id, url, title) do
|
||||
case Blogmark.receive_deep_link(project_id, url) do
|
||||
{:ok, %{post: post, toasts: toasts, errors: errors}} ->
|
||||
socket
|
||||
|> reload_shell(socket.assigns.workbench)
|
||||
|> open_sidebar_item(
|
||||
%{
|
||||
"route" => "post",
|
||||
"id" => post.id,
|
||||
"title" => post.title,
|
||||
"subtitle" => post.slug
|
||||
},
|
||||
:pin
|
||||
)
|
||||
|> append_blogmark_toasts(title, toasts)
|
||||
|> append_blogmark_errors(title, errors)
|
||||
# Transform scripts run in the sandbox process; collect anything they
|
||||
# print/log so it lands in the Output panel like in the old app.
|
||||
{:ok, output_sink} = Agent.start_link(fn -> [] end)
|
||||
|
||||
{:error, reason} ->
|
||||
append_output_entry(socket, title, inspect(reason), url, "error")
|
||||
sink = fn text -> Agent.update(output_sink, fn lines -> [text | lines] end) end
|
||||
|
||||
try do
|
||||
case Blogmark.receive_deep_link(project_id, url, on_output: sink) do
|
||||
{:ok, %{post: post, toasts: toasts, errors: errors}} ->
|
||||
script_output = Agent.get(output_sink, &Enum.reverse/1)
|
||||
|
||||
socket
|
||||
|> reload_shell(socket.assigns.workbench)
|
||||
|> open_sidebar_item(
|
||||
%{
|
||||
"route" => "post",
|
||||
"id" => post.id,
|
||||
"title" => post.title,
|
||||
"subtitle" => post.slug
|
||||
},
|
||||
:pin
|
||||
)
|
||||
|> append_blogmark_script_output(title, script_output)
|
||||
|> append_blogmark_toasts(title, toasts)
|
||||
|> append_blogmark_errors(title, errors)
|
||||
|> open_output_panel_when(script_output != [] or errors != [])
|
||||
|
||||
{:error, reason} ->
|
||||
append_output_entry(socket, title, inspect(reason), url, "error")
|
||||
end
|
||||
after
|
||||
Agent.stop(output_sink)
|
||||
end
|
||||
end
|
||||
|
||||
defp append_blogmark_script_output(socket, title, lines) do
|
||||
Enum.reduce(lines, socket, fn line, acc ->
|
||||
append_output_entry(acc, title, line, nil, "info")
|
||||
end)
|
||||
end
|
||||
|
||||
defp append_blogmark_toasts(socket, title, toasts) do
|
||||
Enum.reduce(toasts, socket, fn message, acc ->
|
||||
append_output_entry(acc, title, message, nil, "info")
|
||||
end)
|
||||
end
|
||||
|
||||
# Old-app parity: transform errors or streamed script output open the
|
||||
# bottom panel on the Output tab so the user actually sees them.
|
||||
defp open_output_panel_when(socket, true) do
|
||||
workbench =
|
||||
socket.assigns.workbench
|
||||
|> Workbench.set_panel_visible(true)
|
||||
|> Workbench.set_panel_tab(:output)
|
||||
|
||||
refresh_layout(socket, workbench)
|
||||
end
|
||||
|
||||
defp open_output_panel_when(socket, false), do: socket
|
||||
|
||||
defp append_blogmark_errors(socket, title, errors) do
|
||||
Enum.reduce(errors, socket, fn %{slug: slug, reason: reason}, acc ->
|
||||
append_output_entry(acc, title, inspect(reason), slug, "error")
|
||||
|
||||
Reference in New Issue
Block a user