summaryrefslogtreecommitdiff
path: root/internal/handlers/widget.go
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-07-16 06:57:47 +0000
committerPeter Stone <thepeterstone@gmail.com>2026-07-16 06:57:47 +0000
commit8a200f7f56c2894349b3f2831cd82625655acc7f (patch)
tree185ddc1e83e015b7186c8569a6a24caa7cd10004 /internal/handlers/widget.go
parentde435fda250f93dc897fcb6414f418e7ed9b3595 (diff)
Suggest an estimate from same-project/label averages on task detail
Diffstat (limited to 'internal/handlers/widget.go')
-rw-r--r--internal/handlers/widget.go37
1 files changed, 28 insertions, 9 deletions
diff --git a/internal/handlers/widget.go b/internal/handlers/widget.go
index 5e515c3..5880314 100644
--- a/internal/handlers/widget.go
+++ b/internal/handlers/widget.go
@@ -612,15 +612,17 @@ func (h *Handler) HandleWidgetLabelsColorSet(w http.ResponseWriter, r *http.Requ
}
type taskDetailResponse struct {
- ID string `json:"id"`
- Title string `json:"title"`
- Description string `json:"description"`
- DueDate *time.Time `json:"due_date,omitempty"`
- Completed bool `json:"completed"`
- Recurrence *recurrenceResponse `json:"recurrence,omitempty"`
- NextDate *time.Time `json:"next_date,omitempty"`
- Project *projectResponse `json:"project,omitempty"`
- Labels []string `json:"labels,omitempty"`
+ ID string `json:"id"`
+ Title string `json:"title"`
+ Description string `json:"description"`
+ DueDate *time.Time `json:"due_date,omitempty"`
+ Completed bool `json:"completed"`
+ Recurrence *recurrenceResponse `json:"recurrence,omitempty"`
+ NextDate *time.Time `json:"next_date,omitempty"`
+ Project *projectResponse `json:"project,omitempty"`
+ Labels []string `json:"labels,omitempty"`
+ EstimatedMinutes int `json:"estimated_minutes,omitempty"`
+ SuggestedEstimateMinutes *int `json:"suggested_estimate_minutes,omitempty"`
}
// HandleWidgetTaskDetail returns full detail for a single doot-native task,
@@ -670,6 +672,23 @@ func (h *Handler) HandleWidgetTaskDetail(w http.ResponseWriter, r *http.Request)
}
}
+ resp.EstimatedMinutes = task.EstimatedMinutes
+ if task.EstimatedMinutes == 0 {
+ if task.ProjectID != "" {
+ if avg, ok, err := h.store.AverageEstimateForProject(task.ProjectID); err == nil && ok {
+ resp.SuggestedEstimateMinutes = &avg
+ }
+ }
+ if resp.SuggestedEstimateMinutes == nil {
+ for _, label := range task.Labels {
+ if avg, ok, err := h.store.AverageEstimateForLabel(label); err == nil && ok {
+ resp.SuggestedEstimateMinutes = &avg
+ break
+ }
+ }
+ }
+ }
+
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(resp)
}