Skip to content

Commit 6a36dc7

Browse files
committed
Refactor OverrideActivationModal to simplify duration handling and make duration settings available for all overrides
1 parent d9f5974 commit 6a36dc7

1 file changed

Lines changed: 39 additions & 50 deletions

File tree

LoopFollow/Remote/LoopAPNS/OverridePresetsView.swift

Lines changed: 39 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,11 @@ struct OverrideActivationModal: View {
215215

216216
// Initialize state based on preset duration
217217
if preset.duration == 0 {
218-
// Indefinite override - allow user to choose
218+
// Indefinite override defaults to indefinite.
219219
_enableIndefinitely = State(initialValue: true)
220+
_durationHours = State(initialValue: 1.0)
220221
} else {
221-
// Override with predefined duration - use preset duration
222+
// Predefined-duration override defaults to the preset duration, but remains editable.
222223
_enableIndefinitely = State(initialValue: false)
223224
_durationHours = State(initialValue: preset.duration / 3600)
224225
}
@@ -251,69 +252,57 @@ struct OverrideActivationModal: View {
251252
.foregroundColor(.secondary)
252253
}
253254

254-
// Only show duration for overrides with predefined duration
255-
if preset.duration != 0 {
256-
Text("Duration: \(preset.durationDescription)")
257-
.font(.subheadline)
258-
.foregroundColor(.secondary)
259-
}
255+
Text("Preset: \(preset.durationDescription)")
256+
.font(.subheadline)
257+
.foregroundColor(.secondary)
260258
}
261259
.padding(.top)
262260

263261
Spacer()
264262

265-
// Duration Settings (only show for overrides without predefined duration)
266-
if preset.duration == 0 {
267-
VStack(spacing: 16) {
268-
// Duration Input (only show when not indefinite)
269-
if !enableIndefinitely {
270-
VStack(spacing: 8) {
271-
HStack {
272-
Text("Duration")
273-
.font(.headline)
274-
Spacer()
275-
Text(formatDuration(durationHours))
276-
.font(.headline)
277-
.foregroundColor(.blue)
278-
}
279-
280-
Slider(value: $durationHours, in: 0.25 ... 24.0, step: 0.25)
281-
.accentColor(.blue)
282-
HStack {
283-
Text("15m")
284-
.font(.caption)
285-
.foregroundColor(.secondary)
286-
.frame(width: 80, alignment: .leading)
287-
Spacer()
288-
Text("24h")
289-
.font(.caption)
290-
.foregroundColor(.secondary)
291-
.frame(width: 80, alignment: .trailing)
292-
}
263+
// Duration Settings (available for all overrides)
264+
VStack(spacing: 16) {
265+
// Duration Input (only show when not indefinite)
266+
if !enableIndefinitely {
267+
VStack(spacing: 8) {
268+
HStack {
269+
Text("Duration")
270+
.font(.headline)
271+
Spacer()
272+
Text(formatDuration(durationHours))
273+
.font(.headline)
274+
.foregroundColor(.blue)
293275
}
294-
.padding(.horizontal)
295-
}
296276

297-
// Indefinitely Toggle
298-
HStack {
299-
Toggle("Enable indefinitely", isOn: $enableIndefinitely)
300-
Spacer()
277+
Slider(value: $durationHours, in: 0.25 ... 24.0, step: 0.25)
278+
.accentColor(.blue)
279+
HStack {
280+
Text("15m")
281+
.font(.caption)
282+
.foregroundColor(.secondary)
283+
.frame(width: 80, alignment: .leading)
284+
Spacer()
285+
Text("24h")
286+
.font(.caption)
287+
.foregroundColor(.secondary)
288+
.frame(width: 80, alignment: .trailing)
289+
}
301290
}
302291
.padding(.horizontal)
303292
}
293+
294+
// Indefinitely Toggle
295+
HStack {
296+
Toggle("Enable indefinitely", isOn: $enableIndefinitely)
297+
Spacer()
298+
}
299+
.padding(.horizontal)
304300
}
305301

306302
// Action Buttons
307303
VStack(spacing: 12) {
308304
Button(action: {
309-
let duration: TimeInterval?
310-
if preset.duration == 0 {
311-
// For indefinite overrides, use user selection
312-
duration = enableIndefinitely ? nil : (durationHours * 3600)
313-
} else {
314-
// For overrides with predefined duration, use preset duration
315-
duration = preset.duration
316-
}
305+
let duration: TimeInterval? = enableIndefinitely ? nil : (durationHours * 3600)
317306
onActivate(duration)
318307
}) {
319308
Text("Activate Override")

0 commit comments

Comments
 (0)