livebook/lib/livebook_web/live/session_live/export_component.ex

65 lines
1.9 KiB
Elixir
Raw Normal View History

defmodule LivebookWeb.SessionLive.ExportComponent do
use LivebookWeb, :live_component
alias Livebook.Session
@impl true
def update(assigns, socket) do
{any_stale_cell?, assigns} = Map.pop!(assigns, :any_stale_cell?)
socket = assign(socket, assigns)
{:ok,
socket
# Note: we need to load the notebook, because the local data
# has cell contents stripped out
|> assign_new(:notebook, fn -> Session.get_notebook(socket.assigns.session.pid) end)
|> assign_new(:any_stale_cell?, fn -> any_stale_cell? end)}
end
@impl true
def render(assigns) do
~H"""
<div class="p-6 max-w-4xl flex flex-col space-y-3">
<h3 class="text-2xl font-semibold text-gray-800">
Export
</h3>
<div class="w-full flex-col space-y-5">
<p class="text-gray-700">
Here you can preview and directly export the notebook source.
</p>
2021-07-28 19:40:36 +08:00
<div class="tabs">
2023-02-23 02:34:54 +08:00
<.link
patch={~p"/sessions/#{@session.id}/export/livemd"}
class={["tab", @tab == "livemd" && "active"]}
>
2021-07-28 19:40:36 +08:00
<span class="font-medium">
Live Markdown
</span>
2023-02-23 02:34:54 +08:00
</.link>
<.link
patch={~p"/sessions/#{@session.id}/export/exs"}
class={["tab", @tab == "exs" && "active"]}
>
2021-07-28 19:40:36 +08:00
<span class="font-medium">
IEx session
2021-07-28 19:40:36 +08:00
</span>
2023-02-23 02:34:54 +08:00
</.link>
</div>
2021-07-28 19:40:36 +08:00
<div>
2022-08-02 21:51:02 +08:00
<.live_component
module={component_for_tab(@tab)}
id={"export-notebook-#{@tab}"}
session={@session}
notebook={@notebook}
any_stale_cell?={@any_stale_cell?}
2022-08-02 21:51:02 +08:00
/>
</div>
</div>
</div>
"""
end
2021-07-28 19:40:36 +08:00
defp component_for_tab("livemd"), do: LivebookWeb.SessionLive.ExportLiveMarkdownComponent
defp component_for_tab("exs"), do: LivebookWeb.SessionLive.ExportElixirComponent
end