diff --git a/PortfolioJournal/Views/Dashboard/MonthlyCheckInView.swift b/PortfolioJournal/Views/Dashboard/MonthlyCheckInView.swift index 6bdd132..45481d2 100644 --- a/PortfolioJournal/Views/Dashboard/MonthlyCheckInView.swift +++ b/PortfolioJournal/Views/Dashboard/MonthlyCheckInView.swift @@ -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) - .font(.headline) + 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(