defmodule LivebookWeb.OpenLive.UrlComponent do use LivebookWeb, :live_component import Ecto.Changeset alias Livebook.{Utils, Notebook} @impl true def mount(socket) do {:ok, assign(socket, changeset: changeset(), error_message: nil)} end defp changeset(attrs \\ %{}) do data = %{url: nil} types = %{url: :string} cast({data, types}, attrs, [:url]) |> validate_required([:url]) |> Livebook.Utils.validate_url(:url) |> Livebook.Utils.validate_not_s3_url( :url, ~s{invalid s3:// URL scheme, you must first connect to the Cloud Storage in your Hub page and then choose the relevant file in "From storage"} ) end @impl true def update(assigns, socket) do if url = assigns[:url] do {:ok, do_import(socket, %{url: url})} else {:ok, socket} end end @impl true def render(assigns) do ~H"""
Paste the URL to a .livemd file, to a GitHub file, or to a Gist.
<.form :let={f} for={@changeset} as={:data} phx-submit="import" phx-change="validate" phx-target={@myself} autocomplete="off" > <.text_field field={f[:url]} label="Notebook URL" autofocus aria-labelledby="import-from-url" spellcheck="false" />