Browse Source

Refactor Snooze functionality by removing the handleSnoozeResponse method and updating the formatInterval method to handle nil values gracefully. Adjusted snooze description logic to utilize the new formatInterval method.

Trio Build Bot 1 month ago
parent
commit
ebab072e5b

+ 0 - 10
Trio/Sources/Modules/Snooze/SnoozeStateModel.swift

@@ -27,16 +27,6 @@ extension Snooze {
                 .contains(duration)
                 .contains(duration)
         }
         }
 
 
-        // Add handleSnoozeResponse inside the class
-        func handleSnoozeResponse(_ duration: TimeInterval) {
-            guard validateSnoozeDuration(duration) else { return }
-
-            Task { @MainActor in
-                snoozeUntilDate = Date().addingTimeInterval(duration)
-                alarm = glucoseStorage.alarm
-            }
-        }
-
         @MainActor func applySnooze(_ duration: TimeInterval) async {
         @MainActor func applySnooze(_ duration: TimeInterval) async {
             // Allow any duration chosen in the Snooze UI, while keeping validation for quick actions elsewhere.
             // Allow any duration chosen in the Snooze UI, while keeping validation for quick actions elsewhere.
             snoozeUntilDate = duration > 0 ? Date().addingTimeInterval(duration) : .distantPast
             snoozeUntilDate = duration > 0 ? Date().addingTimeInterval(duration) : .distantPast

+ 2 - 2
Trio/Sources/Modules/Snooze/View/SnoozeRootView.swift

@@ -36,7 +36,7 @@ extension Snooze {
         }
         }
 
 
         private func formatInterval(_ interval: TimeInterval) -> String {
         private func formatInterval(_ interval: TimeInterval) -> String {
-            formatter.string(from: interval)!
+            formatter.string(from: interval) ?? ""
         }
         }
 
 
         func getSnoozeDescription() -> String {
         func getSnoozeDescription() -> String {
@@ -68,7 +68,7 @@ extension Snooze {
             VStack(alignment: .leading) {
             VStack(alignment: .leading) {
                 Button {
                 Button {
                     let interval = pickerTimes[selectedInterval]
                     let interval = pickerTimes[selectedInterval]
-                    let snoozeFor = formatter.string(from: interval)!
+                    let snoozeFor = formatInterval(interval)
                     let untilDate = Date() + interval
                     let untilDate = Date() + interval
 
 
                     Task { @MainActor [weak state] in
                     Task { @MainActor [weak state] in