summaryrefslogtreecommitdiff
path: root/internal/handlers/timeline_logic.go
diff options
context:
space:
mode:
authorPeter Stone <thepeterstone@gmail.com>2026-01-24 20:28:15 -1000
committerPeter Stone <thepeterstone@gmail.com>2026-01-24 20:28:15 -1000
commit22efca3118676926dec4af74fe8e225606063a35 (patch)
tree9ecbf7885fb97bb0b6666452109916359ad0f59c /internal/handlers/timeline_logic.go
parentc290113bd1a8af694b648bba4c801e00b049683a (diff)
Fix UI bugs and add Timeline view
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 <noreply@anthropic.com>
Diffstat (limited to 'internal/handlers/timeline_logic.go')
-rw-r--r--internal/handlers/timeline_logic.go110
1 files changed, 110 insertions, 0 deletions
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
+}