Fix widget gap: forward-fill months and use reference month date for batch update

BatchUpdateView now accepts a saveDate parameter. When saving from a past-month
check-in, the call site passes referenceDate.endOfMonth so snapshots are dated
within the correct month instead of today. For the current month, Date() is used.

Widget forward-fills missing month buckets (trend and category series) using the
most recent earlier month's value, preventing gaps when a check-in is done in the
following month.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
alexandrev-tibco
2026-02-20 22:51:40 +01:00
parent e3ec0ddb25
commit c94974546f
2 changed files with 22 additions and 4 deletions
@@ -154,7 +154,8 @@ struct MonthlyCheckInView: View {
.sheet(isPresented: $showBatchUpdate) {
viewModel.refresh()
} content: {
BatchUpdateView(sources: viewModel.sources)
let batchSaveDate = referenceDate.isSameMonth(as: Date()) ? Date() : referenceDate.endOfMonth
BatchUpdateView(sources: viewModel.sources, saveDate: batchSaveDate)
}
.onChange(of: starRating) { _, newValue in
MonthlyCheckInStore.setRating(newValue == 0 ? nil : newValue, for: referenceDate)
@@ -945,10 +946,16 @@ struct AchievementMilestoneBar: View {
struct BatchUpdateView: View {
@Environment(\.dismiss) private var dismiss
let sources: [InvestmentSource]
let saveDate: Date
@State private var values: [UUID: String] = [:]
@State private var contributions: [UUID: String] = [:]
@State private var savedCount = 0
init(sources: [InvestmentSource], saveDate: Date = Date()) {
self.sources = sources
self.saveDate = saveDate
}
var body: some View {
NavigationStack {
List {
@@ -1080,7 +1087,7 @@ struct BatchUpdateView: View {
repository.createSnapshot(
for: source,
date: Date(),
date: saveDate,
value: parsed,
contribution: parsedContribution
)