Skip to content

Commit ece739b

Browse files
committed
Fixed bug causing crash when switching between date selection ranges with no chart data saved.
1 parent 71df0e9 commit ece739b

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

InfiniLink/View Components/Sheets/ChartSettingsSheet/ChartSettingsSheetDatePicker.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ struct ChartSettingsSheetDatePicker: View {
1414
let oneMonthAgo = Calendar.current.date(byAdding: .month, value: -1, to: Date()) ?? (Date() - 2419200)
1515

1616
@Binding var chartRangeState: ChartManager.DateSelectionState
17-
let oldestPoint: Date?
17+
let oldestPoint: Date
1818

1919
var body: some View {
2020
List {
2121
DatePicker(
2222
"Start Date",
2323
selection: $chartRangeState.startDate,
24-
in: (oldestPoint ?? oneMonthAgo)...today,
24+
in: (oldestPoint)...today,
2525
displayedComponents: [.date, .hourAndMinute]
2626
)
2727
DatePicker(

InfiniLink/View Components/Sheets/ChartSettingsSheet/ChartSettingsSheetMain.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,11 @@ struct ChartSettingsSheet: View {
8181
case 1:
8282
ChartSettingsSheetSliders(chartRangeState: self.$chartRangeState)
8383
case 2:
84-
ChartSettingsSheetDatePicker(chartRangeState: self.$chartRangeState, oldestPoint: chartPoints[0].timestamp)
84+
if chartPoints.count > 0 {
85+
ChartSettingsSheetDatePicker(chartRangeState: self.$chartRangeState, oldestPoint: chartPoints[0].timestamp!)
86+
} else {
87+
ChartSettingsSheetDatePicker(chartRangeState: self.$chartRangeState, oldestPoint: Calendar.current.date(byAdding: .month, value: -1, to: Date()) ?? (Date() - 2419200))
88+
}
8589
default:
8690
EmptyView()
8791
}

0 commit comments

Comments
 (0)