defmodule LivebookWeb.LearnLive do use LivebookWeb, :live_view import LivebookWeb.SessionHelpers import LivebookWeb.NotebookComponents alias LivebookWeb.LayoutComponents alias Livebook.Notebook.Learn on_mount LivebookWeb.SidebarHook @impl true def mount(_params, _session, socket) do [lead_notebook_info | notebook_infos] = Learn.visible_notebook_infos() {:ok, assign(socket, lead_notebook_info: lead_notebook_info, notebook_infos: notebook_infos, page_title: "Learn - Livebook" )} end @impl true def render(assigns) do ~H"""

Check out a number of examples showcasing various parts of the Elixir ecosystem.
Click on any notebook you like and start playing around with it!

livebook

<%= @lead_notebook_info.title %>

<%= @lead_notebook_info.details.description %>

<.button patch={~p"/learn/notebooks/#{@lead_notebook_info.slug}"}> Open notebook
<%!-- Note: it's fine to use stateless components in this comprehension, because @notebook_infos never change --%> <.learn_notebook_card :for={info <- @notebook_infos} notebook_info={info} />
<.notebook_group :for={group_info <- Learn.group_infos()} group_info={group_info} />
""" end defp notebook_group(assigns) do ~H"""
<%= length(@group_info.notebook_infos) %> notebooks

<%= @group_info.title %>

<%= @group_info.description %>

""" end @impl true def handle_params(%{"slug" => slug}, _url, socket) do {notebook, files} = Learn.notebook_by_slug!(slug) {:noreply, create_session(socket, notebook: notebook, files_source: {:inline, files})} end def handle_params(_params, _url, socket), do: {:noreply, socket} end