From 8a200f7f56c2894349b3f2831cd82625655acc7f Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Thu, 16 Jul 2026 06:57:47 +0000 Subject: Suggest an estimate from same-project/label averages on task detail --- internal/handlers/widget.go | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'internal/handlers/widget.go') 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) } -- cgit v1.2.3