mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-06 19:46:00 +08:00
Make app new session button a link
This commit is contained in:
parent
cc24a8b73c
commit
29122ccf5e
3 changed files with 7 additions and 4 deletions
|
@ -62,10 +62,10 @@ defmodule LivebookWeb.AppLive do
|
|||
<% end %>
|
||||
</p>
|
||||
<div class="flex justify-end">
|
||||
<button class="button-base button-outlined-blue" phx-click="new_session">
|
||||
<.link class="button-base button-outlined-blue" patch={~p"/apps/#{@app.slug}/new"}>
|
||||
<.remix_icon icon="add-line" class="align-middle mr-1" />
|
||||
<span>New session</span>
|
||||
</button>
|
||||
</.link>
|
||||
</div>
|
||||
<div :if={@app_settings.show_existing_sessions} class="w-full flex flex-col space-y-4">
|
||||
<.link
|
||||
|
@ -94,13 +94,15 @@ defmodule LivebookWeb.AppLive do
|
|||
def render(assigns), do: auth_placeholder(assigns)
|
||||
|
||||
@impl true
|
||||
def handle_event("new_session", %{}, socket) do
|
||||
def handle_params(_params, _url, socket) when socket.assigns.live_action == :new_session do
|
||||
session_id =
|
||||
Livebook.App.get_session_id(socket.assigns.app.pid, user: socket.assigns.current_user)
|
||||
|
||||
{:noreply, push_navigate(socket, to: ~p"/apps/#{socket.assigns.app.slug}/#{session_id}")}
|
||||
end
|
||||
|
||||
def handle_params(_params, _url, socket), do: {:noreply, socket}
|
||||
|
||||
@impl true
|
||||
def handle_info({:app_updated, app}, socket) do
|
||||
{:noreply, assign(socket, :app, app)}
|
||||
|
|
|
@ -113,6 +113,7 @@ defmodule LivebookWeb.Router do
|
|||
pipe_through [:browser, :user]
|
||||
|
||||
live "/apps/:slug", AppLive, :page
|
||||
live "/apps/:slug/new", AppLive, :new_session
|
||||
live "/apps/:slug/authenticate", AppAuthLive, :page
|
||||
|
||||
live "/apps/:slug/:id", AppSessionLive, :page
|
||||
|
|
|
@ -84,7 +84,7 @@ defmodule LivebookWeb.AppLiveTest do
|
|||
|
||||
{:error, {:live_redirect, %{to: to}}} =
|
||||
view
|
||||
|> element("button", "New session")
|
||||
|> element("a", "New session")
|
||||
|> render_click()
|
||||
|
||||
assert_receive {:app_updated, %{pid: ^app_pid, sessions: [%{id: session_id}]}}
|
||||
|
|
Loading…
Add table
Reference in a new issue