livebook/lib/livebook_web/live/session_helpers.ex
Jonatan Kłosko f70581f255
Introduce an Explore section (#310)
* 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
2021-06-02 21:51:43 +02:00

22 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