Просмотр исходного кода

disable add button when last entry is at 11.30 p.m.

Marvin Polscheit 6 месяцев назад
Родитель
Сommit
93ada1341c
1 измененных файлов с 17 добавлено и 2 удалено
  1. 17 2
      Trio/Sources/Modules/Onboarding/View/TherapySettingEditorView.swift

+ 17 - 2
Trio/Sources/Modules/Onboarding/View/TherapySettingEditorView.swift

@@ -41,9 +41,9 @@ struct TherapySettingEditorView: View {
                         HStack {
                             Image(systemName: "plus.circle.fill")
                             Text("Add")
-                        }.foregroundColor(.accentColor)
+                        }.foregroundColor(cannotAddMoreEntries ? .secondary : .accentColor)
                     }
-                    .disabled(items.count >= 48)
+                    .disabled(cannotAddMoreEntries)
                 }
                 .listRowBackground(Color.chart.opacity(0.65))
                 .padding(.vertical, 10)
@@ -188,6 +188,21 @@ struct TherapySettingEditorView: View {
         .padding(.vertical, 8)
     }
 
+    /// Check if we can add more entries
+    /// Disabled when: 48 entries OR last entry is at 23:30 (84600 seconds)
+    private var cannotAddMoreEntries: Bool {
+        if items.count >= 48 {
+            return true
+        }
+
+        // Check if last entry is at 23:30 (23.5 hours * 3600 seconds = 84600)
+        if let lastTime = items.last?.time, lastTime >= 84600 {
+            return true
+        }
+
+        return false
+    }
+
     private func sortTherapyItems() {
         Task { @MainActor in
             withAnimation {