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:
@@ -4,7 +4,7 @@ struct MonthlyCheckInView: View {
|
||||
@Environment(\.openURL) private var openURL
|
||||
@EnvironmentObject var accountStore: AccountStore
|
||||
@StateObject private var viewModel = MonthlyCheckInViewModel()
|
||||
let referenceDate: Date
|
||||
@State private var referenceDate: Date
|
||||
let duplicatePrevious: Bool
|
||||
|
||||
@State private var monthlyNote: String
|
||||
@@ -18,7 +18,7 @@ struct MonthlyCheckInView: View {
|
||||
@State private var showAppStoreReviewAlert = false
|
||||
|
||||
init(referenceDate: Date = Date(), duplicatePrevious: Bool = false) {
|
||||
self.referenceDate = referenceDate
|
||||
_referenceDate = State(initialValue: referenceDate)
|
||||
self.duplicatePrevious = duplicatePrevious
|
||||
_monthlyNote = State(initialValue: MonthlyCheckInStore.note(for: referenceDate))
|
||||
_starRating = State(initialValue: MonthlyCheckInStore.rating(for: referenceDate) ?? 0)
|
||||
@@ -74,6 +74,21 @@ struct MonthlyCheckInView: View {
|
||||
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 {
|
||||
true
|
||||
}
|
||||
@@ -167,8 +182,31 @@ struct MonthlyCheckInView: View {
|
||||
|
||||
private var headerCard: some View {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
Text(monthLabel)
|
||||
HStack {
|
||||
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 {
|
||||
Text(
|
||||
|
||||
Reference in New Issue
Block a user