Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set page name when notebook is renamed #844

Merged
merged 5 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/livebook_web/live/explore_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion lib/livebook_web/live/home_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions lib/livebook_web/live/session_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion lib/livebook_web/live/settings_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions test/livebook_web/live/session_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down