From 37c323481d2e124e75bf3480dbc3bf53cad915e0 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Wed, 15 Jul 2026 18:30:16 +0000 Subject: feat(tasks): thread project color from BuildTimeline to WidgetItem Projects are fetched once per BuildTimeline call into a color lookup map, not queried per-task -- same pattern as RecurringEventID's existing TimelineItem->WidgetItem threading. --- internal/handlers/timeline_logic.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'internal/handlers/timeline_logic.go') diff --git a/internal/handlers/timeline_logic.go b/internal/handlers/timeline_logic.go index 6fddd1d..b90b61e 100644 --- a/internal/handlers/timeline_logic.go +++ b/internal/handlers/timeline_logic.go @@ -17,6 +17,16 @@ func BuildTimeline(ctx context.Context, s *store.Store, start, end time.Time) ([ var items []models.TimelineItem now := config.Now() + // Fetch all projects once into a color lookup map + projectColors := make(map[string]string) + if projects, err := s.GetProjects(); err != nil { + log.Printf("Warning: failed to read projects: %v", err) + } else { + for _, p := range projects { + projectColors[p.ID] = p.Color + } + } + // 1. Fetch Meals - combine multiple items for same date+mealType meals, err := s.GetMealsByDateRange(start, end) if err != nil { @@ -147,6 +157,7 @@ func BuildTimeline(ctx context.Context, s *store.Store, start, end time.Time) ([ OriginalItem: task, IsCompleted: task.Completed, Source: "doot", + ProjectColor: projectColors[task.ProjectID], } item.ComputeDaySection(now) items = append(items, item) @@ -170,6 +181,7 @@ func BuildTimeline(ctx context.Context, s *store.Store, start, end time.Time) ([ OriginalItem: task, IsCompleted: task.Completed, Source: "doot", + ProjectColor: projectColors[task.ProjectID], } item.ComputeDaySection(now) items = append(items, item) @@ -191,6 +203,7 @@ func BuildTimeline(ctx context.Context, s *store.Store, start, end time.Time) ([ IsCompleted: task.Completed, Source: "doot", IsAllDay: true, + ProjectColor: projectColors[task.ProjectID], } item.ComputeDaySection(now) items = append(items, item) -- cgit v1.2.3