defmodule LivebookWeb.ExploreLive do use LivebookWeb, :live_view import LivebookWeb.SessionHelpers import LivebookWeb.UserHelpers alias LivebookWeb.{SidebarHelpers, ExploreHelpers, PageHelpers} alias Livebook.Notebook.Explore @impl true def mount(_params, _session, socket) do [lead_notebook_info | notebook_infos] = Explore.visible_notebook_infos() {:ok, socket |> SidebarHelpers.shared_home_handlers() |> assign( lead_notebook_info: lead_notebook_info, notebook_infos: notebook_infos, page_title: "Livebook - Explore" )} 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!

<%= @lead_notebook_info.title %>

<%= @lead_notebook_info.details.description %>

<%= live_patch "Let's go", to: Routes.explore_path(@socket, :notebook, @lead_notebook_info.slug), class: "button-base button-blue" %>
<%# Note: it's fine to use stateless components in this comprehension, because @notebook_infos never change %> <%= for info <- @notebook_infos do %> <% end %>
<%= for group_info <- Explore.group_infos() do %> <.notebook_group group_info={group_info} socket={@socket} /> <% end %>
<.current_user_modal current_user={@current_user} /> """ 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" => "new"}, _url, socket) do {:noreply, create_session(socket)} end def handle_params(%{"slug" => slug}, _url, socket) do {notebook, images} = Explore.notebook_by_slug!(slug) {:noreply, create_session(socket, notebook: notebook, images: images)} end def handle_params(_params, _url, socket), do: {:noreply, socket} end