mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-09-08 05:54:20 +08:00
Set page name when notebook is renamed (#844)
* override tab name when notebook is renamed
* set page_title in after operation function
* add custom page title to all live pages
* Revert "override tab name when notebook is renamed"
This reverts commit 90303e08a8
.
* add test for update
This commit is contained in:
parent
664e5412d5
commit
618593158d
5 changed files with 26 additions and 3 deletions
|
@ -14,7 +14,8 @@ defmodule LivebookWeb.ExploreLive do
|
|||
{:ok,
|
||||
assign(socket,
|
||||
lead_notebook_info: lead_notebook_info,
|
||||
notebook_infos: notebook_infos
|
||||
notebook_infos: notebook_infos,
|
||||
page_title: "Livebook - Explore"
|
||||
)}
|
||||
end
|
||||
|
||||
|
|
|
@ -21,7 +21,8 @@ defmodule LivebookWeb.HomeLive do
|
|||
file: Livebook.Config.default_dir(),
|
||||
file_info: %{exists: true, access: :read_write},
|
||||
sessions: sessions,
|
||||
notebook_infos: notebook_infos
|
||||
notebook_infos: notebook_infos,
|
||||
page_title: "Livebook"
|
||||
)}
|
||||
end
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ defmodule LivebookWeb.SessionLive do
|
|||
self: self(),
|
||||
data_view: data_to_view(data),
|
||||
autofocus_cell_id: autofocus_cell_id(data.notebook),
|
||||
page_title: get_page_title(data.notebook.name),
|
||||
empty_default_runtime: Livebook.Config.default_runtime() |> elem(0) |> struct()
|
||||
)
|
||||
|> assign_private(data: data)
|
||||
|
@ -1083,6 +1084,10 @@ defmodule LivebookWeb.SessionLive do
|
|||
push_event(socket, "clients_updated", %{clients: updated_clients})
|
||||
end
|
||||
|
||||
defp after_operation(socket, _prev_socket, {:set_notebook_name, _client_pid, name}) do
|
||||
assign(socket, page_title: get_page_title(name))
|
||||
end
|
||||
|
||||
defp after_operation(socket, _prev_socket, {:insert_section, client_pid, _index, section_id}) do
|
||||
if client_pid == self() do
|
||||
push_event(socket, "section_inserted", %{section_id: section_id})
|
||||
|
@ -1425,4 +1430,8 @@ defmodule LivebookWeb.SessionLive do
|
|||
defp update_dirty_status(data_view, data) do
|
||||
put_in(data_view.dirty, data.dirty)
|
||||
end
|
||||
|
||||
defp get_page_title(notebook_name) do
|
||||
"Livebook - #{notebook_name}"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -13,7 +13,8 @@ defmodule LivebookWeb.SettingsLive do
|
|||
{:ok,
|
||||
assign(socket,
|
||||
file_systems: file_systems,
|
||||
file_systems_env: file_systems_env
|
||||
file_systems_env: file_systems_env,
|
||||
page_title: "Livebook - Settings"
|
||||
)}
|
||||
end
|
||||
|
||||
|
|
|
@ -28,6 +28,17 @@ defmodule LivebookWeb.SessionLiveTest do
|
|||
assert render(view) =~ "My notebook"
|
||||
end
|
||||
|
||||
test "renders an updated notebook name in title", %{conn: conn, session: session} do
|
||||
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
|
||||
|
||||
assert page_title(view) =~ "Untitled notebook"
|
||||
|
||||
Session.set_notebook_name(session.pid, "My notebook")
|
||||
wait_for_session_update(session.pid)
|
||||
|
||||
assert page_title(view) =~ "My notebook"
|
||||
end
|
||||
|
||||
test "renders a newly inserted section", %{conn: conn, session: session} do
|
||||
{:ok, view, _} = live(conn, "/sessions/#{session.id}")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue