Allow unstarring notebooks directly from the cards (#1818)

This commit is contained in:
Jonatan Kłosko 2023-03-22 17:37:44 +01:00 committed by GitHub
parent 32987558be
commit 1e995cfca3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 3 deletions

View file

@ -116,8 +116,23 @@ defmodule LivebookWeb.HomeLive do
sessions={@sessions}
added_at_label="Starred"
>
<:card_icon>
<.remix_icon icon="star-fill" class="text-yellow-600" />
<:card_icon :let={{_info, idx}}>
<span class="tooltip top" data-tooltip="Unstar">
<button
aria-label="unstar notebook"
phx-click={
with_confirm(
JS.push("unstar_notebook", value: %{idx: idx}),
title: "Unstar notebook",
description: "Once you unstar this notebook, you can always star it again.",
confirm_text: "Unstar",
opt_out_id: "unstar-notebook"
)
}
>
<.remix_icon icon="star-fill" class="text-yellow-600" />
</button>
</span>
</:card_icon>
</.live_component>
<% end %>
@ -262,6 +277,12 @@ defmodule LivebookWeb.HomeLive do
{:noreply, create_session(socket)}
end
def handle_event("unstar_notebook", %{"idx" => idx}, socket) do
%{file: file} = Enum.fetch!(socket.assigns.starred_notebooks, idx)
Livebook.NotebookManager.remove_starred_notebook(file)
{:noreply, socket}
end
def handle_event("bulk_action", %{"action" => "disconnect"} = params, socket) do
socket = assign(socket, selected_session_ids: params["session_ids"])
{:noreply, push_patch(socket, to: ~p"/home/sessions/edit_sessions/disconnect")}

View file

@ -18,7 +18,7 @@ defmodule LivebookWeb.NotebookCardsComponent do
<%= info.name %>
</span>
</span>
<%= @card_icon && render_slot(@card_icon) %>
<%= @card_icon && render_slot(@card_icon, {info, idx}) %>
</div>
<div class="mt-1 flex-grow text-gray-600 text-sm">
<%= @added_at_label %> <%= format_date_relatively(info.added_at) %>