feat: persisted tabs
This commit is contained in:
@@ -13,7 +13,7 @@ defmodule BDS.Desktop.ShellLive do
|
||||
alias BDS.Posts.Post
|
||||
alias BDS.Projects
|
||||
alias BDS.Repo
|
||||
alias BDS.UI.{Commands, MenuBar, Registry, Workbench}
|
||||
alias BDS.UI.{Commands, MenuBar, Registry, Session, Workbench}
|
||||
|
||||
@refresh_interval 1_500
|
||||
@output_entry_limit 20
|
||||
@@ -359,6 +359,10 @@ defmodule BDS.Desktop.ShellLive do
|
||||
{:noreply, set_page_language(socket, language)}
|
||||
end
|
||||
|
||||
def handle_event("restore_workbench_session", %{"session" => session_payload}, socket) when is_map(session_payload) do
|
||||
{:noreply, reload_shell(socket, restore_workbench_session(session_payload))}
|
||||
end
|
||||
|
||||
def handle_event("native_menu_action", %{"action" => action}, socket) do
|
||||
{:noreply, handle_native_menu_action(socket, action)}
|
||||
end
|
||||
@@ -1006,6 +1010,8 @@ defmodule BDS.Desktop.ShellLive do
|
||||
|
||||
defp encoded_shortcuts(shortcuts), do: Jason.encode!(shortcuts)
|
||||
|
||||
defp encoded_workbench_session(workbench), do: Jason.encode!(Session.serialize(workbench))
|
||||
|
||||
defp panel_tab_label(:tasks), do: translated("Tasks")
|
||||
defp panel_tab_label(:output), do: translated("Output")
|
||||
defp panel_tab_label(:git_log), do: translated("Git Log")
|
||||
@@ -1319,7 +1325,7 @@ defmodule BDS.Desktop.ShellLive do
|
||||
|> assign(:project_menu_open, false)
|
||||
|> assign(:sidebar_filters_by_view, %{})
|
||||
|> append_output_entry(title, message_fun.(project))
|
||||
|> reload_shell(Workbench.clear_tabs(socket.assigns.workbench))
|
||||
|> reload_shell(Workbench.new())
|
||||
|
||||
{:error, reason} ->
|
||||
socket
|
||||
@@ -1357,6 +1363,12 @@ defmodule BDS.Desktop.ShellLive do
|
||||
end
|
||||
end
|
||||
|
||||
defp restore_workbench_session(session_payload) do
|
||||
Session.restore(session_payload)
|
||||
rescue
|
||||
_error -> Workbench.new()
|
||||
end
|
||||
|
||||
defp safe_existing_atom(action) when is_binary(action) do
|
||||
String.to_existing_atom(action)
|
||||
rescue
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
<div class="app" id="bds-shell-app" phx-hook="AppShell" data-shortcuts={encoded_shortcuts(@client_shortcuts)}>
|
||||
<div
|
||||
class="app"
|
||||
id="bds-shell-app"
|
||||
phx-hook="AppShell"
|
||||
data-shortcuts={encoded_shortcuts(@client_shortcuts)}
|
||||
data-project-id={@projects.active_project_id || ""}
|
||||
data-workbench-session={encoded_workbench_session(@workbench)}
|
||||
>
|
||||
<%= if @is_mac_ui do %>
|
||||
<span data-testid="window-title" hidden><%= @page_title %></span>
|
||||
<% end %>
|
||||
|
||||
@@ -32,18 +32,18 @@ defmodule BDS.UI.Session do
|
||||
Workbench.new(
|
||||
sidebar_visible: Map.get(payload, "sidebar_visible", true),
|
||||
sidebar_width: Map.get(payload, "sidebar_width", 280),
|
||||
active_view: Map.get(payload, "active_view", "posts"),
|
||||
active_view: atomize(Map.get(payload, "active_view"), :posts),
|
||||
assistant_sidebar_visible: Map.get(payload, "assistant_sidebar_visible", false),
|
||||
assistant_sidebar_width: Map.get(payload, "assistant_sidebar_width", 360),
|
||||
panel_visible: get_in(payload, ["panel", "visible"]) || false,
|
||||
panel_tab: atomize(get_in(payload, ["panel", "active_tab"]) || "tasks"),
|
||||
panel_tab: atomize(get_in(payload, ["panel", "active_tab"]) || "tasks", :tasks),
|
||||
dirty_tabs: Enum.map(Map.get(payload, "dirty_tabs", []), &decode_tab_ref/1)
|
||||
)
|
||||
|
||||
tabs =
|
||||
Enum.map(Map.get(payload, "tabs", []), fn tab ->
|
||||
%{
|
||||
type: atomize(Map.get(tab, "type", "post")),
|
||||
type: atomize(Map.get(tab, "type", "post"), :post),
|
||||
id: Map.get(tab, "id"),
|
||||
is_transient: Map.get(tab, "is_transient", false)
|
||||
}
|
||||
@@ -58,10 +58,15 @@ defmodule BDS.UI.Session do
|
||||
defp encode_tab_ref({type, id}), do: %{"type" => Atom.to_string(type), "id" => id}
|
||||
|
||||
defp decode_tab_ref(nil), do: nil
|
||||
defp decode_tab_ref(%{"type" => type, "id" => id}), do: {atomize(type), id}
|
||||
defp decode_tab_ref(%{"type" => type, "id" => id}), do: {atomize(type, :post), id}
|
||||
|
||||
defp atomize(value) when is_atom(value), do: value
|
||||
defp atomize(value) when is_binary(value), do: String.to_atom(value)
|
||||
defp atomize(value, _fallback) when is_atom(value), do: value
|
||||
|
||||
defp atomize(value, fallback) when is_binary(value) do
|
||||
String.to_existing_atom(value)
|
||||
rescue
|
||||
ArgumentError -> fallback
|
||||
end
|
||||
|
||||
defp active_route(nil), do: :dashboard
|
||||
defp active_route({type, _id}), do: type
|
||||
|
||||
Reference in New Issue
Block a user