From 790559896fe03d5c61a8594d7887394ca290d802 Mon Sep 17 00:00:00 2001 From: lkasso Date: Sun, 19 Jul 2026 20:55:20 -0700 Subject: [PATCH] Swipe-to-delete for saved sessions in Session History MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Owner request. Standard trailing swipe with a destructive Delete on every session row — removal is optimistic for instant UI, the store delete cascades the samples, and a failed delete resurrects the row via reload plus an alert (a row must never vanish while its data survives). Also surfaces loadError, which was recorded but never presented. Co-Authored-By: Claude Fable 5 --- .../Sessions/SessionHistoryView.swift | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Apps/MetaWear/MetaWear/Features/Sessions/SessionHistoryView.swift b/Apps/MetaWear/MetaWear/Features/Sessions/SessionHistoryView.swift index f2f774a..3cf2b18 100644 --- a/Apps/MetaWear/MetaWear/Features/Sessions/SessionHistoryView.swift +++ b/Apps/MetaWear/MetaWear/Features/Sessions/SessionHistoryView.swift @@ -26,6 +26,11 @@ struct SessionHistoryView: View { .foregroundStyle(.secondary) } } + .swipeActions(edge: .trailing) { + Button("Delete", systemImage: "trash", role: .destructive) { + Task { await delete(snap) } + } + } } } } @@ -42,6 +47,11 @@ struct SessionHistoryView: View { .refreshable { await reload() } + .alert(item: $loadError) { err in + Alert(title: Text("Session History"), + message: Text(err.message), + dismissButton: .default(Text("OK"))) + } } /// Serial → MAC translation from the remembered-device records (which @@ -66,6 +76,20 @@ struct SessionHistoryView: View { loadError = AppError(error: error) } } + + /// Standard swipe-to-delete: remove optimistically for instant UI, + /// then delete from the store (samples cascade). On failure the reload + /// resurrects the row and the alert explains — the row must never + /// vanish while the data survives. + private func delete(_ snapshot: MWSessionSnapshot) async { + snapshots.removeAll { $0.id == snapshot.id } + do { + try await appStore.persistence.deleteSession(id: snapshot.id) + } catch { + loadError = AppError(error: error) + await reload() + } + } } // MARK: - Grouping