mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-11-22 09:29:18 +08:00
Allow for hiding notebooks from recent list (#1830)
This commit is contained in:
parent
fda0525fae
commit
15d2b2f75e
3 changed files with 42 additions and 2 deletions
|
|
@ -85,6 +85,14 @@ defmodule Livebook.NotebookManager do
|
||||||
GenServer.cast(__MODULE__, {:add_starred_notebook, file, name})
|
GenServer.cast(__MODULE__, {:add_starred_notebook, file, name})
|
||||||
end
|
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 """
|
@doc """
|
||||||
Removes the given file from starred notebooks.
|
Removes the given file from starred notebooks.
|
||||||
"""
|
"""
|
||||||
|
|
@ -171,6 +179,13 @@ defmodule Livebook.NotebookManager do
|
||||||
end
|
end
|
||||||
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
|
def handle_cast({:remove_starred_notebook, file}, state = prev_state) do
|
||||||
starred_notebooks = Enum.reject(state.starred_notebooks, &(&1.file == file))
|
starred_notebooks = Enum.reject(state.starred_notebooks, &(&1.file == file))
|
||||||
state = %{state | starred_notebooks: starred_notebooks}
|
state = %{state | starred_notebooks: starred_notebooks}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ defmodule Livebook.Storage do
|
||||||
@type namespace :: atom()
|
@type namespace :: atom()
|
||||||
@type entity_id :: binary()
|
@type entity_id :: binary()
|
||||||
@type attribute :: atom()
|
@type attribute :: atom()
|
||||||
@type value :: binary() | nil
|
@type value :: term()
|
||||||
@type timestamp :: non_neg_integer()
|
@type timestamp :: non_neg_integer()
|
||||||
@type entity :: %{required(:id) => entity_id(), optional(attribute()) => value()}
|
@type entity :: %{required(:id) => entity_id(), optional(attribute()) => value()}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,26 @@ defmodule LivebookWeb.OpenLive do
|
||||||
notebook_infos={@recent_notebooks}
|
notebook_infos={@recent_notebooks}
|
||||||
sessions={@sessions}
|
sessions={@sessions}
|
||||||
added_at_label="Opened"
|
added_at_label="Opened"
|
||||||
/>
|
>
|
||||||
|
<:card_icon :let={{_info, idx}}>
|
||||||
|
<span class="tooltip top" data-tooltip="Hide notebook">
|
||||||
|
<button
|
||||||
|
aria-label="hide notebook"
|
||||||
|
phx-click={
|
||||||
|
with_confirm(
|
||||||
|
JS.push("hide_recent_notebook", value: %{idx: idx}),
|
||||||
|
title: "Hide notebook",
|
||||||
|
description: "The notebook will reappear here when you open it again.",
|
||||||
|
confirm_text: "Hide",
|
||||||
|
opt_out_id: "hide-notebook"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<.remix_icon icon="close-fill" class="text-gray-600 text-lg" />
|
||||||
|
</button>
|
||||||
|
</span>
|
||||||
|
</:card_icon>
|
||||||
|
</.live_component>
|
||||||
<% end %>
|
<% end %>
|
||||||
<div class="mt-3 text-gray-600 text-sm">
|
<div class="mt-3 text-gray-600 text-sm">
|
||||||
Looking for unsaved notebooks? <.link
|
Looking for unsaved notebooks? <.link
|
||||||
|
|
@ -174,6 +193,12 @@ defmodule LivebookWeb.OpenLive do
|
||||||
{:noreply, create_session(socket)}
|
{:noreply, create_session(socket)}
|
||||||
end
|
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
|
@impl true
|
||||||
def handle_info({type, session} = event, socket)
|
def handle_info({type, session} = event, socket)
|
||||||
when type in [:session_created, :session_updated, :session_closed] and
|
when type in [:session_created, :session_updated, :session_closed] and
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue