Skip to content

Commit 5133601

Browse files
authored
Migrate layouts to Phoenix v1.8 (#3196)
1 parent d7e3e87 commit 5133601

27 files changed

Lines changed: 1257 additions & 1200 deletions

lib/livebook/teams/requests.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,14 +223,14 @@ defmodule Livebook.Teams.Requests do
223223
params = %{access_token: access_token}
224224

225225
fun = fn
226-
_, %Req.TransportError{reason: :econnrefused} -> not valid_cache?
227-
_, %Req.Response{status: status} when status in [408, 429, 500, 502, 503, 504] -> true
228-
_, %Req.TransportError{reason: reason} when reason in [:timeout, :closed] -> true
226+
_, %{reason: :econnrefused} -> not valid_cache?
227+
_, %{status: status} when status in [408, 429, 500, 502, 503, 504] -> true
228+
_, %{reason: reason} when reason in [:timeout, :closed] -> true
229229
_, _ -> false
230230
end
231231

232232
case Req.get(req, url: "/api/v1/org/identity", params: params, retry: fun) do
233-
{:error, %Req.TransportError{reason: :econnrefused}} -> :econnrefused
233+
{:error, %{reason: :econnrefused}} -> :econnrefused
234234
otherwise -> handle_response(otherwise)
235235
end
236236
end

lib/livebook_web.ex

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ defmodule LivebookWeb do
33

44
def controller do
55
quote do
6-
use Phoenix.Controller,
7-
formats: [:html, :json],
8-
layouts: [html: LivebookWeb.Layouts]
6+
use Phoenix.Controller, formats: [:html, :json]
97

108
import Plug.Conn
119

@@ -15,7 +13,7 @@ defmodule LivebookWeb do
1513

1614
def live_view do
1715
quote do
18-
use Phoenix.LiveView, layout: {LivebookWeb.Layouts, :live}
16+
use Phoenix.LiveView
1917

2018
unquote(html_helpers())
2119
end
@@ -64,6 +62,8 @@ defmodule LivebookWeb do
6462

6563
# Shortcut for generating JS commands
6664
alias Phoenix.LiveView.JS
65+
# Shortcut for layout components
66+
alias LivebookWeb.Layouts
6767

6868
# Routes generation with the ~p sigil
6969
unquote(verified_routes())

lib/livebook_web/components/core_components.ex

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,45 @@ defmodule LivebookWeb.CoreComponents do
8888
"""
8989
end
9090

91+
@doc """
92+
Renders page title.
93+
94+
## Examples
95+
96+
<.title text="Learn" />
97+
98+
"""
99+
attr :text, :string, default: nil
100+
attr :back_navigate, :string, default: nil
101+
102+
slot :inner_block
103+
104+
def title(assigns) do
105+
if assigns.text == nil and assigns.inner_block == [] do
106+
raise ArgumentError, "should pass at least text attribute or an inner block"
107+
end
108+
109+
~H"""
110+
<div class="relative">
111+
<div
112+
:if={@back_navigate}
113+
class="hidden md:flex absolute top-0 bottom-0 left-0 transform -translate-x-full"
114+
>
115+
<.link navigate={@back_navigate}>
116+
<.remix_icon icon="arrow-left-line" class="align-middle mr-2 text-2xl text-gray-800" />
117+
</.link>
118+
</div>
119+
<h1 class="text-2xl text-gray-800 font-medium">
120+
<%= if @inner_block != [] do %>
121+
{render_slot(@inner_block)}
122+
<% else %>
123+
{@text}
124+
<% end %>
125+
</h1>
126+
</div>
127+
"""
128+
end
129+
91130
@doc """
92131
Renders a message notice.
93132

0 commit comments

Comments
 (0)