---
phase: 11-projection-pipeline-sort-fixes
plan: "03"
subsystem: ui
tags: [rust, slint, discovery-mode, sort, filter-pipeline]

# Dependency graph
requires:
  - phase: 11-projection-pipeline-sort-fixes
    provides: sort_cards_by_mode called in apply_filters but result discarded by all_cards iteration
provides:
  - filtered_cards built by iterating after_archive (sorted) and looking up matching CardData from all_cards
affects: [card-grid rendering, discovery mode switching, sort order preservation]

# Tech tracking
tech-stack:
  added: []
  patterns: []

key-files:
  created: []
  modified:
    - crates/app/src/main.rs

key-decisions:
  - "Iterate after_archive (sorted) and use filter_map + find to reconstruct CardData order rather than filtering all_cards against after_archive set"

patterns-established:
  - "Sort-preserving identity reconstruction: iterate sorted vec, look up full objects from source collection via identity match"

requirements-completed: [CARD-08, CARD-09]

# Metrics
duration: 5min
completed: 2026-03-20
---

# Phase 11 Plan 03: Projection Pipeline Sort Fix Summary

**Fixed sort bypass in apply_filters by iterating after_archive (sorted) instead of all_cards, so discovery-mode card ordering is now visible in the UI**

## Performance

- **Duration:** ~5 min
- **Started:** 2026-03-20T00:00:00Z
- **Completed:** 2026-03-20T00:05:00Z
- **Tasks:** 1
- **Files modified:** 1

## Accomplishments
- Replaced `all_cards.iter().filter()` with `after_archive.iter().filter_map()` in `apply_filters`
- `filtered_cards` now preserves the sort order established by `sort_cards_by_mode`
- Cards visually reorder when switching discovery modes (ByRecipient = alphabetical, ByStatusUpdated = most recent first)
- All workspace tests continue passing

## Task Commits

Each task was committed atomically:

1. **Task 1: Fix filtered_cards to iterate after_archive instead of all_cards** - `2894b16` (fix)

## Files Created/Modified
- `crates/app/src/main.rs` - Replaced all_cards-based filter with after_archive-based filter_map for sort order preservation

## Decisions Made
- Iterate the sorted `after_archive` vec and use `filter_map` + `find` to look up the matching `CardData` from `all_cards`. This preserves sort order through the identity-match reconstruction without requiring CardData to implement Ord.

## Deviations from Plan

None - plan executed exactly as written.

## Issues Encountered
None.

## User Setup Required
None - no external service configuration required.

## Next Phase Readiness
- Sort order bug is closed; discovery mode switching now visually reorders the card grid
- Phase 11 is complete; ready for phase 12 or further milestone work

---
*Phase: 11-projection-pipeline-sort-fixes*
*Completed: 2026-03-20*

## Self-Check: PASSED
- crates/app/src/main.rs: FOUND
- 11-03-SUMMARY.md: FOUND
- Commit 2894b16: FOUND
