diff options
Diffstat (limited to 'internal')
| -rw-r--r-- | internal/api/trello.go | 28 | ||||
| -rw-r--r-- | internal/store/sqlite.go | 10 |
2 files changed, 34 insertions, 4 deletions
diff --git a/internal/api/trello.go b/internal/api/trello.go index b9391d6..c78ebc8 100644 --- a/internal/api/trello.go +++ b/internal/api/trello.go @@ -217,13 +217,39 @@ func (c *TrelloClient) GetBoardsWithCards(ctx context.Context) ([]models.Board, wg.Wait() - // Sort boards: Non-empty boards first, then alphabetical by name + // Sort boards: Non-empty boards first, newest card activity, then alphabetical by name + // Trello card IDs are chronologically sortable (newer IDs > older IDs) sort.Slice(boards, func(i, j int) bool { hasCardsI := len(boards[i].Cards) > 0 hasCardsJ := len(boards[j].Cards) > 0 + + // 1. Prioritize boards with cards if hasCardsI != hasCardsJ { return hasCardsI // true (non-empty) comes before false } + + // 2. If both have cards, compare by newest card (max ID) + if hasCardsI && hasCardsJ { + maxIDI := "" + for _, card := range boards[i].Cards { + if maxIDI == "" || card.ID > maxIDI { + maxIDI = card.ID + } + } + + maxIDJ := "" + for _, card := range boards[j].Cards { + if maxIDJ == "" || card.ID > maxIDJ { + maxIDJ = card.ID + } + } + + if maxIDI != maxIDJ { + return maxIDI > maxIDJ // Newer (larger) ID comes first + } + } + + // 3. Fallback to alphabetical by name return boards[i].Name < boards[j].Name }) diff --git a/internal/store/sqlite.go b/internal/store/sqlite.go index 5063336..fa8f2b1 100644 --- a/internal/store/sqlite.go +++ b/internal/store/sqlite.go @@ -424,13 +424,17 @@ func (s *Store) SaveBoards(boards []models.Board) error { // GetBoards retrieves all boards with their cards from the database func (s *Store) GetBoards() ([]models.Board, error) { - // Fetch boards, sorted by: non-empty boards first, then alphabetical + // Fetch boards, sorted by: non-empty boards first, newest card activity, then alphabetical + // Trello card IDs are chronologically sortable (newer IDs > older IDs) boardRows, err := s.db.Query(` SELECT b.id, b.name FROM boards b + LEFT JOIN cards c ON c.board_id = b.id + GROUP BY b.id, b.name ORDER BY - CASE WHEN (SELECT COUNT(*) FROM cards c WHERE c.board_id = b.id) > 0 THEN 0 ELSE 1 END, - b.name + CASE WHEN COUNT(c.id) > 0 THEN 0 ELSE 1 END, + MAX(c.id) DESC, + b.name ASC `) if err != nil { return nil, err |
