Browse Source

Merge pull request #1293 from EJM0/feat/add-undo-snooze

add swipe action to undo snooze
Deniz Cengiz 2 days ago
parent
commit
502709a543
1 changed files with 27 additions and 1 deletions
  1. 27 1
      Trio/Sources/Views/SnoozeAlertsSheetView.swift

+ 27 - 1
Trio/Sources/Views/SnoozeAlertsSheetView.swift

@@ -26,7 +26,16 @@ struct SnoozeAlertsSheetView: View {
                             ))
                                 .font(.headline)
                         }
-                    }.listRowBackground(Color.chart)
+                        .swipeActions(edge: .trailing, allowsFullSwipe: true) {
+                            endSnoozeAction
+                        }
+                        .listRowBackground(Color.chart)
+                    } footer: {
+                        HStack {
+                            Image(systemName: "hand.draw.fill").foregroundStyle(.primary)
+                            Text("Swipe left to end snooze.")
+                        }
+                    }
                 }
                 Section(footer: Text(
                     "Pick a duration to mute every Trio alarm. Critical alerts (e.g. occlusion, urgent low) still pierce the snooze."
@@ -62,6 +71,15 @@ struct SnoozeAlertsSheetView: View {
         }
     }
 
+    private var endSnoozeAction: some View {
+        Button(role: .destructive) {
+            endSnooze()
+        } label: {
+            Label("End Snooze", systemImage: "alarm.waves.left.and.right.fill")
+        }
+        .tint(.red)
+    }
+
     private func applySnooze(_ duration: TimeInterval) {
         let trioAlertManager = resolver.resolve(TrioAlertManager.self)
         Task { @MainActor in
@@ -70,4 +88,12 @@ struct SnoozeAlertsSheetView: View {
             isPresented = false
         }
     }
+
+    private func endSnooze() {
+        let trioAlertManager = resolver.resolve(TrioAlertManager.self)
+        Task { @MainActor in
+            await trioAlertManager?.applySnooze(for: 0)
+            snoozeUntilDate = Date().addingTimeInterval(0)
+        }
+    }
 }