diff --git a/lib/livebook/notebook_manager.ex b/lib/livebook/notebook_manager.ex index 13c233ff9..cc617f47e 100644 --- a/lib/livebook/notebook_manager.ex +++ b/lib/livebook/notebook_manager.ex @@ -85,6 +85,14 @@ defmodule Livebook.NotebookManager do GenServer.cast(__MODULE__, {:add_starred_notebook, file, name}) end + @doc """ + Removes the given file from recent notebooks. + """ + @spec remove_recent_notebook(FileSystem.File.t()) :: :ok + def remove_recent_notebook(file) do + GenServer.cast(__MODULE__, {:remove_recent_notebook, file}) + end + @doc """ Removes the given file from starred notebooks. """ @@ -171,6 +179,13 @@ defmodule Livebook.NotebookManager do end end + def handle_cast({:remove_recent_notebook, file}, state = prev_state) do + recent_notebooks = Enum.reject(state.recent_notebooks, &(&1.file == file)) + state = %{state | recent_notebooks: recent_notebooks} + broadcast_changes(state, prev_state) + {:noreply, state, {:continue, :dump_state}} + end + def handle_cast({:remove_starred_notebook, file}, state = prev_state) do starred_notebooks = Enum.reject(state.starred_notebooks, &(&1.file == file)) state = %{state | starred_notebooks: starred_notebooks} diff --git a/lib/livebook/storage.ex b/lib/livebook/storage.ex index 48b72c14b..dd4309ebf 100644 --- a/lib/livebook/storage.ex +++ b/lib/livebook/storage.ex @@ -17,7 +17,7 @@ defmodule Livebook.Storage do @type namespace :: atom() @type entity_id :: binary() @type attribute :: atom() - @type value :: binary() | nil + @type value :: term() @type timestamp :: non_neg_integer() @type entity :: %{required(:id) => entity_id(), optional(attribute()) => value()} diff --git a/lib/livebook_web/live/open_live.ex b/lib/livebook_web/live/open_live.ex index 0a0582e78..655a766b2 100644 --- a/lib/livebook_web/live/open_live.ex +++ b/lib/livebook_web/live/open_live.ex @@ -113,7 +113,26 @@ defmodule LivebookWeb.OpenLive do notebook_infos={@recent_notebooks} sessions={@sessions} added_at_label="Opened" - /> + > + <:card_icon :let={{_info, idx}}> + + + + + <% end %>
Looking for unsaved notebooks? <.link @@ -174,6 +193,12 @@ defmodule LivebookWeb.OpenLive do {:noreply, create_session(socket)} end + def handle_event("hide_recent_notebook", %{"idx" => idx}, socket) do + %{file: file} = Enum.fetch!(socket.assigns.recent_notebooks, idx) + Livebook.NotebookManager.remove_recent_notebook(file) + {:noreply, socket} + end + @impl true def handle_info({type, session} = event, socket) when type in [:session_created, :session_updated, :session_closed] and