mirror of
https://github.com/livebook-dev/livebook.git
synced 2024-11-12 10:49:29 +08:00
f70581f255
* Add explore page * Move sidebar to a configurable component * Fix homepage test * Add images * Store example notebooks in files and make explore notebooks linkable * Fix tests * Raise on invalid notebook slug * Keep just the file contents in notebook info * Move notebook lookup to Explore * Exclude notebooks in progress
21 lines
707 B
Elixir
21 lines
707 B
Elixir
defmodule LivebookWeb.SessionHelpers do
|
|
import Phoenix.LiveView
|
|
alias LivebookWeb.Router.Helpers, as: Routes
|
|
|
|
@doc """
|
|
Creates a new session, redirects on success,
|
|
puts an error flash message on failure.
|
|
|
|
Accepts the same options as `Livebook.SessionSupervisor.create_session/1`.
|
|
"""
|
|
@spec create_session(Phoenix.LiveView.Socket.t(), keyword()) :: Phoenix.LiveView.Socket.t()
|
|
def create_session(socket, opts \\ []) do
|
|
case Livebook.SessionSupervisor.create_session(opts) do
|
|
{:ok, id} ->
|
|
push_redirect(socket, to: Routes.session_path(socket, :page, id))
|
|
|
|
{:error, reason} ->
|
|
put_flash(socket, :error, "Failed to create session: #{reason}")
|
|
end
|
|
end
|
|
end
|