From 22efca3118676926dec4af74fe8e225606063a35 Mon Sep 17 00:00:00 2001 From: Peter Stone Date: Sat, 24 Jan 2026 20:28:15 -1000 Subject: Fix UI bugs and add Timeline view MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug fixes: - #25: Replace 📅 with 🗓️ to avoid misleading date display - #30: Standardize background opacity (shopping items now use bg-white/5) New feature: - #11: Add Timeline view showing chronological events/tasks/meals Co-Authored-By: Claude Opus 4.5 --- internal/handlers/timeline_logic.go | 110 ++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 internal/handlers/timeline_logic.go (limited to 'internal/handlers/timeline_logic.go') diff --git a/internal/handlers/timeline_logic.go b/internal/handlers/timeline_logic.go new file mode 100644 index 0000000..1aba780 --- /dev/null +++ b/internal/handlers/timeline_logic.go @@ -0,0 +1,110 @@ +package handlers + +import ( + "context" + "sort" + "time" + + "task-dashboard/internal/api" + "task-dashboard/internal/models" + "task-dashboard/internal/store" +) + +// BuildTimeline aggregates and normalizes data into a timeline structure +func BuildTimeline(ctx context.Context, s *store.Store, calendarClient api.GoogleCalendarAPI, start, end time.Time) ([]models.TimelineItem, error) { + var items []models.TimelineItem + + // 1. Fetch Tasks + tasks, err := s.GetTasksByDateRange(start, end) + if err != nil { + return nil, err + } + for _, task := range tasks { + if task.DueDate == nil { + continue + } + items = append(items, models.TimelineItem{ + ID: task.ID, + Type: models.TimelineItemTypeTask, + Title: task.Content, + Time: *task.DueDate, + Description: task.Description, + URL: task.URL, + OriginalItem: task, + }) + } + + // 2. Fetch Meals + meals, err := s.GetMealsByDateRange(start, end) + if err != nil { + return nil, err + } + for _, meal := range meals { + mealTime := meal.Date + // Apply Meal Defaults + switch meal.MealType { + case "breakfast": + mealTime = time.Date(mealTime.Year(), mealTime.Month(), mealTime.Day(), 8, 0, 0, 0, mealTime.Location()) + case "lunch": + mealTime = time.Date(mealTime.Year(), mealTime.Month(), mealTime.Day(), 12, 0, 0, 0, mealTime.Location()) + case "dinner": + mealTime = time.Date(mealTime.Year(), mealTime.Month(), mealTime.Day(), 19, 0, 0, 0, mealTime.Location()) + default: + mealTime = time.Date(mealTime.Year(), mealTime.Month(), mealTime.Day(), 12, 0, 0, 0, mealTime.Location()) + } + + items = append(items, models.TimelineItem{ + ID: meal.ID, + Type: models.TimelineItemTypeMeal, + Title: meal.RecipeName, + Time: mealTime, + URL: meal.RecipeURL, + OriginalItem: meal, + }) + } + + // 3. Fetch Cards + cards, err := s.GetCardsByDateRange(start, end) + if err != nil { + return nil, err + } + for _, card := range cards { + if card.DueDate == nil { + continue + } + items = append(items, models.TimelineItem{ + ID: card.ID, + Type: models.TimelineItemTypeCard, + Title: card.Name, + Time: *card.DueDate, + URL: card.URL, + OriginalItem: card, + }) + } + + // 4. Fetch Events + if calendarClient != nil { + events, err := calendarClient.GetEventsByDateRange(ctx, start, end) + if err == nil { + for _, event := range events { + items = append(items, models.TimelineItem{ + ID: event.ID, + Type: models.TimelineItemTypeEvent, + Title: event.Summary, + Time: event.Start, + EndTime: &event.End, + Description: event.Description, + URL: event.HTMLLink, + OriginalItem: event, + }) + } + } + } + + // Sort items by Time + sort.Slice(items, func(i, j int) bool { + return items[i].Time.Before(items[j].Time) + }) + + return items, nil +} -- cgit v1.2.3