app: delete a recording from its card's menu

The list could only open the review, so a clip that was not worth
keeping stayed on disk forever. The dots beside Review open a menu
drawn over this window, so it stays inside it, with room for more
actions later. Delete asks before the clip and its timeline leave
the disk and the row leaves the list.
This commit is contained in:
vhaudiquet committed 2026-11-21 19:01:41 +01:00
1 parent b1cde7e783
commit 6ca825990d
6 files changed
+294 -11

No files matched your search

+146 -8
View File
@@ -8,10 +8,13 @@ use rune::{Color, El, col, el, row, text};
use crate::app::App;
use crate::format;
use crate::history::{Outcome, QueueCategory, Summary};
use crate::history::{self, Outcome, QueueCategory, Summary};
use crate::icons;
use crate::screens::review;
use crate::ui::{self, Paint, body, heading};
use rune_kit::{Kit, Menu, MenuItem, Placement};
const FILTERS: [Option<QueueCategory>; 6] = [
None,
Some(QueueCategory::RankedSolo),
@@ -33,7 +36,8 @@ fn outcome_color(p: Paint, outcome: Outcome) -> Color {
}
}
pub fn view(app: &App, p: Paint) -> El {
pub fn view(app: &App, p: Paint, layer: &mut Vec<El>) -> El {
let kit = rune_kit::Kit::neutral(app.dark);
let filtered: Vec<&Summary> = app
.games
.iter()
@@ -64,7 +68,7 @@ pub fn view(app: &App, p: Paint) -> El {
));
} else {
for (index, game) in filtered.iter().enumerate() {
list = list.child(game_card(app, p, game, index));
list = list.child(game_card(app, p, &kit, layer, game, index));
}
}
@@ -159,7 +163,14 @@ fn empty(p: Paint, title: &str, detail: &str) -> El {
)
}
fn game_card(app: &App, p: Paint, game: &Summary, index: usize) -> El {
fn game_card(
app: &App,
p: Paint,
k: &Kit,
layer: &mut Vec<El>,
game: &Summary,
index: usize,
) -> El {
let outcome = game.outcome();
let ink = outcome_color(p, outcome);
let id = game.recording_id.clone();
@@ -305,10 +316,17 @@ fn game_card(app: &App, p: Paint, game: &Summary, index: usize) -> El {
)
.child(stats_row)
.child(
text("Review →")
.key("open")
.font(type_::LABEL)
.color(p.accent),
row()
.key("actions")
.gap(space::S3)
.center_y()
.child(
text("Review →")
.key("open")
.font(type_::LABEL)
.color(p.accent),
)
.child(card_menu(app, k, layer, p, game, index)),
),
),
)
@@ -326,3 +344,123 @@ fn stat(p: Paint, value: &str, label: &str) -> El {
)
.child(text(label).key("label").font(body(10.5)).color(p.muted()))
}
/// The dots at the end of a card: they open the menu of actions a recording offers. The menu
/// is drawn over this window, so it stays inside it, and more actions can join `Delete` later.
/// The key is the card's position, so rows stay distinct even where ids repeat.
fn card_menu(
app: &App,
k: &Kit,
layer: &mut Vec<El>,
p: Paint,
game: &Summary,
index: usize,
) -> El {
let menu = Menu::new(format!("menu-{index}"))
.trigger(ui::menu_button(
p,
format!("menu-{index}"),
&icons::DOTS,
"Recording options",
move |app: &mut App| app.menu_open = Some(index),
))
.placement(Placement::BottomEnd)
.open(app.menu_open == Some(index))
.on_close(|app: &mut App| app.menu_open = None)
.item({
let id = game.recording_id.clone();
MenuItem::new("Delete")
.danger(true)
.on_select(move |app: &mut App| {
app.menu_open = None;
app.confirm_delete = Some(id.clone());
})
});
menu.build(k, layer)
}
/// The confirmation the menu's Delete opens: the row leaves the list and its files leave the
/// disk. `app::view` draws it over the whole window, title bar included.
pub fn delete_dialog(app: &App, p: Paint, layer: &mut Vec<El>) {
let panel = col()
.key("delete-dialog")
.role("dialog")
.label("Delete this recording")
.w(380.0)
.padding(space::S6)
.gap(space::S3)
.radius(radius::LG)
.fill(p.t.card)
.border(p.hair, p.t.card_border)
.shadow(4.0, 12.0, p.t.shadow)
.shadow(24.0, 48.0, p.t.shadow_soft)
.modal(true, |app: &mut App| app.confirm_delete = None)
.child(
text("Are you sure you want to delete this entry?")
.key("delete-question")
.font(heading(15.0))
.color(p.t.text),
)
.child(
text("The recording and its timeline are removed from disk.")
.key("delete-note")
.font(body(12.0))
.color(p.muted()),
)
.child(
row()
.key("delete-actions")
.w_full()
.gap(space::S2)
.justify_end()
.child(ui::button(p, "delete-no", "No", false, |app: &mut App| {
app.confirm_delete = None;
}))
.child(ui::button_danger(
p,
"delete-yes",
"Yes",
|app: &mut App| {
delete_confirmed(app);
},
)),
);
layer.push(
el().key("delete-scrim")
.absolute(0.0, 0.0)
.w_full()
.h_full()
.fill(Color::BLACK.alpha(if app.dark { 0.55 } else { 0.28 }))
.a11y_hidden(),
);
layer.push(
el().key("delete-layer")
.absolute(0.0, 0.0)
.w_full()
.h_full()
.padding(16.0)
.center()
.child(panel),
);
}
/// Yes on the dialog: the files go, the row goes, the dialog closes.
fn delete_confirmed(app: &mut App) {
let Some(id) = app.confirm_delete.take() else {
return;
};
// A review left open keeps the clip's file in use, and the delete would fail on it.
if app.reviewed().is_some_and(|game| game.recording_id == id) {
review::leave(app);
}
let Some(summary) = app.games.iter().find(|g| g.recording_id == id).cloned() else {
return;
};
if let Err(e) = history::delete(&id, summary.video_file.as_deref()) {
app.notify_error(e);
return;
}
app.forget_game(&id);
app.notify("Recording deleted");
}