Skip to content

Commit

Permalink
List password-protected apps on the auth page (#2284)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonatanklosko committed Oct 18, 2023
1 parent 4d9d250 commit 1e4fa47
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
9 changes: 4 additions & 5 deletions lib/livebook_web/controllers/auth_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ defmodule LivebookWeb.AuthController do
render(conn, "index.html",
errors: [],
auth_mode: Livebook.Config.auth_mode(),
any_public_app?: any_public_app?(),
any_apps?: any_apps?(),
empty_apps_path?: Livebook.Apps.empty_apps_path?()
)
end
Expand Down Expand Up @@ -56,7 +56,7 @@ defmodule LivebookWeb.AuthController do
render(conn, "index.html",
errors: errors,
auth_mode: auth_mode,
any_public_app?: any_public_app?(),
any_apps?: any_apps?(),
empty_apps_path?: Livebook.Apps.empty_apps_path?()
)
end
Expand All @@ -75,8 +75,7 @@ defmodule LivebookWeb.AuthController do
|> halt()
end

defp any_public_app?() do
Livebook.Apps.list_apps()
|> Enum.any?(& &1.public?)
defp any_apps?() do
Livebook.Apps.list_apps() != []
end
end
6 changes: 3 additions & 3 deletions lib/livebook_web/controllers/auth_html/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@
</div>

<div
:if={@any_public_app? or @empty_apps_path?}
:if={@any_apps? or @empty_apps_path?}
class="w-full h-full px-4 py-8 flex justify-center items-center"
>
<div class="w-full flex flex-col items-center">
<div class="text-gray-700 text-xl font-medium">
Public apps
Apps
</div>
<div :if={@any_public_app?} class="w-full mt-5 mx-auto max-w-[400px]">
<div :if={@any_apps?} class="w-full mt-5 mx-auto max-w-[400px]">
<%= live_render(@conn, LivebookWeb.AuthAppListLive) %>
</div>
<div :if={@empty_apps_path?} class="mt-5 text-gray-600">
Expand Down
7 changes: 3 additions & 4 deletions lib/livebook_web/live/auth_app_list_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ defmodule LivebookWeb.AuthAppListLive do
<.link
:for={app <- visible_apps(@apps)}
href={~p"/apps/#{app.slug}"}
class="px-4 py-3 border border-gray-200 rounded-xl text-gray-800 pointer hover:bg-gray-50 flex justify-between"
class="px-4 py-3 border border-gray-200 rounded-xl text-gray-800 pointer hover:bg-gray-50 flex items-center justify-between"
>
<span class="font-semibold"><%= app.notebook_name %></span>
<.remix_icon :if={not app.public?} icon="lock-password-line" />
</.link>
</div>
"""
end

defp visible_apps(apps) do
apps
|> Enum.filter(& &1.public?)
|> Enum.sort_by(& &1.notebook_name)
Enum.sort_by(apps, & &1.notebook_name)
end
end

0 comments on commit 1e4fa47

Please sign in to comment.