Add prev/next navigation buttons to Monthly Check-in view

Adds chevron buttons to navigate between months, similar to Lose It Log view.
The next month button is disabled when already at the current month.

Fixes #20

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
alexandrev-tibco
2026-02-11 23:46:54 +01:00
parent 8fa66c1c70
commit 7d1eb874d8
@@ -4,7 +4,7 @@ struct MonthlyCheckInView: View {
@Environment(\.openURL) private var openURL @Environment(\.openURL) private var openURL
@EnvironmentObject var accountStore: AccountStore @EnvironmentObject var accountStore: AccountStore
@StateObject private var viewModel = MonthlyCheckInViewModel() @StateObject private var viewModel = MonthlyCheckInViewModel()
let referenceDate: Date @State private var referenceDate: Date
let duplicatePrevious: Bool let duplicatePrevious: Bool
@State private var monthlyNote: String @State private var monthlyNote: String
@@ -18,7 +18,7 @@ struct MonthlyCheckInView: View {
@State private var showAppStoreReviewAlert = false @State private var showAppStoreReviewAlert = false
init(referenceDate: Date = Date(), duplicatePrevious: Bool = false) { init(referenceDate: Date = Date(), duplicatePrevious: Bool = false) {
self.referenceDate = referenceDate _referenceDate = State(initialValue: referenceDate)
self.duplicatePrevious = duplicatePrevious self.duplicatePrevious = duplicatePrevious
_monthlyNote = State(initialValue: MonthlyCheckInStore.note(for: referenceDate)) _monthlyNote = State(initialValue: MonthlyCheckInStore.note(for: referenceDate))
_starRating = State(initialValue: MonthlyCheckInStore.rating(for: referenceDate) ?? 0) _starRating = State(initialValue: MonthlyCheckInStore.rating(for: referenceDate) ?? 0)
@@ -74,6 +74,21 @@ struct MonthlyCheckInView: View {
return .appSecondary return .appSecondary
} }
private var canGoToNextMonth: Bool {
guard let nextMonth = Calendar.current.date(byAdding: .month, value: 1, to: referenceDate) else { return false }
return nextMonth <= Date()
}
private func navigateMonth(offset: Int) {
guard let newDate = Calendar.current.date(byAdding: .month, value: offset, to: referenceDate) else { return }
referenceDate = newDate
monthlyNote = MonthlyCheckInStore.note(for: newDate)
starRating = MonthlyCheckInStore.rating(for: newDate) ?? 0
selectedMood = MonthlyCheckInStore.mood(for: newDate)
viewModel.selectedRange = DateRange.month(containing: newDate)
viewModel.refresh()
}
private var canAddNewCheckIn: Bool { private var canAddNewCheckIn: Bool {
true true
} }
@@ -167,8 +182,31 @@ struct MonthlyCheckInView: View {
private var headerCard: some View { private var headerCard: some View {
VStack(alignment: .leading, spacing: 8) { VStack(alignment: .leading, spacing: 8) {
Text(monthLabel) HStack {
.font(.headline) Button {
navigateMonth(offset: -1)
} label: {
Image(systemName: "chevron.left")
.font(.headline)
.foregroundColor(.appPrimary)
}
Spacer()
Text(monthLabel)
.font(.title3.weight(.bold))
Spacer()
Button {
navigateMonth(offset: 1)
} label: {
Image(systemName: "chevron.right")
.font(.headline)
.foregroundColor(canGoToNextMonth ? .appPrimary : .secondary.opacity(0.3))
}
.disabled(!canGoToNextMonth)
}
if let date = lastCompletionDate { if let date = lastCompletionDate {
Text( Text(