Skip to content

Commit 9db726f

Browse files
Add plans directly from calendar dates
1 parent 7196325 commit 9db726f

5 files changed

Lines changed: 45 additions & 9 deletions

File tree

Sources/SajiloApp/Features/Calendar/DayDetailView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ struct DayDetailView: View {
66
let model: AppModel
77
let date: NepaliDate
88
let onBack: () -> Void
9+
let startAddingPlan: Bool
910

1011
@State private var copiedFormat: ConversionOutcome.CopyFormat?
1112
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@@ -48,6 +49,7 @@ struct DayDetailView: View {
4849
DayPlanSection(
4950
date: date,
5051
plans: model.plans(on: date),
52+
startAddingPlan: startAddingPlan,
5153
onSave: model.saveDayPlan,
5254
onDelete: model.deleteDayPlan
5355
)

Sources/SajiloApp/Features/Dashboard/DashboardPreviews.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ private func previewDate(year: Int, month: Int, day: Int) -> Date {
4242

4343
/// A day carrying a festival, tithi, and holiday flag from the bundled data.
4444
#Preview("Day detail") {
45-
DayDetailView(model: .preview(), date: NepaliDate(year: 2083, month: 4, day: 1), onBack: {})
45+
DayDetailView(model: .preview(), date: NepaliDate(year: 2083, month: 4, day: 1), onBack: {}, startAddingPlan: false)
4646
.frame(width: Theme.Metric.popoverWidth)
4747
.background {
4848
Rectangle()
@@ -53,7 +53,7 @@ private func previewDate(year: Int, month: Int, day: Int) -> Date {
5353

5454
/// A day the source grid truncated, so it has no event at all.
5555
#Preview("Day detail — no event") {
56-
DayDetailView(model: .preview(), date: NepaliDate(year: 2083, month: 4, day: 31), onBack: {})
56+
DayDetailView(model: .preview(), date: NepaliDate(year: 2083, month: 4, day: 31), onBack: {}, startAddingPlan: false)
5757
.frame(width: Theme.Metric.popoverWidth)
5858
.background {
5959
Rectangle()

Sources/SajiloApp/Features/Dashboard/DashboardView.swift

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ struct DashboardView: View {
1414
return false
1515
}
1616

17+
private var startsAddingPlan: Bool {
18+
if case let .dayDetail(_, startAddingPlan) = route {
19+
return startAddingPlan
20+
}
21+
return false
22+
}
23+
1724
var body: some View {
1825
// Both routes stay in the hierarchy rather than being swapped by an
1926
// `if`. The popover then takes the height of the taller one and holds
@@ -27,7 +34,12 @@ struct DashboardView: View {
2734
// Mounted only once a day has been picked, so the popover does not
2835
// pay for a detail view nobody has opened yet.
2936
if let selectedDate {
30-
DayDetailView(model: model, date: selectedDate, onBack: { navigate(to: .dashboard) })
37+
DayDetailView(
38+
model: model,
39+
date: selectedDate,
40+
onBack: { navigate(to: .dashboard) },
41+
startAddingPlan: startsAddingPlan
42+
)
3143
.modifier(RouteLayer(isActive: isShowingDayDetail, edge: 1, reduceMotion: reduceMotion))
3244
}
3345

@@ -111,7 +123,11 @@ struct DashboardView: View {
111123
private var dashboard: some View {
112124
VStack(spacing: 0) {
113125
DateHeaderView(model: model, openSettings: { navigate(to: .settings) })
114-
MonthCalendarView(model: model, onSelectDate: select(_:))
126+
MonthCalendarView(
127+
model: model,
128+
onSelectDate: select(_:),
129+
onAddPlan: startPlan(for:)
130+
)
115131
.cardSection()
116132
.padding(.horizontal, Theme.Space.m)
117133
.padding(.top, Theme.Space.m)
@@ -160,13 +176,18 @@ struct DashboardView: View {
160176

161177
private func select(_ date: NepaliDate) {
162178
selectedDate = date
163-
navigate(to: .dayDetail(date))
179+
navigate(to: .dayDetail(date, startAddingPlan: false))
180+
}
181+
182+
private func startPlan(for date: NepaliDate) {
183+
selectedDate = date
184+
navigate(to: .dayDetail(date, startAddingPlan: true))
164185
}
165186
}
166187

167188
enum DashboardRoute: Equatable {
168189
case dashboard
169-
case dayDetail(NepaliDate)
190+
case dayDetail(NepaliDate, startAddingPlan: Bool)
170191
case upcoming
171192
case settings
172193
case weather

Sources/SajiloApp/Features/Dashboard/MonthCalendarView.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import SwiftUI
66
struct MonthCalendarView: View {
77
let model: AppModel
88
let onSelectDate: (NepaliDate) -> Void
9+
let onAddPlan: (NepaliDate) -> Void
910

1011
@Environment(\.numeralStyle) private var numerals
1112
@State private var isMovingForward = true
@@ -40,7 +41,8 @@ struct MonthCalendarView: View {
4041
CalendarDayView(
4142
day: day,
4243
hasPlan: day.date.map(model.hasDayPlan(on:)) ?? false,
43-
onSelect: onSelectDate
44+
onSelect: onSelectDate,
45+
onAddPlan: onAddPlan
4446
)
4547
}
4648
}
@@ -163,9 +165,9 @@ struct MonthCalendarView: View {
163165
private struct CalendarDayView: View {
164166
let day: CalendarDay
165167
let hasPlan: Bool
166-
167168
@Environment(\.numeralStyle) private var numerals
168169
let onSelect: (NepaliDate) -> Void
170+
let onAddPlan: (NepaliDate) -> Void
169171

170172
@State private var isHovering = false
171173

@@ -211,8 +213,13 @@ private struct CalendarDayView: View {
211213
.buttonStyle(.plain)
212214
.onHover { isHovering = $0 }
213215
.animation(.easeOut(duration: 0.12), value: isHovering)
216+
.contextMenu {
217+
Button(L10n.addPlan, systemImage: "calendar.badge.plus") {
218+
onAddPlan(date)
219+
}
220+
}
214221
.accessibilityLabel(accessibilityDescription(for: date))
215-
.accessibilityHint("Open date details")
222+
.accessibilityHint("Open date details. Use the context menu to add a plan.")
216223
.accessibilityAddTraits(day.isToday ? .isSelected : [])
217224
} else {
218225
Color.clear

Sources/SajiloApp/Features/Planner/DayPlanSection.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import SwiftUI
66
struct DayPlanSection: View {
77
let date: NepaliDate
88
let plans: [DayPlan]
9+
let startAddingPlan: Bool
910
let onSave: (DayPlan) -> Void
1011
let onDelete: (DayPlan.ID) -> Void
1112

@@ -53,6 +54,11 @@ struct DayPlanSection: View {
5354
}
5455
}
5556
.cardSection()
57+
.onAppear {
58+
if startAddingPlan, draft == nil {
59+
draft = DayPlanDraft(date: date)
60+
}
61+
}
5662
}
5763
}
5864

0 commit comments

Comments
 (0)