-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix macOS goal editing updates #5758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,6 +158,26 @@ class DashboardViewModel: ObservableObject { | |
| } | ||
| } | ||
|
|
||
| func updateGoal(_ goal: Goal, title: String, currentValue: Double, targetValue: Double) async { | ||
| log("Goals: Updating goal '\(goal.title)' -> title='\(title)', current=\(currentValue), target=\(targetValue)") | ||
|
|
||
| do { | ||
| let updated = try await APIClient.shared.updateGoal( | ||
| goalId: goal.id, | ||
| title: title, | ||
| currentValue: currentValue, | ||
| targetValue: targetValue | ||
| ) | ||
|
|
||
| _ = try? await GoalStorage.shared.syncServerGoal(updated) | ||
| goals = try await GoalStorage.shared.getLocalGoals() | ||
| log("Goals: Updated goal '\(updated.title)' confirmed by API") | ||
| } catch { | ||
| logError("Failed to update goal", error: error) | ||
| goals = (try? await GoalStorage.shared.getLocalGoals()) ?? goals | ||
| } | ||
| } | ||
|
Comment on lines
+161
to
+179
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Consider applying a similar optimistic strategy — update the in-memory func updateGoal(_ goal: Goal, title: String, currentValue: Double, targetValue: Double) async {
log("Goals: Updating goal '\(goal.title)' -> title='\(title)', current=\(currentValue), target=\(targetValue)")
// Optimistic update
if let index = goals.firstIndex(where: { $0.id == goal.id }) {
goals[index].title = title
goals[index].currentValue = currentValue
goals[index].targetValue = targetValue
}
do {
let updated = try await APIClient.shared.updateGoal(
goalId: goal.id,
title: title,
currentValue: currentValue,
targetValue: targetValue
)
_ = try? await GoalStorage.shared.syncServerGoal(updated)
goals = try await GoalStorage.shared.getLocalGoals()
log("Goals: Updated goal '\(updated.title)' confirmed by API")
} catch {
logError("Failed to update goal", error: error)
goals = (try? await GoalStorage.shared.getLocalGoals()) ?? goals
}
}Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
|
|
||
| func deleteGoal(_ goal: Goal) async { | ||
| do { | ||
| // Soft-delete locally first for instant UI update | ||
|
|
@@ -230,6 +250,16 @@ struct DashboardPage: View { | |
| ) | ||
| } | ||
| }, | ||
| onUpdateGoal: { goal, title, current, target in | ||
| Task { | ||
| await viewModel.updateGoal( | ||
| goal, | ||
| title: title, | ||
| currentValue: current, | ||
| targetValue: target | ||
| ) | ||
| } | ||
| }, | ||
| onUpdateProgress: { goal, value in | ||
| Task { | ||
| await viewModel.updateGoalProgress(goal, currentValue: value) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syncServerGoalfails silentlysyncServerGoalis called withtry?, so if the local SQLite write fails, the subsequentgetLocalGoals()will return the old values — making the UI appear unchanged even though the API update succeeded. The user sees no error and has to re-open the goals list to observe the change is gone.The same pattern exists in
createGoal. If a silent local-sync failure is acceptable here, consider at least applying the server response directly to the in-memory array as a fallback: