Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Apps/MetaWear/MetaWear/Features/Sessions/SessionHistoryView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ struct SessionHistoryView: View {
.foregroundStyle(.secondary)
}
}
.swipeActions(edge: .trailing) {
Button("Delete", systemImage: "trash", role: .destructive) {
Task { await delete(snap) }
}
}
}
}
}
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading