mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-25 04:46:04 +08:00
Prevent from scrolling to top on modal open (#129)
* Render modal components at the end of live views * Add error pages * Restructure web module * Update lib/livebook_web/templates/error/500.html.eex Co-authored-by: José Valim <jose.valim@dashbit.co> * Update lib/livebook_web/templates/error/500.html.eex Co-authored-by: José Valim <jose.valim@dashbit.co> * Update lib/livebook_web/views/error_view.ex Co-authored-by: José Valim <jose.valim@dashbit.co> Co-authored-by: José Valim <jose.valim@dashbit.co>
This commit is contained in:
parent
0fbeb42d24
commit
cc9d5a8103
12 changed files with 97 additions and 44 deletions
|
|
@ -5,9 +5,7 @@ config :livebook, LivebookWeb.Endpoint,
|
||||||
url: [host: "localhost"],
|
url: [host: "localhost"],
|
||||||
secret_key_base: "9hHHeOiAA8wrivUfuS//jQMurHxoMYUtF788BQMx2KO7mYUE8rVrGGG09djBNQq7",
|
secret_key_base: "9hHHeOiAA8wrivUfuS//jQMurHxoMYUtF788BQMx2KO7mYUE8rVrGGG09djBNQq7",
|
||||||
pubsub_server: Livebook.PubSub,
|
pubsub_server: Livebook.PubSub,
|
||||||
live_view: [signing_salt: "mAPgPEM4"],
|
live_view: [signing_salt: "mAPgPEM4"]
|
||||||
# We are always in debug mode since we are executing code anyway
|
|
||||||
debug_errors: true
|
|
||||||
|
|
||||||
# Configures Elixir's Logger
|
# Configures Elixir's Logger
|
||||||
config :logger, :console,
|
config :logger, :console,
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ config :livebook, LivebookWeb.Endpoint,
|
||||||
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
|
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
|
||||||
http: [ip: {127, 0, 0, 1}, port: 4000],
|
http: [ip: {127, 0, 0, 1}, port: 4000],
|
||||||
code_reloader: true,
|
code_reloader: true,
|
||||||
|
debug_errors: true,
|
||||||
check_origin: false,
|
check_origin: false,
|
||||||
watchers: [
|
watchers: [
|
||||||
node: [
|
node: [
|
||||||
|
|
|
||||||
|
|
@ -17,13 +17,6 @@ defmodule LivebookWeb.HomeLive do
|
||||||
@impl true
|
@impl true
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~L"""
|
~L"""
|
||||||
<%= if @live_action == :delete_session do %>
|
|
||||||
<%= live_modal @socket, LivebookWeb.DeleteSessionComponent,
|
|
||||||
id: :delete_session_modal,
|
|
||||||
return_to: Routes.home_path(@socket, :page),
|
|
||||||
session_summary: @session_summary %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div class="flex flex-grow h-full">
|
<div class="flex flex-grow h-full">
|
||||||
<div class="flex flex-col items-center space-y-6 px-3 py-8 bg-gray-900">
|
<div class="flex flex-col items-center space-y-6 px-3 py-8 bg-gray-900">
|
||||||
<%= live_patch to: Routes.home_path(@socket, :page) do %>
|
<%= live_patch to: Routes.home_path(@socket, :page) do %>
|
||||||
|
|
@ -92,7 +85,7 @@ defmodule LivebookWeb.HomeLive do
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<%= live_component @socket, LivebookWeb.SessionsComponent,
|
<%= live_component @socket, LivebookWeb.SessionLive.SessionsComponent,
|
||||||
id: "sessions_list",
|
id: "sessions_list",
|
||||||
session_summaries: @session_summaries %>
|
session_summaries: @session_summaries %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
@ -100,6 +93,13 @@ defmodule LivebookWeb.HomeLive do
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<%= if @live_action == :delete_session do %>
|
||||||
|
<%= live_modal @socket, LivebookWeb.SessionLive.DeleteSessionComponent,
|
||||||
|
id: :delete_session_modal,
|
||||||
|
return_to: Routes.home_path(@socket, :page),
|
||||||
|
session_summary: @session_summary %>
|
||||||
|
<% end %>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule LivebookWeb.DeleteSessionComponent do
|
defmodule LivebookWeb.SessionLive.DeleteSessionComponent do
|
||||||
use LivebookWeb, :live_component
|
use LivebookWeb, :live_component
|
||||||
|
|
||||||
alias Livebook.SessionSupervisor
|
alias Livebook.SessionSupervisor
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule LivebookWeb.SessionsComponent do
|
defmodule LivebookWeb.SessionLive.SessionsComponent do
|
||||||
use LivebookWeb, :live_component
|
use LivebookWeb, :live_component
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
|
|
@ -47,30 +47,6 @@ defmodule LivebookWeb.SessionLive do
|
||||||
@impl true
|
@impl true
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
~L"""
|
~L"""
|
||||||
<%= if @live_action == :settings do %>
|
|
||||||
<%= live_modal @socket, LivebookWeb.SessionLive.SettingsComponent,
|
|
||||||
id: :settings_modal,
|
|
||||||
return_to: Routes.session_path(@socket, :page, @session_id),
|
|
||||||
tab: @tab,
|
|
||||||
session_id: @session_id,
|
|
||||||
data_view: @data_view %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= if @live_action == :shortcuts do %>
|
|
||||||
<%= live_modal @socket, LivebookWeb.SessionLive.ShortcutsComponent,
|
|
||||||
id: :shortcuts_modal,
|
|
||||||
platform: @platform,
|
|
||||||
return_to: Routes.session_path(@socket, :page, @session_id) %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<%= if @live_action == :cell_settings do %>
|
|
||||||
<%= live_modal @socket, LivebookWeb.SessionLive.CellSettingsComponent,
|
|
||||||
id: :cell_settings_modal,
|
|
||||||
session_id: @session_id,
|
|
||||||
cell: @cell,
|
|
||||||
return_to: Routes.session_path(@socket, :page, @session_id) %>
|
|
||||||
<% end %>
|
|
||||||
|
|
||||||
<div class="flex flex-grow h-full"
|
<div class="flex flex-grow h-full"
|
||||||
id="session"
|
id="session"
|
||||||
data-element="session"
|
data-element="session"
|
||||||
|
|
@ -141,7 +117,7 @@ defmodule LivebookWeb.SessionLive do
|
||||||
</div>
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= for {section_view, index} <- Enum.with_index(@data_view.section_views) do %>
|
<%= for {section_view, index} <- Enum.with_index(@data_view.section_views) do %>
|
||||||
<%= live_component @socket, LivebookWeb.SectionComponent,
|
<%= live_component @socket, LivebookWeb.SessionLive.SectionComponent,
|
||||||
id: section_view.id,
|
id: section_view.id,
|
||||||
index: index,
|
index: index,
|
||||||
session_id: @session_id,
|
session_id: @session_id,
|
||||||
|
|
@ -157,6 +133,30 @@ defmodule LivebookWeb.SessionLive do
|
||||||
data_view: @data_view %>
|
data_view: @data_view %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<%= if @live_action == :settings do %>
|
||||||
|
<%= live_modal @socket, LivebookWeb.SessionLive.SettingsComponent,
|
||||||
|
id: :settings_modal,
|
||||||
|
return_to: Routes.session_path(@socket, :page, @session_id),
|
||||||
|
tab: @tab,
|
||||||
|
session_id: @session_id,
|
||||||
|
data_view: @data_view %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= if @live_action == :shortcuts do %>
|
||||||
|
<%= live_modal @socket, LivebookWeb.SessionLive.ShortcutsComponent,
|
||||||
|
id: :shortcuts_modal,
|
||||||
|
platform: @platform,
|
||||||
|
return_to: Routes.session_path(@socket, :page, @session_id) %>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
|
<%= if @live_action == :cell_settings do %>
|
||||||
|
<%= live_modal @socket, LivebookWeb.SessionLive.CellSettingsComponent,
|
||||||
|
id: :cell_settings_modal,
|
||||||
|
session_id: @session_id,
|
||||||
|
cell: @cell,
|
||||||
|
return_to: Routes.session_path(@socket, :page, @session_id) %>
|
||||||
|
<% end %>
|
||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule LivebookWeb.CellComponent do
|
defmodule LivebookWeb.SessionLive.CellComponent do
|
||||||
use LivebookWeb, :live_component
|
use LivebookWeb, :live_component
|
||||||
|
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule LivebookWeb.InsertButtonsComponent do
|
defmodule LivebookWeb.SessionLive.InsertButtonsComponent do
|
||||||
use LivebookWeb, :live_component
|
use LivebookWeb, :live_component
|
||||||
|
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
defmodule LivebookWeb.SectionComponent do
|
defmodule LivebookWeb.SessionLive.SectionComponent do
|
||||||
use LivebookWeb, :live_component
|
use LivebookWeb, :live_component
|
||||||
|
|
||||||
def render(assigns) do
|
def render(assigns) do
|
||||||
|
|
@ -27,18 +27,18 @@ defmodule LivebookWeb.SectionComponent do
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="flex flex-col space-y-1">
|
<div class="flex flex-col space-y-1">
|
||||||
<%= for {cell_view, index} <- Enum.with_index(@section_view.cell_views) do %>
|
<%= for {cell_view, index} <- Enum.with_index(@section_view.cell_views) do %>
|
||||||
<%= live_component @socket, LivebookWeb.InsertButtonsComponent,
|
<%= live_component @socket, LivebookWeb.SessionLive.InsertButtonsComponent,
|
||||||
id: "#{@section_view.id}:#{index}",
|
id: "#{@section_view.id}:#{index}",
|
||||||
persistent: false,
|
persistent: false,
|
||||||
section_id: @section_view.id,
|
section_id: @section_view.id,
|
||||||
insert_cell_index: index,
|
insert_cell_index: index,
|
||||||
insert_section_index: nil %>
|
insert_section_index: nil %>
|
||||||
<%= live_component @socket, LivebookWeb.CellComponent,
|
<%= live_component @socket, LivebookWeb.SessionLive.CellComponent,
|
||||||
id: cell_view.id,
|
id: cell_view.id,
|
||||||
session_id: @session_id,
|
session_id: @session_id,
|
||||||
cell_view: cell_view %>
|
cell_view: cell_view %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<%= live_component @socket, LivebookWeb.InsertButtonsComponent,
|
<%= live_component @socket, LivebookWeb.SessionLive.InsertButtonsComponent,
|
||||||
id: "#{@section_view.id}:last",
|
id: "#{@section_view.id}:last",
|
||||||
persistent: @section_view.cell_views == [],
|
persistent: @section_view.cell_views == [],
|
||||||
section_id: @section_view.id,
|
section_id: @section_view.id,
|
||||||
22
lib/livebook_web/templates/error/404.html.eex
Normal file
22
lib/livebook_web/templates/error/404.html.eex
Normal file
|
|
@ -0,0 +1,22 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<%= live_title_tag "Livebook" %>
|
||||||
|
<link phx-track-static rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="h-screen flex items-center justify-center bg-gray-900">
|
||||||
|
<div class="flex flex-col space-y-4 items-center">
|
||||||
|
<a href="/">
|
||||||
|
<img src="/logo.png" height="128" width="128" alt="livebook" />
|
||||||
|
</a>
|
||||||
|
<div class="text-2xl text-gray-50">
|
||||||
|
No Numbats here!
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
25
lib/livebook_web/templates/error/500.html.eex
Normal file
25
lib/livebook_web/templates/error/500.html.eex
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8"/>
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
|
||||||
|
<%= live_title_tag "Livebook" %>
|
||||||
|
<link phx-track-static rel="stylesheet" href="<%= Routes.static_path(@conn, "/css/app.css") %>"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="h-screen flex items-center justify-center bg-gray-900">
|
||||||
|
<div class="flex flex-col space-y-4 items-center">
|
||||||
|
<a href="/">
|
||||||
|
<img src="/logo.png" height="128" width="128" alt="livebook" />
|
||||||
|
</a>
|
||||||
|
<div class="text-2xl text-gray-50">
|
||||||
|
Something went wrong.
|
||||||
|
</div>
|
||||||
|
<div class="text-lg text-gray-50">
|
||||||
|
Check out the console for logs for more information.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
7
lib/livebook_web/views/error_view.ex
Normal file
7
lib/livebook_web/views/error_view.ex
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
defmodule LivebookWeb.ErrorView do
|
||||||
|
use LivebookWeb, :view
|
||||||
|
|
||||||
|
def template_not_found(_template, assigns) do
|
||||||
|
render("500.html", assigns)
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Add table
Reference in a new issue