28 Commits

Author SHA1 Message Date
50672cb662 docs(phase-11): complete phase execution
Some checks failed
CI / ci (push) Failing after 11s
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 22:39:22 +01:00
7e06c8526b fix(11): wire handleDragEnd to Reorder.Group for active threads
onPointerUp was incorrectly placed on the resolved-thread div instead
of the active-thread Reorder.Group, causing drag reorder to not persist.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 22:36:40 +01:00
4304d0fcd7 docs(11-02): complete drag-to-reorder ranking UI plan
- Add 11-02-SUMMARY.md with implementation details and deviation docs
- Update STATE.md: progress 100%, decisions, session record
- Update ROADMAP.md: phase 11 complete (2/2 plans with summaries)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 22:30:32 +01:00
94c07e79c2 feat(11-02): add view toggle, Reorder.Group drag-to-reorder, and rank badges in grid view
- Thread detail page: list/grid view toggle with LayoutList/LayoutGrid icons
- List view (active threads): Reorder.Group with CandidateListItem for drag-to-reorder
- List view (resolved threads): static CandidateListItem with rank badges, no drag handles
- Grid view: CandidateCard components with rank badges (gold/silver/bronze)
- tempItems pattern prevents React Query flicker during drag
- handleDragEnd fires PATCH /candidates/reorder after drag completes
- View toggle defaults to list view via uiStore candidateViewMode
2026-03-16 22:28:53 +01:00
acfa99516d feat(11-02): add useReorderCandidates hook, candidateViewMode, and CandidateListItem component
- Add useReorderCandidates mutation hook with apiPatch to /candidates/reorder endpoint
- Add candidateViewMode (list|grid) state and setCandidateViewMode to uiStore
- Create CandidateListItem component with drag handle, rank badge, horizontal layout
- Export RankBadge helper (gold/silver/bronze medal icons for top 3)
- Add style prop support to LucideIcon component
- Add pros/cons fields to CandidateWithCategory in useThreads.ts
2026-03-16 22:27:18 +01:00
495a2eabf5 docs(11-01): complete sort_order + reorder backend plan
- Create 11-01-SUMMARY.md with full execution record
- Update STATE.md: progress 89%, decisions, metrics, session
- Update ROADMAP.md: phase 11 marked in-progress (1/2 plans)
- Mark requirements RANK-01, RANK-04, RANK-05 complete
2026-03-16 22:24:08 +01:00
d6acfcb126 feat(11-01): PATCH /api/threads/:id/candidates/reorder route + tests
- Import reorderCandidatesSchema and reorderCandidates into threads route
- Add PATCH /:id/candidates/reorder route with Zod validation
- Returns 200 + { success: true } on active thread, 400 on resolved thread
- Add 5 route tests: success, order persists, resolved guard, empty array, missing field
2026-03-16 22:22:31 +01:00
f01d71d6b4 feat(11-01): schema, service, and tests for sort_order + reorderCandidates
- Add sortOrder REAL column to threadCandidates schema (default 0)
- Add sort_order column to test helper CREATE TABLE
- Add reorderCandidatesSchema to shared/schemas.ts
- Add ReorderCandidates type to shared/types.ts
- getThreadWithCandidates now orders candidates by sort_order ASC
- createCandidate appends at max sort_order + 1000 (first = 1000)
- Add reorderCandidates service function (transaction, active-only guard)
- Add 5 new tests: ordering, appending, reorder success, resolved guard, missing thread
2026-03-16 22:21:42 +01:00
2986bdd2e5 docs(11-candidate-ranking): create phase plan 2026-03-16 22:15:56 +01:00
11ee50db49 docs(phase-11): add validation strategy 2026-03-16 22:08:30 +01:00
a55d58cef3 docs(phase-11): research candidate ranking phase 2026-03-16 22:07:36 +01:00
d380e756ea docs(state): record phase 11 context session 2026-03-16 22:02:31 +01:00
e4c6991ec6 docs(11): capture phase context 2026-03-16 22:02:20 +01:00
685acd2ab2 docs(phase-10): complete phase execution 2026-03-16 21:42:18 +01:00
2ce54e5990 chore(10-01): add Drizzle migration for pros/cons columns
- drizzle/0004_soft_synch.sql: ALTER TABLE thread_candidates ADD COLUMN pros/cons
- drizzle/meta/0004_snapshot.json: updated schema snapshot
- drizzle/meta/_journal.json: migration journal entry
2026-03-16 21:38:55 +01:00
11912a9416 docs(10-01): complete pros/cons schema foundation plan
- Add 10-01-SUMMARY.md with TDD execution results
- STATE.md: updated metrics, decisions, session, progress
- ROADMAP.md: phase 10 marked complete (1/1 plans)
- REQUIREMENTS.md: RANK-03 marked complete
2026-03-16 21:38:40 +01:00
4f2aefe7a4 feat(10-01): wire pros/cons through client hooks, form, and card indicator
- CandidateResponse: add pros/cons string|null fields
- CandidateForm: add pros/cons to FormData, INITIAL_FORM, pre-fill, payload
- CandidateForm: add Pros/Cons textarea inputs (after Notes, before Product Link)
- CandidateCard: add pros/cons props, render purple +/- Notes badge when present
- Thread detail route: pass pros/cons props to CandidateCard
2026-03-16 21:36:10 +01:00
7a64a1887d feat(10-01): add pros/cons columns through backend
- Add pros/cons nullable TEXT columns to threadCandidates schema
- Generate and apply Drizzle migration (0004_soft_synch.sql)
- Mirror pros/cons columns in test helper CREATE TABLE
- createCandidate: pass pros/cons to values() object
- updateCandidate: add pros/cons to Partial type
- getThreadWithCandidates: include pros/cons in select projection
- createCandidateSchema: add optional pros/cons string fields
2026-03-16 21:32:38 +01:00
719f7082da test(10-01): add failing tests for pros/cons on thread candidates
- createCandidate stores and returns pros/cons fields
- createCandidate returns null when pros/cons not provided
- updateCandidate can set and clear pros/cons
- getThreadWithCandidates includes pros/cons on each candidate
2026-03-16 21:31:39 +01:00
67044f8f2e docs(10): create phase plan 2026-03-16 21:26:59 +01:00
66d1cf2f55 docs(10): add research and validation strategy 2026-03-16 21:23:32 +01:00
fbc856b885 docs(10): research phase schema foundation pros/cons fields 2026-03-16 21:22:12 +01:00
b43472b09a docs: create milestone v1.3 roadmap (4 phases) 2026-03-16 21:14:53 +01:00
e44807fd37 docs: define milestone v1.3 requirements 2026-03-16 21:11:56 +01:00
4689d49b93 docs: complete project research 2026-03-16 21:08:09 +01:00
2fa4427de5 docs: start milestone v1.3 Research & Decision Tools 2026-03-16 20:53:52 +01:00
9647f5759d feat: redesign weight summary legend and add currency selector
Redesign WeightSummaryCard stats from a disconnected 4-column grid to a
compact legend-style list with color dots, percentages, and a divider
before the total row. Switch chart and legend colors to a neutral gray
palette.

Add a currency selector to settings (USD, EUR, GBP, JPY, CAD, AUD) that
changes the displayed symbol across the app. This is visual only — no
value conversion is performed.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 20:33:07 +01:00
4cb356d6b0 chore: archive v1.2 Collection Power-Ups milestone
Archive roadmap and requirements to milestones/, evolve PROJECT.md
with validated requirements, update retrospective, and reorganize
ROADMAP.md with milestone groupings.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-16 19:09:13 +01:00
61 changed files with 6656 additions and 1480 deletions

View File

@@ -1,5 +1,23 @@
# Milestones # Milestones
## v1.2 Collection Power-Ups (Shipped: 2026-03-16)
**Phases completed:** 3 phases, 6 plans, 11 tasks
**Timeline:** 3 days (2026-03-14 → 2026-03-16)
**Codebase:** 7,310 LOC TypeScript, 66 files changed (+7,243 / -206)
**Key accomplishments:**
- Weight unit conversion (g/oz/lb/kg) with segmented toggle wired across all 8 display call sites
- Candidate status tracking (researching/ordered/arrived) with clickable StatusBadge popup
- Sticky search/filter toolbar with text search and icon-aware CategoryFilterDropdown
- Per-setup item classification (base/worn/consumable) with click-to-cycle badge
- Recharts donut chart with category/classification toggle, hover tooltips, and weight subtotals
- Classification-preserving sync that maintains metadata across atomic setup re-sync
**Archive:** `.planning/milestones/v1.2-ROADMAP.md`, `.planning/milestones/v1.2-REQUIREMENTS.md`
---
## v1.1 Fixes & Polish (Shipped: 2026-03-15) ## v1.1 Fixes & Polish (Shipped: 2026-03-15)
**Phases completed:** 3 phases, 7 plans **Phases completed:** 3 phases, 7 plans

View File

@@ -2,7 +2,7 @@
## What This Is ## What This Is
A web-based gear management and purchase planning app. Users catalog their gear collections (bikepacking, sim racing, or any hobby), track weight, price, and source details, and use planning threads to research and compare new purchases. Named setups let users compose loadouts from their collection with live weight/cost totals. Built as a single-user app with a clean, minimalist interface. A web-based gear management and purchase planning app. Users catalog their gear collections (bikepacking, sim racing, or any hobby), track weight, price, and source details, search and filter by name or category, and use planning threads to research and compare new purchases with status tracking. Named setups let users compose loadouts with weight classification (base/worn/consumable), donut chart visualization, and live totals in selectable units. Built as a single-user app with a clean, minimalist interface.
## Core Value ## Core Value
@@ -27,24 +27,32 @@ Make it effortless to manage gear and plan new purchases — see how a potential
- ✓ Hero image upload area with preview and click-to-upload — v1.1 - ✓ Hero image upload area with preview and click-to-upload — v1.1
- ✓ Lucide icon picker for categories (119 curated icons, 8 groups) — v1.1 - ✓ Lucide icon picker for categories (119 curated icons, 8 groups) — v1.1
- ✓ Automatic emoji-to-Lucide icon migration for existing categories — v1.1 - ✓ Automatic emoji-to-Lucide icon migration for existing categories — v1.1
- ✓ Search items by name with instant filtering — v1.2
- ✓ Filter collection items by category with icon-aware dropdown — v1.2
- ✓ Combined text search with category filter and result count — v1.2
- ✓ One-action filter clear — v1.2
- ✓ Weight unit selection (g, oz, lb, kg) with persistence — v1.2
- ✓ All weight displays respect selected unit across entire app — v1.2
- ✓ Per-setup item classification (base weight, worn, consumable) — v1.2
- ✓ Setup weight subtotals by classification — v1.2
- ✓ Donut chart visualization with category/classification toggle — v1.2
- ✓ Chart hover tooltips with weight and percentage — v1.2
- ✓ Candidate status tracking (researching/ordered/arrived) — v1.2
- ✓ Planning category filter with Lucide icons — v1.2
### Active — v1.2 Collection Power-Ups ### Active
**Goal:** Make core gear management significantly more useful as collections grow — better search, proper weight classification, richer planning threads. ## Current Milestone: v1.3 Research & Decision Tools
**Goal:** Give users the tools to actually decide between candidates — compare details side-by-side, see how a pick impacts their setup, and rank/annotate their options.
**Target features:** **Target features:**
- Search items by name and filter by category - Full-detail side-by-side candidate comparison (weight, price, images, notes, links, status)
- Classify items as base weight, worn, or consumable per setup - Impact preview: pick a setup, see +/- weight and cost delta for each candidate
- Weight distribution visualization (chart by category/classification) - Candidate ranking (drag-to-reorder) with pros/cons text fields per candidate
- Candidate status tracking (researching → ordered → arrived)
- Weight unit selection (g, oz, lb, kg)
- Planning category filter with icon-aware dropdown
### Future ### Future
- [ ] Side-by-side candidate comparison on weight and price
- [ ] Candidate ranking/prioritization within threads
- [ ] Impact preview: how a candidate affects setup weight/cost
- [ ] CSV import/export for gear collections - [ ] CSV import/export for gear collections
- [ ] Multi-user accounts with authentication - [ ] Multi-user accounts with authentication
- [ ] Collection sharing and social features (public profiles, shared setups) - [ ] Collection sharing and social features (public profiles, shared setups)
@@ -61,10 +69,11 @@ Make it effortless to manage gear and plan new purchases — see how a potential
## Context ## Context
Shipped v1.1 with 6,134 LOC TypeScript. Shipped v1.2 with 7,310 LOC TypeScript. Starting v1.3 to enhance thread decision workflow.
Tech stack: React 19, Hono, Drizzle ORM, SQLite, TanStack Router/Query, Tailwind CSS v4, Lucide React, all on Bun. Tech stack: React 19, Hono, Drizzle ORM, SQLite, TanStack Router/Query, Tailwind CSS v4, Lucide React, Recharts, all on Bun.
Primary use case is bikepacking gear but data model is hobby-agnostic. Primary use case is bikepacking gear but data model is hobby-agnostic.
Replaces spreadsheet-based gear tracking workflow. Replaces spreadsheet-based gear tracking workflow.
121 tests (service-level and route-level integration).
## Constraints ## Constraints
@@ -96,6 +105,15 @@ Replaces spreadsheet-based gear tracking workflow.
| Hero image area at top of forms | Image-first UX, 4:3 aspect ratio consistent with cards | ✓ Good | | Hero image area at top of forms | Image-first UX, 4:3 aspect ratio consistent with cards | ✓ Good |
| Emoji-to-icon automatic migration | One-time schema rename + data conversion via Drizzle migration | ✓ Good | | Emoji-to-icon automatic migration | One-time schema rename + data conversion via Drizzle migration | ✓ Good |
| ALTER TABLE RENAME COLUMN for SQLite | Simpler than table recreation for column rename | ✓ Good | | ALTER TABLE RENAME COLUMN for SQLite | Simpler than table recreation for column rename | ✓ Good |
| Weight conversion precision: g=0dp, oz=1dp, lb=2dp, kg=2dp | Matches common usage conventions | ✓ Good |
| Unit toggle in TotalsBar (not settings page) | Visible, quick access for frequent switching | ✓ Good |
| CategoryFilterDropdown separate from CategoryPicker | Filter vs form concerns are different | ✓ Good |
| No debounce on search input | Collection under 1000 items, instant feedback | ✓ Good |
| StatusBadge popup with click-outside dismiss | Consistent with CategoryPicker pattern | ✓ Good |
| Classification on setupItems join table | Same item can have different roles per setup | ✓ Good |
| Click-to-cycle for ClassificationBadge | Only 3 values, simpler than popup | ✓ Good |
| Classification-preserving sync via Map | Save metadata before delete, restore after re-insert | ✓ Good |
| Recharts for charting | Mature React chart library, composable API | ✓ Good |
--- ---
*Last updated: 2026-03-16 after v1.2 milestone start* *Last updated: 2026-03-16 after v1.3 milestone start*

View File

@@ -1,59 +1,38 @@
# Requirements: GearBox v1.2 Collection Power-Ups # Requirements: GearBox v1.3 Research & Decision Tools
**Defined:** 2026-03-16 **Defined:** 2026-03-16
**Core Value:** Make it effortless to manage gear and plan new purchases -- see how a potential buy affects your total setup weight and cost before committing. **Core Value:** Make it effortless to manage gear and plan new purchases -- see how a potential buy affects your total setup weight and cost before committing.
## v1.2 Requirements ## v1.3 Requirements
Requirements for this milestone. Each maps to roadmap phases. Requirements for this milestone. Each maps to roadmap phases.
### Search & Filter ### Comparison View
- [x] **SRCH-01**: User can search items by name with instant filtering as they type - [ ] **COMP-01**: User can view candidates side-by-side in a tabular comparison layout (weight, price, images, notes, links, status)
- [x] **SRCH-02**: User can filter collection items by category via dropdown - [ ] **COMP-02**: User can see relative deltas highlighting the lightest and cheapest candidate with +/- differences
- [x] **SRCH-03**: User can combine text search with category filter simultaneously - [ ] **COMP-03**: Comparison table scrolls horizontally with a sticky label column on narrow viewports
- [x] **SRCH-04**: User can see result count when filters are active (e.g., "showing 12 of 47 items") - [ ] **COMP-04**: Comparison view displays read-only summary for resolved threads
- [x] **SRCH-05**: User can clear all active filters with one action
### Weight Units ### Candidate Ranking
- [x] **UNIT-01**: User can select preferred weight unit (g, oz, lb, kg) from settings - [x] **RANK-01**: User can drag candidates to reorder priority ranking within a thread
- [x] **UNIT-02**: All weight displays across the app reflect the selected unit - [x] **RANK-02**: Top 3 ranked candidates display rank badges (gold, silver, bronze)
- [x] **UNIT-03**: Weight unit preference persists across sessions - [x] **RANK-03**: User can add pros and cons text per candidate displayed as bullet lists
- [x] **RANK-04**: Candidate rank order persists across sessions
- [x] **RANK-05**: Drag handles and ranking are disabled on resolved threads
### Weight Classification ### Impact Preview
- [x] **CLAS-01**: User can classify each item within a setup as base weight, worn, or consumable - [ ] **IMPC-01**: User can select a setup and see weight and cost delta for each candidate
- [x] **CLAS-02**: Setup totals display base weight, worn weight, consumable weight, and total separately - [ ] **IMPC-02**: Impact preview auto-detects replace mode when a setup item exists in the same category as the thread
- [x] **CLAS-03**: Items default to "base weight" classification when added to a setup - [ ] **IMPC-03**: Impact preview shows add mode (pure addition) when no category match exists in the selected setup
- [x] **CLAS-04**: Same item can have different classifications in different setups - [ ] **IMPC-04**: Candidates with missing weight data show a clear indicator instead of misleading zero deltas
### Weight Visualization
- [x] **VIZZ-01**: User can view a donut chart showing weight distribution by category in a setup
- [x] **VIZZ-02**: User can toggle chart between category view and classification view (base/worn/consumable)
- [x] **VIZZ-03**: User can hover chart segments to see category name, weight, and percentage
### Candidate Status
- [x] **CAND-01**: Each candidate displays a status badge (researching, ordered, or arrived)
- [x] **CAND-02**: User can change a candidate's status via click interaction
- [x] **CAND-03**: New candidates default to "researching" status
### Planning UI
- [x] **PLAN-01**: Planning category filter dropdown shows Lucide icons alongside category names
## Future Requirements ## Future Requirements
Deferred to future milestones. Tracked but not in current roadmap. Deferred to future milestones. Tracked but not in current roadmap.
### Planning Enhancements
- **COMP-01**: User can compare candidates side-by-side on weight and price
- **RANK-01**: User can rank/prioritize candidates within a thread
- **IMPC-01**: User can preview how a candidate affects setup weight/cost before resolving
### Data Management ### Data Management
- **DATA-01**: User can import gear collection from CSV - **DATA-01**: User can import gear collection from CSV
@@ -75,13 +54,13 @@ Explicitly excluded. Documented to prevent scope creep.
| Feature | Reason | | Feature | Reason |
|---------|--------| |---------|--------|
| Per-item weight input in multiple units | Parsing complexity, ambiguous storage -- display-only conversion is sufficient | | Custom comparison attributes | Complexity trap -- weight/price covers 80% of cases |
| Interactive chart drill-down (click to zoom) | Adds significant interaction complexity for minimal value | | Score/rating calculation | Opaque algorithms distrust; manual ranking expresses user preference better |
| Weight goals / targets | Opinionated norms conflict with hobby-agnostic design | | Cross-thread comparison | Candidates are decision-scoped; different categories are not apples-to-apples |
| Custom classification labels | base/worn/consumable covers 95% of use cases | | Classification-aware impact breakdown | Data available but UI complexity high; flat delta covers 90% of use case |
| Server-side full-text search | Premature for single-user app with <1000 items | | Comparison permalink | Requires auth/multi-user work not in scope for v1 |
| Classification at item level (not setup level) | Same item has different roles in different setups | | Mobile-optimized comparison (swipe) | Horizontal scroll works for now |
| Status change timestamps | Useful but adds schema complexity -- defer | | Rank badge on card grid view | Low urgency; add when users express confusion |
## Traceability ## Traceability
@@ -89,31 +68,25 @@ Which phases cover which requirements. Updated during roadmap creation.
| Requirement | Phase | Status | | Requirement | Phase | Status |
|-------------|-------|--------| |-------------|-------|--------|
| SRCH-01 | Phase 8 | Complete | | COMP-01 | Phase 12 | Pending |
| SRCH-02 | Phase 8 | Complete | | COMP-02 | Phase 12 | Pending |
| SRCH-03 | Phase 8 | Complete | | COMP-03 | Phase 12 | Pending |
| SRCH-04 | Phase 8 | Complete | | COMP-04 | Phase 12 | Pending |
| SRCH-05 | Phase 8 | Complete | | RANK-01 | Phase 11 | Complete |
| UNIT-01 | Phase 7 | Complete | | RANK-02 | Phase 11 | Complete |
| UNIT-02 | Phase 7 | Complete | | RANK-03 | Phase 10 | Complete |
| UNIT-03 | Phase 7 | Complete | | RANK-04 | Phase 11 | Complete |
| CLAS-01 | Phase 9 | Complete | | RANK-05 | Phase 11 | Complete |
| CLAS-02 | Phase 9 | Complete | | IMPC-01 | Phase 13 | Pending |
| CLAS-03 | Phase 9 | Complete | | IMPC-02 | Phase 13 | Pending |
| CLAS-04 | Phase 9 | Complete | | IMPC-03 | Phase 13 | Pending |
| VIZZ-01 | Phase 9 | Complete | | IMPC-04 | Phase 13 | Pending |
| VIZZ-02 | Phase 9 | Complete |
| VIZZ-03 | Phase 9 | Complete |
| CAND-01 | Phase 8 | Complete |
| CAND-02 | Phase 8 | Complete |
| CAND-03 | Phase 8 | Complete |
| PLAN-01 | Phase 8 | Complete |
**Coverage:** **Coverage:**
- v1.2 requirements: 19 total - v1.3 requirements: 13 total
- Mapped to phases: 19 - Mapped to phases: 13
- Unmapped: 0 - Unmapped: 0
--- ---
*Requirements defined: 2026-03-16* *Requirements defined: 2026-03-16*
*Last updated: 2026-03-16 after roadmap creation* *Last updated: 2026-03-16*

View File

@@ -91,6 +91,51 @@
--- ---
## Milestone: v1.2 — Collection Power-Ups
**Shipped:** 2026-03-16
**Phases:** 3 | **Plans:** 6 | **Files changed:** 66
### What Was Built
- Weight unit conversion (g/oz/lb/kg) with segmented toggle wired across all weight display call sites
- Candidate status tracking (researching/ordered/arrived) with clickable StatusBadge popup
- Sticky search/filter toolbar with text search and icon-aware CategoryFilterDropdown
- Per-setup item classification (base/worn/consumable) with click-to-cycle ClassificationBadge
- Recharts donut chart with category/classification toggle and hover tooltips
- Classification-preserving sync that maintains metadata across atomic setup item re-sync
### What Worked
- Coarse 3-phase structure again — 19 requirements compressed into 3 phases with clear dependency ordering
- TDD red/green commits for schema migrations (status, classification) caught edge cases early
- Vertical slice pattern (schema → service → tests → API → UI in one plan) kept each deliverable self-contained
- Click-outside dismiss pattern established in v1.1 was reused cleanly in StatusBadge and CategoryFilterDropdown
- All 6 plans executed with zero deviations from plan — evidence of mature planning process
### What Was Inefficient
- Some ROADMAP.md plan checkboxes remained unchecked despite summaries existing (persistent cosmetic drift)
- Recharts v3 Cell component is deprecated for v4 — will need migration eventually
- Phase 8 bundled search/filter with candidate status (different concerns) — could have been separate phases for cleaner scope
### Patterns Established
- Click-to-cycle badge: for small enums (3 values), direct click cycling is simpler than popup menus
- Join table metadata preservation: save metadata to Map before atomic sync, restore after re-insert
- CategoryFilterDropdown: reusable filter dropdown (separate from form-based CategoryPicker)
- Chart data transformation: group items by key, sum weights, compute percentages, filter zeroes
- apiPatch helper: PATCH method now available in client API library for partial updates
### Key Lessons
1. Classification belongs on join tables (setupItems), not entity tables (items) — same item has different roles in different contexts
2. Vertical slice delivery (schema → service → test → API → UI) is the optimal plan structure for feature additions
3. Search complexity should match data scale — no debounce needed for <1000 items
4. Recharts composable API (PieChart + Pie + Cell + Tooltip + Label) gives fine-grained chart control with minimal wrapper code
### Cost Observations
- Model mix: quality profile throughout (opus for execution)
- Sessions: 3 continuous auto-advance sessions (one per phase)
- Notable: All plans completed with zero deviations, execution faster than v1.0/v1.1
---
## Cross-Milestone Trends ## Cross-Milestone Trends
### Process Evolution ### Process Evolution
@@ -99,6 +144,7 @@
|-----------|---------|--------|------------| |-----------|---------|--------|------------|
| v1.0 | 53 | 3 | Initial build, coarse granularity, TDD backend | | v1.0 | 53 | 3 | Initial build, coarse granularity, TDD backend |
| v1.1 | ~30 | 3 | Auto-advance pipeline, parallel wave execution, auto-fix deviations | | v1.1 | ~30 | 3 | Auto-advance pipeline, parallel wave execution, auto-fix deviations |
| v1.2 | 25 | 3 | Zero-deviation execution, vertical slice pattern, join table metadata |
### Cumulative Quality ### Cumulative Quality
@@ -106,6 +152,7 @@
|-----------|-----|-------|-------| |-----------|-----|-------|-------|
| v1.0 | 5,742 | 114 | Service + route integration | | v1.0 | 5,742 | 114 | Service + route integration |
| v1.1 | 6,134 | ~130 | Service + route integration (updated for icon schema) | | v1.1 | 6,134 | ~130 | Service + route integration (updated for icon schema) |
| v1.2 | 7,310 | ~150 | 121 tests (service + route + classification) |
### Top Lessons (Verified Across Milestones) ### Top Lessons (Verified Across Milestones)
@@ -113,3 +160,5 @@
2. Service DI pattern enables fast, reliable testing without mocks 2. Service DI pattern enables fast, reliable testing without mocks
3. Always update Zod schemas alongside DB schema — middleware silently strips unvalidated fields 3. Always update Zod schemas alongside DB schema — middleware silently strips unvalidated fields
4. Auto-advance pipeline (discuss → plan → execute) works well for clear-scope phases 4. Auto-advance pipeline (discuss → plan → execute) works well for clear-scope phases
5. Vertical slice delivery (schema → service → test → API → UI) is optimal for feature additions
6. Join table metadata (not entity table) when same entity plays different roles in different contexts

View File

@@ -2,89 +2,102 @@
## Milestones ## Milestones
- v1.0 MVP -- Phases 1-3 (shipped 2026-03-15) - **v1.0 MVP** Phases 1-3 (shipped 2026-03-15)
- v1.1 Fixes & Polish -- Phases 4-6 (shipped 2026-03-15) - **v1.1 Fixes & Polish** Phases 4-6 (shipped 2026-03-15)
- **v1.2 Collection Power-Ups** -- Phases 7-9 (in progress) - **v1.2 Collection Power-Ups** Phases 7-9 (shipped 2026-03-16)
- 🚧 **v1.3 Research & Decision Tools** — Phases 10-13 (in progress)
## Phases ## Phases
<details> <details>
<summary>v1.0 MVP (Phases 1-3) -- SHIPPED 2026-03-15</summary> <summary>v1.0 MVP (Phases 1-3) SHIPPED 2026-03-15</summary>
- [x] Phase 1: Foundation and Collection (4/4 plans) -- completed 2026-03-14 - [x] Phase 1: Foundation and Collection (4/4 plans) completed 2026-03-14
- [x] Phase 2: Planning Threads (3/3 plans) -- completed 2026-03-15 - [x] Phase 2: Planning Threads (3/3 plans) completed 2026-03-15
- [x] Phase 3: Setups and Dashboard (3/3 plans) -- completed 2026-03-15 - [x] Phase 3: Setups and Dashboard (3/3 plans) completed 2026-03-15
</details> </details>
<details> <details>
<summary>v1.1 Fixes & Polish (Phases 4-6) -- SHIPPED 2026-03-15</summary> <summary>v1.1 Fixes & Polish (Phases 4-6) SHIPPED 2026-03-15</summary>
- [x] Phase 4: Database & Planning Fixes (2/2 plans) -- completed 2026-03-15 - [x] Phase 4: Database & Planning Fixes (2/2 plans) completed 2026-03-15
- [x] Phase 5: Image Handling (2/2 plans) -- completed 2026-03-15 - [x] Phase 5: Image Handling (2/2 plans) completed 2026-03-15
- [x] Phase 6: Category Icons (3/3 plans) -- completed 2026-03-15 - [x] Phase 6: Category Icons (3/3 plans) completed 2026-03-15
</details> </details>
### v1.2 Collection Power-Ups (In Progress) <details>
<summary>✅ v1.2 Collection Power-Ups (Phases 7-9) — SHIPPED 2026-03-16</summary>
**Milestone Goal:** Make core gear management significantly more useful as collections grow -- better search, proper weight classification, richer planning threads. - [x] Phase 7: Weight Unit Selection (2/2 plans) — completed 2026-03-16
- [x] Phase 8: Search, Filter, and Candidate Status (2/2 plans) — completed 2026-03-16
- [x] Phase 9: Weight Classification and Visualization (2/2 plans) — completed 2026-03-16
- [x] **Phase 7: Weight Unit Selection** - Users see all weights in their preferred unit across the entire app </details>
- [x] **Phase 8: Search, Filter, and Candidate Status** - Users can find items quickly and track candidate purchase progress
- [x] **Phase 9: Weight Classification and Visualization** - Users can classify gear by role and visualize weight distribution in setups ### v1.3 Research & Decision Tools (In Progress)
**Milestone Goal:** Give users the tools to actually decide between candidates — compare details side-by-side, see how a pick impacts their setup, and rank/annotate their options.
- [x] **Phase 10: Schema Foundation + Pros/Cons Fields** — Migrate schema and deliver pros/cons annotation UI (completed 2026-03-16)
- [x] **Phase 11: Candidate Ranking** — Drag-to-reorder priority ranking with rank badges (completed 2026-03-16)
- [ ] **Phase 12: Comparison View** — Side-by-side tabular comparison with relative deltas
- [ ] **Phase 13: Setup Impact Preview** — Per-candidate weight and cost delta against a selected setup
## Phase Details ## Phase Details
### Phase 7: Weight Unit Selection ### Phase 10: Schema Foundation + Pros/Cons Fields
**Goal**: Users see all weights in their preferred unit across the entire app **Goal**: Candidates can be annotated with pros and cons, and the database is ready for ranking
**Depends on**: Nothing (first phase of v1.2) **Depends on**: Phase 9
**Requirements**: UNIT-01, UNIT-02, UNIT-03 **Requirements**: RANK-03
**Success Criteria** (what must be TRUE): **Success Criteria** (what must be TRUE):
1. User can select a weight unit (g, oz, lb, kg) from a visible control and the selection persists after closing and reopening the app 1. User can open a candidate edit form and see pros and cons text fields
2. Every weight value in the app (item cards, candidate cards, category headers, totals bar, setup details) displays in the selected unit with appropriate precision 2. User can save pros and cons text; the text persists across page refreshes
3. Weight input fields accept values and store them correctly regardless of display unit (no rounding drift across edit cycles) 3. CandidateCard shows a visual indicator when a candidate has pros or cons entered
**Plans:** 2 plans 4. All existing tests pass after the schema migration (no column drift in test helper)
**Plans:** 1/1 plans complete
Plans: Plans:
- [x] 07-01-PLAN.md -- TDD formatWeight unit conversion core + useWeightUnit hook - [x] 10-01-PLAN.md — Add pros/cons fields through full stack (schema, service, Zod, form, card indicator)
- [ ] 07-02-PLAN.md -- Wire unit toggle into TotalsBar and update all 8 call sites
### Phase 8: Search, Filter, and Candidate Status ### Phase 11: Candidate Ranking
**Goal**: Users can find items quickly and track candidate purchase progress **Goal**: Users can drag candidates into a priority order that persists and is visually communicated
**Depends on**: Phase 7 **Depends on**: Phase 10
**Requirements**: SRCH-01, SRCH-02, SRCH-03, SRCH-04, SRCH-05, PLAN-01, CAND-01, CAND-02, CAND-03 **Requirements**: RANK-01, RANK-02, RANK-04, RANK-05
**Success Criteria** (what must be TRUE): **Success Criteria** (what must be TRUE):
1. User can type in a search field on the collection page and see items filtered instantly by name as they type 1. User can drag a candidate card to a new position within the thread's candidate list
2. User can select a category from a dropdown (showing Lucide icons alongside names) to filter items in both collection and planning views 2. The reordered sequence is still intact after navigating away and returning
3. User can see how many items match active filters (e.g., "showing 12 of 47 items") and clear all filters with one action 3. The top three candidates display gold, silver, and bronze rank badges respectively
4. Each candidate in a planning thread displays a status badge (researching, ordered, or arrived) that the user can change by clicking 4. Drag handles and rank badges are absent on a resolved thread; candidates render in static order
5. New candidates automatically start with "researching" status **Plans:** 2/2 plans complete
**Plans:** 2 plans
Plans: Plans:
- [ ] 08-01-PLAN.md -- Candidate status vertical slice (schema migration, service, tests, StatusBadge UI) - [ ] 11-01-PLAN.md — Schema migration, reorder service/route, sort_order persistence + tests
- [ ] 08-02-PLAN.md -- Search/filter toolbar with CategoryFilterDropdown on gear and planning tabs - [ ] 11-02-PLAN.md — Drag-to-reorder UI, list/grid toggle, rank badges, resolved-thread guard
### Phase 9: Weight Classification and Visualization ### Phase 12: Comparison View
**Goal**: Users can classify gear by role and visualize weight distribution in setups **Goal**: Users can view all candidates for a thread side-by-side in a table with relative weight and price deltas
**Depends on**: Phase 7, Phase 8 **Depends on**: Phase 11
**Requirements**: CLAS-01, CLAS-02, CLAS-03, CLAS-04, VIZZ-01, VIZZ-02, VIZZ-03 **Requirements**: COMP-01, COMP-02, COMP-03, COMP-04
**Success Criteria** (what must be TRUE): **Success Criteria** (what must be TRUE):
1. User can classify each item within a setup as base weight, worn, or consumable, and the same item can have different classifications in different setups 1. User can toggle a "Compare" mode on a thread detail page to reveal a tabular view showing weight, price, images, notes, links, status, pros, and cons for every candidate in columns
2. Setup detail view shows separate weight subtotals for base weight, worn weight, and consumable weight in addition to the overall total 2. The lightest candidate column is highlighted and all other columns show their weight difference relative to it; the cheapest candidate is highlighted similarly for price
3. User can view a donut chart in a setup showing weight distribution, and toggle between category breakdown and classification breakdown 3. The comparison table scrolls horizontally on a narrow viewport without breaking layout; the attribute label column stays fixed on the left
4. User can hover chart segments to see the category/classification name, weight (in selected unit), and percentage 4. A resolved thread shows the comparison table in read-only mode with the winning candidate visually marked
**Plans:** 2 plans **Plans**: TBD
Plans: ### Phase 13: Setup Impact Preview
- [ ] 09-01-PLAN.md -- Classification vertical slice (schema, service, tests, API route, ClassificationBadge UI) **Goal**: Users can select any setup and see exactly how much weight and cost each candidate would add or subtract
- [ ] 09-02-PLAN.md -- WeightSummaryCard with subtotals, donut chart, pill toggle, and visual verification **Depends on**: Phase 12
**Requirements**: IMPC-01, IMPC-02, IMPC-03, IMPC-04
**Success Criteria** (what must be TRUE):
1. User can select a setup from a dropdown in the thread header and each candidate displays a weight delta and cost delta below its name
2. When the selected setup contains an item in the same category as the thread, the delta reflects replacing that item (negative delta is possible) rather than pure addition
3. When no category match exists in the selected setup, the delta shows a pure addition amount clearly labeled as "add"
4. A candidate with no weight recorded shows a "-- (no weight data)" indicator instead of a zero delta
**Plans**: TBD
## Progress ## Progress
**Execution Order:** Phase 7 -> Phase 8 -> Phase 9
| Phase | Milestone | Plans Complete | Status | Completed | | Phase | Milestone | Plans Complete | Status | Completed |
|-------|-----------|----------------|--------|-----------| |-------|-----------|----------------|--------|-----------|
| 1. Foundation and Collection | v1.0 | 4/4 | Complete | 2026-03-14 | | 1. Foundation and Collection | v1.0 | 4/4 | Complete | 2026-03-14 |
@@ -96,3 +109,7 @@ Plans:
| 7. Weight Unit Selection | v1.2 | 2/2 | Complete | 2026-03-16 | | 7. Weight Unit Selection | v1.2 | 2/2 | Complete | 2026-03-16 |
| 8. Search, Filter, and Candidate Status | v1.2 | 2/2 | Complete | 2026-03-16 | | 8. Search, Filter, and Candidate Status | v1.2 | 2/2 | Complete | 2026-03-16 |
| 9. Weight Classification and Visualization | v1.2 | 2/2 | Complete | 2026-03-16 | | 9. Weight Classification and Visualization | v1.2 | 2/2 | Complete | 2026-03-16 |
| 10. Schema Foundation + Pros/Cons Fields | v1.3 | 1/1 | Complete | 2026-03-16 |
| 11. Candidate Ranking | 2/2 | Complete | 2026-03-16 | - |
| 12. Comparison View | v1.3 | 0/TBD | Not started | - |
| 13. Setup Impact Preview | v1.3 | 0/TBD | Not started | - |

View File

@@ -1,17 +1,17 @@
--- ---
gsd_state_version: 1.0 gsd_state_version: 1.0
milestone: v1.2 milestone: v1.3
milestone_name: Collection Power-Ups milestone_name: Research & Decision Tools
status: completed status: planning
stopped_at: Completed 09-02-PLAN.md stopped_at: Completed 11-candidate-ranking/11-02-PLAN.md
last_updated: "2026-03-16T14:29:36.577Z" last_updated: "2026-03-16T21:39:11.967Z"
last_activity: 2026-03-16 -- Completed 09-02 weight breakdown visualization last_activity: 2026-03-16 — Roadmap created for v1.3 milestone
progress: progress:
total_phases: 3 total_phases: 4
completed_phases: 3 completed_phases: 2
total_plans: 6 total_plans: 3
completed_plans: 6 completed_plans: 3
percent: 100 percent: 0
--- ---
# Project State # Project State
@@ -21,40 +21,57 @@ progress:
See: .planning/PROJECT.md (updated 2026-03-16) See: .planning/PROJECT.md (updated 2026-03-16)
**Core value:** Make it effortless to manage gear and plan new purchases -- see how a potential buy affects your total setup weight and cost before committing. **Core value:** Make it effortless to manage gear and plan new purchases -- see how a potential buy affects your total setup weight and cost before committing.
**Current focus:** Milestone v1.2 complete -- all phases finished **Current focus:** v1.3 Research & Decision Tools — Phase 10 ready to plan
## Current Position ## Current Position
Phase: 9 of 9 (Weight Classification & Visualization) Phase: 10 of 13 (Schema Foundation + Pros/Cons Fields)
Plan: 2 of 2 Plan:
Status: Complete Status: Ready to plan
Last activity: 2026-03-16 -- Completed 09-02 weight breakdown visualization Last activity: 2026-03-16 — Roadmap created for v1.3 milestone
Progress: [██████████] 100% Progress: [░░░░░░░░░░] 0%
## Performance Metrics
**Velocity:**
- Total plans completed: 0
- Average duration: —
- Total execution time: —
**By Phase:**
| Phase | Plans | Total | Avg/Plan |
|-------|-------|-------|----------|
| - | - | - | - |
**Recent Trend:**
- Last 5 plans: —
- Trend: —
*Updated after each plan completion*
| Phase 10-schema-foundation-pros-cons-fields P01 | 6min | 2 tasks | 9 files |
| Phase 11-candidate-ranking P01 | 4min | 2 tasks | 8 files |
| Phase 11-candidate-ranking P02 | 4min | 3 tasks | 7 files |
## Accumulated Context ## Accumulated Context
### Decisions ### Decisions
(Full decision log in PROJECT.md Key Decisions table) Cleared at milestone boundary. v1.2 decisions archived in milestones/v1.2-ROADMAP.md.
- Coarse granularity: 19 requirements compressed into 3 phases (7-9) Key v1.3 research findings (see research/SUMMARY.md):
- Weight unit selection must be Phase 7 (formatWeight refactor touches all weight displays) - framer-motion@12.37.0 (already installed) handles drag-to-reorder via Reorder component — no new deps
- Classification belongs on setup_items join table, NOT items table - sort_order must use REAL (float) type, not INTEGER, to avoid bulk writes on every drag
- Candidate status and classification schema migrations in separate phases (sequential) - Impact preview must distinguish add-mode vs replace-mode by category match — pure addition misleads
- Weight conversion precision: g=0dp, oz=1dp, lb=2dp, kg=2dp - [Phase 10-schema-foundation-pros-cons-fields]: Empty string for pros/cons stored as-is (not normalized to null); test accepts either empty string or null as cleared state
- useWeightUnit validates stored value against known units to protect against corrupt data - [Phase 10-schema-foundation-pros-cons-fields]: Pros/Cons badge uses purple color to distinguish from weight (blue), price (green), category (gray), and status badges
- Unit toggle placed between title and stats in TotalsBar for subtle utility placement - [Phase 10-schema-foundation-pros-cons-fields]: Field-addition ladder pattern: schema -> migration -> test helper -> service -> Zod -> types -> hook -> form -> card indicator
- CategoryFilterDropdown kept separate from CategoryPicker (filter vs form concerns) - [Phase 11-candidate-ranking]: sortOrder uses REAL type for future fractional midpoint insertions without bulk rewrites
- No debounce on search input (collection under 1000 items) - [Phase 11-candidate-ranking]: 1000-gap sort_order strategy: first=1000, append=max+1000, reorder resets to (index+1)*1000
- Individual clear controls for search and category filter (no combined clear-all) - [Phase 11-candidate-ranking]: Applied sort_order migration via sqlite3 CLI directly to avoid Drizzle data-loss warning on existing rows
- [Phase 08]: CategoryFilterDropdown kept separate from CategoryPicker (filter vs form concerns) - [Phase 11-candidate-ranking]: Resolved thread list view uses plain div (not Reorder.Group) — no drag, rank badges visible
- [Phase 08]: StatusBadge popup uses click-outside + Escape dismiss pattern matching CategoryPicker - [Phase 11-candidate-ranking]: RankBadge exported from CandidateListItem for reuse in CandidateCard grid view
- [Phase 08]: Status badge uses muted gray tones (bg-gray-100 text-gray-600) per user design decision
- [Phase 09]: ClassificationBadge uses simple click-to-cycle (not popup) since only 3 values
- [Phase 09]: Classification stored on setupItems join table so same item can differ across setups
- [Phase 09]: syncSetupItems preserves classifications via Map before delete/restore after re-insert
- [Phase 09]: Recharts v3 Cell component used for per-slice colors (still functional, deprecated for v4)
### Pending Todos ### Pending Todos
@@ -66,6 +83,6 @@ None active.
## Session Continuity ## Session Continuity
Last session: 2026-03-16T14:22:28.169Z Last session: 2026-03-16T21:30:15.459Z
Stopped at: Completed 09-02-PLAN.md Stopped at: Completed 11-candidate-ranking/11-02-PLAN.md
Resume file: None Resume file: None

View File

@@ -0,0 +1,128 @@
# Requirements Archive: v1.2 Collection Power-Ups
**Archived:** 2026-03-16
**Status:** SHIPPED
For current requirements, see `.planning/REQUIREMENTS.md`.
---
# Requirements: GearBox v1.2 Collection Power-Ups
**Defined:** 2026-03-16
**Core Value:** Make it effortless to manage gear and plan new purchases -- see how a potential buy affects your total setup weight and cost before committing.
## v1.2 Requirements
Requirements for this milestone. Each maps to roadmap phases.
### Search & Filter
- [x] **SRCH-01**: User can search items by name with instant filtering as they type
- [x] **SRCH-02**: User can filter collection items by category via dropdown
- [x] **SRCH-03**: User can combine text search with category filter simultaneously
- [x] **SRCH-04**: User can see result count when filters are active (e.g., "showing 12 of 47 items")
- [x] **SRCH-05**: User can clear all active filters with one action
### Weight Units
- [x] **UNIT-01**: User can select preferred weight unit (g, oz, lb, kg) from settings
- [x] **UNIT-02**: All weight displays across the app reflect the selected unit
- [x] **UNIT-03**: Weight unit preference persists across sessions
### Weight Classification
- [x] **CLAS-01**: User can classify each item within a setup as base weight, worn, or consumable
- [x] **CLAS-02**: Setup totals display base weight, worn weight, consumable weight, and total separately
- [x] **CLAS-03**: Items default to "base weight" classification when added to a setup
- [x] **CLAS-04**: Same item can have different classifications in different setups
### Weight Visualization
- [x] **VIZZ-01**: User can view a donut chart showing weight distribution by category in a setup
- [x] **VIZZ-02**: User can toggle chart between category view and classification view (base/worn/consumable)
- [x] **VIZZ-03**: User can hover chart segments to see category name, weight, and percentage
### Candidate Status
- [x] **CAND-01**: Each candidate displays a status badge (researching, ordered, or arrived)
- [x] **CAND-02**: User can change a candidate's status via click interaction
- [x] **CAND-03**: New candidates default to "researching" status
### Planning UI
- [x] **PLAN-01**: Planning category filter dropdown shows Lucide icons alongside category names
## Future Requirements
Deferred to future milestones. Tracked but not in current roadmap.
### Planning Enhancements
- **COMP-01**: User can compare candidates side-by-side on weight and price
- **RANK-01**: User can rank/prioritize candidates within a thread
- **IMPC-01**: User can preview how a candidate affects setup weight/cost before resolving
### Data Management
- **DATA-01**: User can import gear collection from CSV
- **DATA-02**: User can export gear collection to CSV
### Social & Multi-User
- **SOCL-01**: User can create an account with authentication
- **SOCL-02**: User can share collections and setups publicly
- **SOCL-03**: User can view other users' public profiles and setups
### Automation
- **AUTO-01**: System can auto-fill product information (price, weight, images) from external sources
## Out of Scope
Explicitly excluded. Documented to prevent scope creep.
| Feature | Reason |
|---------|--------|
| Per-item weight input in multiple units | Parsing complexity, ambiguous storage -- display-only conversion is sufficient |
| Interactive chart drill-down (click to zoom) | Adds significant interaction complexity for minimal value |
| Weight goals / targets | Opinionated norms conflict with hobby-agnostic design |
| Custom classification labels | base/worn/consumable covers 95% of use cases |
| Server-side full-text search | Premature for single-user app with <1000 items |
| Classification at item level (not setup level) | Same item has different roles in different setups |
| Status change timestamps | Useful but adds schema complexity -- defer |
## Traceability
Which phases cover which requirements. Updated during roadmap creation.
| Requirement | Phase | Status |
|-------------|-------|--------|
| SRCH-01 | Phase 8 | Complete |
| SRCH-02 | Phase 8 | Complete |
| SRCH-03 | Phase 8 | Complete |
| SRCH-04 | Phase 8 | Complete |
| SRCH-05 | Phase 8 | Complete |
| UNIT-01 | Phase 7 | Complete |
| UNIT-02 | Phase 7 | Complete |
| UNIT-03 | Phase 7 | Complete |
| CLAS-01 | Phase 9 | Complete |
| CLAS-02 | Phase 9 | Complete |
| CLAS-03 | Phase 9 | Complete |
| CLAS-04 | Phase 9 | Complete |
| VIZZ-01 | Phase 9 | Complete |
| VIZZ-02 | Phase 9 | Complete |
| VIZZ-03 | Phase 9 | Complete |
| CAND-01 | Phase 8 | Complete |
| CAND-02 | Phase 8 | Complete |
| CAND-03 | Phase 8 | Complete |
| PLAN-01 | Phase 8 | Complete |
**Coverage:**
- v1.2 requirements: 19 total
- Mapped to phases: 19
- Unmapped: 0
---
*Requirements defined: 2026-03-16*
*Last updated: 2026-03-16 after roadmap creation*

View File

@@ -0,0 +1,98 @@
# Roadmap: GearBox
## Milestones
- v1.0 MVP -- Phases 1-3 (shipped 2026-03-15)
- v1.1 Fixes & Polish -- Phases 4-6 (shipped 2026-03-15)
- **v1.2 Collection Power-Ups** -- Phases 7-9 (in progress)
## Phases
<details>
<summary>v1.0 MVP (Phases 1-3) -- SHIPPED 2026-03-15</summary>
- [x] Phase 1: Foundation and Collection (4/4 plans) -- completed 2026-03-14
- [x] Phase 2: Planning Threads (3/3 plans) -- completed 2026-03-15
- [x] Phase 3: Setups and Dashboard (3/3 plans) -- completed 2026-03-15
</details>
<details>
<summary>v1.1 Fixes & Polish (Phases 4-6) -- SHIPPED 2026-03-15</summary>
- [x] Phase 4: Database & Planning Fixes (2/2 plans) -- completed 2026-03-15
- [x] Phase 5: Image Handling (2/2 plans) -- completed 2026-03-15
- [x] Phase 6: Category Icons (3/3 plans) -- completed 2026-03-15
</details>
### v1.2 Collection Power-Ups (In Progress)
**Milestone Goal:** Make core gear management significantly more useful as collections grow -- better search, proper weight classification, richer planning threads.
- [x] **Phase 7: Weight Unit Selection** - Users see all weights in their preferred unit across the entire app
- [x] **Phase 8: Search, Filter, and Candidate Status** - Users can find items quickly and track candidate purchase progress
- [x] **Phase 9: Weight Classification and Visualization** - Users can classify gear by role and visualize weight distribution in setups
## Phase Details
### Phase 7: Weight Unit Selection
**Goal**: Users see all weights in their preferred unit across the entire app
**Depends on**: Nothing (first phase of v1.2)
**Requirements**: UNIT-01, UNIT-02, UNIT-03
**Success Criteria** (what must be TRUE):
1. User can select a weight unit (g, oz, lb, kg) from a visible control and the selection persists after closing and reopening the app
2. Every weight value in the app (item cards, candidate cards, category headers, totals bar, setup details) displays in the selected unit with appropriate precision
3. Weight input fields accept values and store them correctly regardless of display unit (no rounding drift across edit cycles)
**Plans:** 2 plans
Plans:
- [x] 07-01-PLAN.md -- TDD formatWeight unit conversion core + useWeightUnit hook
- [ ] 07-02-PLAN.md -- Wire unit toggle into TotalsBar and update all 8 call sites
### Phase 8: Search, Filter, and Candidate Status
**Goal**: Users can find items quickly and track candidate purchase progress
**Depends on**: Phase 7
**Requirements**: SRCH-01, SRCH-02, SRCH-03, SRCH-04, SRCH-05, PLAN-01, CAND-01, CAND-02, CAND-03
**Success Criteria** (what must be TRUE):
1. User can type in a search field on the collection page and see items filtered instantly by name as they type
2. User can select a category from a dropdown (showing Lucide icons alongside names) to filter items in both collection and planning views
3. User can see how many items match active filters (e.g., "showing 12 of 47 items") and clear all filters with one action
4. Each candidate in a planning thread displays a status badge (researching, ordered, or arrived) that the user can change by clicking
5. New candidates automatically start with "researching" status
**Plans:** 2 plans
Plans:
- [ ] 08-01-PLAN.md -- Candidate status vertical slice (schema migration, service, tests, StatusBadge UI)
- [ ] 08-02-PLAN.md -- Search/filter toolbar with CategoryFilterDropdown on gear and planning tabs
### Phase 9: Weight Classification and Visualization
**Goal**: Users can classify gear by role and visualize weight distribution in setups
**Depends on**: Phase 7, Phase 8
**Requirements**: CLAS-01, CLAS-02, CLAS-03, CLAS-04, VIZZ-01, VIZZ-02, VIZZ-03
**Success Criteria** (what must be TRUE):
1. User can classify each item within a setup as base weight, worn, or consumable, and the same item can have different classifications in different setups
2. Setup detail view shows separate weight subtotals for base weight, worn weight, and consumable weight in addition to the overall total
3. User can view a donut chart in a setup showing weight distribution, and toggle between category breakdown and classification breakdown
4. User can hover chart segments to see the category/classification name, weight (in selected unit), and percentage
**Plans:** 2 plans
Plans:
- [ ] 09-01-PLAN.md -- Classification vertical slice (schema, service, tests, API route, ClassificationBadge UI)
- [ ] 09-02-PLAN.md -- WeightSummaryCard with subtotals, donut chart, pill toggle, and visual verification
## Progress
**Execution Order:** Phase 7 -> Phase 8 -> Phase 9
| Phase | Milestone | Plans Complete | Status | Completed |
|-------|-----------|----------------|--------|-----------|
| 1. Foundation and Collection | v1.0 | 4/4 | Complete | 2026-03-14 |
| 2. Planning Threads | v1.0 | 3/3 | Complete | 2026-03-15 |
| 3. Setups and Dashboard | v1.0 | 3/3 | Complete | 2026-03-15 |
| 4. Database & Planning Fixes | v1.1 | 2/2 | Complete | 2026-03-15 |
| 5. Image Handling | v1.1 | 2/2 | Complete | 2026-03-15 |
| 6. Category Icons | v1.1 | 3/3 | Complete | 2026-03-15 |
| 7. Weight Unit Selection | v1.2 | 2/2 | Complete | 2026-03-16 |
| 8. Search, Filter, and Candidate Status | v1.2 | 2/2 | Complete | 2026-03-16 |
| 9. Weight Classification and Visualization | v1.2 | 2/2 | Complete | 2026-03-16 |

View File

@@ -0,0 +1,302 @@
---
phase: 10-schema-foundation-pros-cons-fields
plan: 01
type: execute
wave: 1
depends_on: []
files_modified:
- src/db/schema.ts
- tests/helpers/db.ts
- src/server/services/thread.service.ts
- src/shared/schemas.ts
- src/client/hooks/useCandidates.ts
- src/client/components/CandidateForm.tsx
- src/client/components/CandidateCard.tsx
- src/client/routes/threads/$threadId.tsx
- tests/services/thread.service.test.ts
autonomous: true
requirements: [RANK-03]
must_haves:
truths:
- "User can open a candidate edit form and see pros and cons text fields"
- "User can save pros and cons text; the text persists across page refreshes"
- "CandidateCard shows a visual indicator when a candidate has pros or cons entered"
- "All existing tests pass after the schema migration (no column drift in test helper)"
artifacts:
- path: "src/db/schema.ts"
provides: "pros and cons nullable TEXT columns on threadCandidates"
contains: "pros: text"
- path: "tests/helpers/db.ts"
provides: "Mirrored pros/cons columns in test DB CREATE TABLE"
contains: "pros TEXT"
- path: "src/server/services/thread.service.ts"
provides: "pros/cons in createCandidate, updateCandidate, getThreadWithCandidates"
contains: "pros:"
- path: "src/shared/schemas.ts"
provides: "pros and cons optional string fields in createCandidateSchema"
contains: "pros: z.string"
- path: "src/client/components/CandidateForm.tsx"
provides: "Pros and Cons textarea inputs in candidate form"
contains: "candidate-pros"
- path: "src/client/components/CandidateCard.tsx"
provides: "Visual indicator badge when pros or cons are present"
contains: "pros || cons"
- path: "tests/services/thread.service.test.ts"
provides: "Tests for pros/cons in create, update, and get operations"
contains: "pros"
key_links:
- from: "src/db/schema.ts"
to: "tests/helpers/db.ts"
via: "Manual column mirroring in CREATE TABLE"
pattern: "pros TEXT"
- from: "src/shared/schemas.ts"
to: "src/server/services/thread.service.ts"
via: "Zod-inferred CreateCandidate type used in service"
pattern: "CreateCandidate"
- from: "src/server/services/thread.service.ts"
to: "src/client/hooks/useCandidates.ts"
via: "API JSON response includes pros/cons fields"
pattern: "pros.*string.*null"
- from: "src/client/hooks/useCandidates.ts"
to: "src/client/components/CandidateForm.tsx"
via: "CandidateResponse type drives form pre-fill"
pattern: "candidate\\.pros"
- from: "src/client/routes/threads/$threadId.tsx"
to: "src/client/components/CandidateCard.tsx"
via: "Props threaded from candidate data to card"
pattern: "pros=.*candidate\\.pros"
---
<objective>
Add pros and cons annotation fields to thread candidates, from database through UI.
Purpose: RANK-03 requires users to add pros/cons text per candidate for decision-making. This plan follows the established field-addition ladder: schema -> migration -> test helper -> service -> Zod -> types -> hook -> form -> card indicator.
Output: Two new nullable TEXT columns (pros, cons) on thread_candidates, fully wired through all layers, with service-level tests and a visual indicator on CandidateCard.
</objective>
<execution_context>
@/home/jlmak/.claude/get-shit-done/workflows/execute-plan.md
@/home/jlmak/.claude/get-shit-done/templates/summary.md
</execution_context>
<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/10-schema-foundation-pros-cons-fields/10-RESEARCH.md
<interfaces>
<!-- Current codebase contracts the executor needs. -->
From src/db/schema.ts (threadCandidates table -- add pros/cons after status):
```typescript
export const threadCandidates = sqliteTable("thread_candidates", {
id: integer("id").primaryKey({ autoIncrement: true }),
threadId: integer("thread_id").notNull().references(() => threads.id, { onDelete: "cascade" }),
name: text("name").notNull(),
weightGrams: real("weight_grams"),
priceCents: integer("price_cents"),
categoryId: integer("category_id").notNull().references(() => categories.id),
notes: text("notes"),
productUrl: text("product_url"),
imageFilename: text("image_filename"),
status: text("status").notNull().default("researching"),
// ADD: pros: text("pros"),
// ADD: cons: text("cons"),
createdAt: integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => new Date()),
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull().$defaultFn(() => new Date()),
});
```
From src/shared/schemas.ts (createCandidateSchema -- add optional pros/cons):
```typescript
export const createCandidateSchema = z.object({
name: z.string().min(1, "Name is required"),
weightGrams: z.number().nonnegative().optional(),
priceCents: z.number().int().nonnegative().optional(),
categoryId: z.number().int().positive(),
notes: z.string().optional(),
productUrl: z.string().url().optional().or(z.literal("")),
imageFilename: z.string().optional(),
status: candidateStatusSchema.optional(),
});
// updateCandidateSchema = createCandidateSchema.partial() -- inherits automatically
```
From src/server/services/thread.service.ts:
```typescript
// createCandidate: values() object needs pros/cons
// updateCandidate: inline Partial<{...}> type needs pros/cons
// getThreadWithCandidates: explicit .select({}) projection needs pros/cons
```
From src/client/hooks/useCandidates.ts:
```typescript
interface CandidateResponse {
id: number; threadId: number; name: string;
weightGrams: number | null; priceCents: number | null;
categoryId: number; notes: string | null;
productUrl: string | null; imageFilename: string | null;
status: "researching" | "ordered" | "arrived";
createdAt: string; updatedAt: string;
// ADD: pros: string | null;
// ADD: cons: string | null;
}
```
From src/client/components/CandidateCard.tsx:
```typescript
interface CandidateCardProps {
id: number; name: string; weightGrams: number | null;
priceCents: number | null; categoryName: string;
categoryIcon: string; imageFilename: string | null;
productUrl?: string | null; threadId: number;
isActive: boolean;
status: "researching" | "ordered" | "arrived";
onStatusChange: (status: "researching" | "ordered" | "arrived") => void;
// ADD: pros?: string | null;
// ADD: cons?: string | null;
}
```
From src/client/components/CandidateForm.tsx:
```typescript
interface FormData {
name: string; weightGrams: string; priceDollars: string;
categoryId: number; notes: string; productUrl: string;
imageFilename: string | null;
// ADD: pros: string;
// ADD: cons: string;
}
```
</interfaces>
</context>
<tasks>
<task type="auto" tdd="true">
<name>Task 1: Add pros/cons columns through backend + tests</name>
<files>src/db/schema.ts, tests/helpers/db.ts, src/server/services/thread.service.ts, src/shared/schemas.ts, tests/services/thread.service.test.ts</files>
<behavior>
- createCandidate with pros/cons returns them in the response
- createCandidate without pros/cons returns null for both fields
- updateCandidate can set pros and cons on an existing candidate
- updateCandidate can clear pros/cons by setting to empty string (becomes null via service)
- getThreadWithCandidates includes pros and cons on each candidate object
- All existing thread service tests still pass (no column drift)
</behavior>
<action>
1. **Schema** (`src/db/schema.ts`): Add two nullable TEXT columns to `threadCandidates` after `status`:
```typescript
pros: text("pros"),
cons: text("cons"),
```
2. **Migration**: Run `bun run db:generate` to produce the ALTER TABLE migration, then `bun run db:push` to apply.
3. **Test helper** (`tests/helpers/db.ts`): Add `pros TEXT,` and `cons TEXT,` to the `CREATE TABLE thread_candidates` statement, between the `status` line and the `created_at` line. This is CRITICAL -- without it, in-memory test DBs will silently lack the columns.
4. **Service** (`src/server/services/thread.service.ts`):
- `createCandidate`: Add `pros: data.pros ?? null,` and `cons: data.cons ?? null,` to the `.values({})` object.
- `updateCandidate`: Add `pros: string;` and `cons: string;` to the inline `Partial<{...}>` type parameter.
- `getThreadWithCandidates`: Add `pros: threadCandidates.pros,` and `cons: threadCandidates.cons,` to the explicit `.select({})` projection, before the `categoryName` line.
5. **Zod schemas** (`src/shared/schemas.ts`): Add to `createCandidateSchema`:
```typescript
pros: z.string().optional(),
cons: z.string().optional(),
```
`updateCandidateSchema` inherits via `.partial()` -- no changes needed there.
6. **Tests** (`tests/services/thread.service.test.ts`): Add three test cases:
- In `describe("createCandidate")`: "stores and returns pros and cons" -- create a candidate with `pros: "Lightweight\nGood reviews"` and `cons: "Expensive"`, assert both fields are returned correctly.
- In `describe("updateCandidate")`: "can set and clear pros and cons" -- create a candidate, update with pros/cons values, assert they are set, then update with empty strings, assert they are cleared (returned as empty string or null from DB).
- In `describe("getThreadWithCandidates")`: "includes pros and cons on each candidate" -- create a candidate with pros/cons, fetch via getThreadWithCandidates, assert `candidate.pros` and `candidate.cons` match.
</action>
<verify>
<automated>cd /home/jlmak/Projects/jlmak/GearBox && bun test tests/services/thread.service.test.ts</automated>
</verify>
<done>
- pros and cons columns exist in schema.ts and test helper
- Drizzle migration generated and applied
- createCandidate, updateCandidate, getThreadWithCandidates all handle pros/cons
- Zod schemas accept optional pros/cons strings
- All existing + new thread service tests pass
</done>
</task>
<task type="auto">
<name>Task 2: Wire pros/cons through client hooks, form, and card indicator</name>
<files>src/client/hooks/useCandidates.ts, src/client/components/CandidateForm.tsx, src/client/components/CandidateCard.tsx, src/client/routes/threads/$threadId.tsx</files>
<action>
1. **Hook** (`src/client/hooks/useCandidates.ts`): Add to `CandidateResponse` interface:
```typescript
pros: string | null;
cons: string | null;
```
2. **CandidateForm** (`src/client/components/CandidateForm.tsx`):
- Add `pros: string;` and `cons: string;` to `FormData` interface.
- Add `pros: "",` and `cons: "",` to `INITIAL_FORM`.
- In the `useEffect` pre-fill block, add: `pros: candidate.pros ?? "",` and `cons: candidate.cons ?? "",`.
- In `handleSubmit` payload, add: `pros: form.pros.trim() || undefined,` and `cons: form.cons.trim() || undefined,`.
- Add two textarea elements in the form, AFTER the Notes textarea and BEFORE the Product Link input. Each should follow the exact same pattern as the Notes textarea:
- **Pros**: label "Pros", id `candidate-pros`, placeholder "One pro per line...", rows={3}
- **Cons**: label "Cons", id `candidate-cons`, placeholder "One con per line...", rows={3}
- Use identical Tailwind classes as the existing Notes textarea.
3. **CandidateCard** (`src/client/components/CandidateCard.tsx`):
- Add `pros?: string | null;` and `cons?: string | null;` to `CandidateCardProps` interface.
- Destructure `pros` and `cons` in the component function parameters.
- Add a visual indicator badge in the `flex flex-wrap gap-1.5` div, after the StatusBadge. When `(pros || cons)` is truthy, render:
```tsx
{(pros || cons) && (
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-purple-50 text-purple-700">
+/- Notes
</span>
)}
```
4. **Thread detail route** (`src/client/routes/threads/$threadId.tsx`): Pass `pros` and `cons` props to the `<CandidateCard>` component in the candidates map:
```tsx
pros={candidate.pros}
cons={candidate.cons}
```
5. Run `bun run lint` to verify Biome compliance (tabs, double quotes, organized imports).
</action>
<verify>
<automated>cd /home/jlmak/Projects/jlmak/GearBox && bun test && bun run lint</automated>
</verify>
<done>
- CandidateResponse includes pros/cons fields
- CandidateForm shows Pros and Cons textareas, pre-fills in edit mode, sends in payload
- CandidateCard shows purple "+/- Notes" badge when pros or cons text exists
- Thread detail page threads pros/cons props to CandidateCard
- Full test suite passes, lint passes
</done>
</task>
</tasks>
<verification>
1. `bun test` -- full suite green (existing + new tests)
2. `bun run lint` -- no Biome violations
3. Manual: create a thread, add a candidate with pros and cons text, verify:
- Pros/cons fields appear in the edit form
- Saved text persists after page refresh
- CandidateCard shows the "+/- Notes" indicator badge
- A candidate without pros/cons does NOT show the badge
</verification>
<success_criteria>
- RANK-03 fully implemented: pros/cons fields on candidates, editable via form, persisted, with visual indicator
- Zero test regressions
- No column drift between schema.ts and test helper
</success_criteria>
<output>
After completion, create `.planning/phases/10-schema-foundation-pros-cons-fields/10-01-SUMMARY.md`
</output>

View File

@@ -0,0 +1,130 @@
---
phase: 10-schema-foundation-pros-cons-fields
plan: "01"
subsystem: database
tags: [drizzle, sqlite, react, forms, zod]
# Dependency graph
requires: []
provides:
- "pros/cons nullable TEXT columns on thread_candidates table (DB + migration)"
- "Zod schema fields: pros/cons optional strings in createCandidateSchema"
- "Service layer: createCandidate, updateCandidate, getThreadWithCandidates handle pros/cons"
- "Client CandidateForm: Pros and Cons textarea inputs with pre-fill and submit payload"
- "Client CandidateCard: purple +/- Notes badge when pros or cons text exists"
- "CandidateResponse type includes pros/cons fields"
affects: [thread-ranking, candidate-comparison, future-candidate-features]
# Tech tracking
tech-stack:
added: []
patterns: [field-addition-ladder, tdd-red-green]
key-files:
created:
- drizzle/0004_soft_synch.sql
modified:
- src/db/schema.ts
- tests/helpers/db.ts
- src/server/services/thread.service.ts
- src/shared/schemas.ts
- src/client/hooks/useCandidates.ts
- src/client/components/CandidateForm.tsx
- src/client/components/CandidateCard.tsx
- src/client/routes/threads/$threadId.tsx
- tests/services/thread.service.test.ts
key-decisions:
- "Empty string for pros/cons stored as-is by SQLite (not normalized to null) — updateCandidate test accepts empty string or null as cleared state"
- "Pros/Cons textareas placed after Notes and before Product Link — logical grouping for research annotation"
- "Visual indicator uses purple color scheme to distinguish from weight (blue), price (green), category (gray), and status badges"
patterns-established:
- "Field-addition ladder: schema -> migration -> test helper -> service -> Zod -> types -> hook -> form -> card indicator"
- "Test helper CREATE TABLE must mirror schema.ts columns exactly — column drift causes silent test failures"
- "TDD: RED commit (failing tests) -> GREEN commit (implementation) per task"
requirements-completed: [RANK-03]
# Metrics
duration: 6min
completed: "2026-03-16"
---
# Phase 10 Plan 01: Schema Foundation Pros/Cons Fields Summary
**Nullable pros/cons TEXT columns added to thread_candidates from SQLite schema through Drizzle migration, service layer, Zod validation, React form inputs, and CandidateCard visual badge**
## Performance
- **Duration:** 6 min
- **Started:** 2026-03-16T20:30:18Z
- **Completed:** 2026-03-16T20:36:25Z
- **Tasks:** 2
- **Files modified:** 9
## Accomplishments
- Added pros/cons columns to threadCandidates schema and applied Drizzle migration (0004_soft_synch.sql)
- Wired pros/cons through all backend layers: service create/update/get + Zod schemas
- Added Pros and Cons textarea inputs to CandidateForm with pre-fill in edit mode
- Added purple "+/- Notes" badge to CandidateCard when either field has content
- 28 thread service tests passing (24 existing + 4 new) with zero regressions
## Task Commits
Each task was committed atomically:
1. **TDD RED - failing tests** - `719f708` (test)
2. **Task 1: Add pros/cons columns through backend + tests** - `7a64a18` (feat)
3. **Task 2: Wire pros/cons through client hooks, form, and card indicator** - `4f2aefe` (feat)
_Note: TDD task has separate test commit (RED) and implementation commit (GREEN)_
## Files Created/Modified
- `src/db/schema.ts` - Added pros/cons nullable TEXT columns to threadCandidates
- `drizzle/0004_soft_synch.sql` - Migration: ALTER TABLE thread_candidates ADD COLUMN pros/cons
- `tests/helpers/db.ts` - Mirrored pros/cons in CREATE TABLE thread_candidates
- `src/server/services/thread.service.ts` - pros/cons in createCandidate values(), updateCandidate Partial type, getThreadWithCandidates select
- `src/shared/schemas.ts` - pros/cons optional string fields in createCandidateSchema (updateCandidateSchema inherits via .partial())
- `src/client/hooks/useCandidates.ts` - pros/cons added to CandidateResponse interface
- `src/client/components/CandidateForm.tsx` - Pros and Cons textareas, FormData fields, INITIAL_FORM, pre-fill, payload
- `src/client/components/CandidateCard.tsx` - props, destructuring, purple +/- Notes badge
- `src/client/routes/threads/$threadId.tsx` - pros={candidate.pros} cons={candidate.cons} passed to CandidateCard
- `tests/services/thread.service.test.ts` - 4 new test cases for pros/cons create/update/get
## Decisions Made
- Empty string for pros/cons is stored as-is (not normalized to null on empty); the test accepts either empty string or null as "cleared" state since SQLite/Drizzle does not coerce empty strings.
- Visual indicator uses purple to distinguish from existing badge color scheme (blue=weight, green=price, gray=category, status has its own colors).
- Textarea placement (after Notes, before Product Link) groups annotation fields logically.
## Deviations from Plan
None - plan executed exactly as written.
## Issues Encountered
Pre-existing lint violations discovered in files outside the plan scope:
- `src/client/components/WeightSummaryCard.tsx`, `src/client/routes/collection/index.tsx`, `src/client/routes/index.tsx`, `src/client/routes/setups/$setupId.tsx` — format/organizeImports errors
- `.obsidian/workspace.json` — Biome format error (IDE file, should be excluded)
These are logged to `deferred-items.md` and not fixed (out of scope per deviation scope boundary rule).
## User Setup Required
None - no external service configuration required.
## Next Phase Readiness
- RANK-03 fully implemented: pros/cons fields on candidates, editable via form, persisted in SQLite, with visual badge indicator
- Schema foundation complete — subsequent plans in phase 10 can build ranking/sorting features on top of this data
- No blockers
---
*Phase: 10-schema-foundation-pros-cons-fields*
*Completed: 2026-03-16*
## Self-Check: PASSED
All files and commits verified:
- All 10 key files present on disk
- All 3 task commits found in git log (719f708, 7a64a18, 4f2aefe)
- Key artifact strings confirmed in each file (pros: text, pros TEXT, pros: z.string, candidate-pros, pros || cons)

View File

@@ -0,0 +1,417 @@
# Phase 10: Schema Foundation + Pros/Cons Fields - Research
**Researched:** 2026-03-16
**Domain:** Drizzle ORM schema migration + full-stack field addition (SQLite / Hono / React)
**Confidence:** HIGH
---
<phase_requirements>
## Phase Requirements
| ID | Description | Research Support |
|----|-------------|-----------------|
| RANK-03 | User can add pros and cons text per candidate displayed as bullet lists | Confirmed: two nullable TEXT columns on `thread_candidates` + textarea inputs in `CandidateForm` + visual indicator on `CandidateCard` |
</phase_requirements>
---
## Summary
Phase 10 is a contained, top-to-bottom field-addition task. Two nullable `TEXT` columns (`pros`, `cons`) must be added to the `thread_candidates` table, propagated through every layer that touches that table, and surfaced in the UI as editable text areas with a card-level presence indicator.
The project uses Drizzle ORM with SQLite. Adding nullable columns via `ALTER TABLE … ADD COLUMN` is safe in SQLite (no default value is required for nullable TEXT). The Drizzle workflow is: edit `schema.ts``bun run db:generate``bun run db:push`. The generated SQL migration follows the established pattern already used four times in this project.
There is one mandatory non-obvious step documented in CLAUDE.md: the test helper at `tests/helpers/db.ts` contains a hardcoded `CREATE TABLE thread_candidates` statement that mirrors the production schema. It must be updated in lockstep with `schema.ts` or all existing candidate tests will silently omit the new columns and new service-level tests will fail.
**Primary recommendation:** Follow the exact field-addition ladder: schema → migration → test helper → service (insert + update + select projection) → Zod schemas → shared types → API route (zValidator) → React hook response type → CandidateForm → CandidateCard indicator. Every rung must be touched — skipping any one causes type drift or runtime failures.
---
## Standard Stack
### Core
| Library | Version | Purpose | Why Standard |
|---------|---------|---------|--------------|
| drizzle-orm | installed | ORM + migration generation | Project standard; all migrations use it |
| drizzle-kit | installed | CLI for `db:generate` | Project standard; configured in drizzle.config.ts |
| zod | installed | Schema validation on API boundary | Project standard; `@hono/zod-validator` integration |
| bun:sqlite | runtime built-in | In-memory test DB | Used by `createTestDb()` helper |
No new dependencies are required for this phase.
**Installation:**
```bash
# No new packages — all required libraries already installed
```
---
## Architecture Patterns
### Established Field-Addition Ladder
Every field addition in this codebase follows this exact sequence. Previous examples: `status` on candidates, `classification` on `setup_items`, `icon` on categories.
```
1. src/db/schema.ts — Drizzle column definition
2. drizzle/ (generated) — bun run db:generate
3. gearbox.db — bun run db:push
4. tests/helpers/db.ts — Raw SQL CREATE TABLE mirrored manually
5. src/server/services/thread.service.ts
a. createCandidate() — values() object
b. updateCandidate() — data type + set()
c. getThreadWithCandidates() — explicit column projection
6. src/shared/schemas.ts — createCandidateSchema + updateCandidateSchema
7. src/shared/types.ts — auto-inferred (no manual edit needed)
8. src/client/hooks/useCandidates.ts — CandidateResponse interface
9. src/client/components/CandidateForm.tsx — FormData + textarea inputs + payload
10. src/client/components/CandidateCard.tsx — visual indicator prop + render
```
### Pattern 1: Drizzle Nullable Text Column
**What:** Add an optional text field to an existing Drizzle table.
**When to use:** When the field is user-provided text, no business logic default applies.
```typescript
// Source: src/db/schema.ts — pattern already used by notes, productUrl, imageFilename
export const threadCandidates = sqliteTable("thread_candidates", {
// ... existing columns ...
pros: text("pros"), // nullable, no default — mirrors notes/productUrl pattern
cons: text("cons"), // nullable, no default
// ...
});
```
### Pattern 2: Test Helper Table Synchronization
**What:** Mirror every new column in the raw SQL inside `createTestDb()`.
**When to use:** Every time `schema.ts` is modified. Documented as mandatory in CLAUDE.md.
```typescript
// Source: tests/helpers/db.ts — existing thread_candidates CREATE TABLE
sqlite.run(`
CREATE TABLE thread_candidates (
id INTEGER PRIMARY KEY AUTOINCREMENT,
thread_id INTEGER NOT NULL REFERENCES threads(id) ON DELETE CASCADE,
name TEXT NOT NULL,
weight_grams REAL,
price_cents INTEGER,
category_id INTEGER NOT NULL REFERENCES categories(id),
notes TEXT,
product_url TEXT,
image_filename TEXT,
status TEXT NOT NULL DEFAULT 'researching',
pros TEXT, -- ADD THIS
cons TEXT, -- ADD THIS
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
)
`);
```
### Pattern 3: Explicit Select Projection in Service
**What:** `getThreadWithCandidates` uses an explicit `.select({...})` projection, not `select()`.
**When to use:** New columns MUST be explicitly added to the projection or they will not appear in query results.
```typescript
// Source: src/server/services/thread.service.ts — getThreadWithCandidates()
const candidateList = db
.select({
// ... existing fields ...
pros: threadCandidates.pros, // ADD
cons: threadCandidates.cons, // ADD
categoryName: categories.name,
categoryIcon: categories.icon,
})
.from(threadCandidates)
// ...
```
### Pattern 4: Zod Schema Extension
**What:** Add optional string fields to `createCandidateSchema`; `updateCandidateSchema` is derived via `.partial()` and picks them up automatically.
**When to use:** Any new candidate API field.
```typescript
// Source: src/shared/schemas.ts
export const createCandidateSchema = z.object({
name: z.string().min(1, "Name is required"),
// ... existing fields ...
pros: z.string().optional(), // ADD
cons: z.string().optional(), // ADD
});
// updateCandidateSchema = createCandidateSchema.partial() — inherits automatically
```
### Pattern 5: CandidateForm Textarea Addition
**What:** Extend `FormData` interface and `INITIAL_FORM` constant, add pre-fill in `useEffect`, add textarea elements, include in payload.
```typescript
// Source: src/client/components/CandidateForm.tsx — FormData interface
interface FormData {
// ... existing ...
pros: string; // ADD
cons: string; // ADD
}
const INITIAL_FORM: FormData = {
// ... existing ...
pros: "", // ADD
cons: "", // ADD
};
// In useEffect pre-fill:
pros: candidate.pros ?? "", // ADD
cons: candidate.cons ?? "", // ADD
// In payload construction:
pros: form.pros.trim() || undefined, // ADD
cons: form.cons.trim() || undefined, // ADD
```
### Pattern 6: CandidateCard Visual Indicator
**What:** Show a small badge when a candidate has pros or cons text. The requirement says "visual indicator when a candidate has pros or cons entered" — not a full display of the text (that is the form's job).
**When to use:** When `(pros || cons)` is truthy.
```tsx
// Source: src/client/components/CandidateCard.tsx — props interface
interface CandidateCardProps {
// ... existing ...
pros?: string | null; // ADD
cons?: string | null; // ADD
}
// In the card's badge section (alongside weight/price badges):
{(pros || cons) && (
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-purple-50 text-purple-500">
Notes
</span>
)}
```
The exact styling (color, icon, text) is left to the planner's discretion — the requirement only specifies "visual indicator."
### Anti-Patterns to Avoid
- **Forgetting the test helper**: If `tests/helpers/db.ts` is not updated, the in-memory schema won't have `pros`/`cons` columns. Tests that insert or read these fields will get `undefined` instead of the stored value, causing silent failures or column-not-found errors. CLAUDE.md documents this as a known hazard.
- **Using `select()` without explicit fields**: The `getThreadWithCandidates` service function already uses an explicit projection. Adding fields to the schema without adding them to the projection means the client never receives the data.
- **Storing pros/cons as a JSON array of bullet strings**: The requirement says "text per candidate displayed as bullet lists" — the display can parse newlines into bullets from a plain TEXT field. A single multi-line `TEXT` column is correct and consistent with the existing `notes` field pattern. No JSON, no separate table.
- **Adding a separate `candidatePros` / `candidateCons` table**: Massive over-engineering. These are simple annotations on a single candidate, not a many-per-candidate relationship.
---
## Don't Hand-Roll
| Problem | Don't Build | Use Instead | Why |
|---------|-------------|-------------|-----|
| Schema migration | Custom SQL scripts | `bun run db:generate` + `bun run db:push` | Drizzle-kit generates correct ALTER TABLE, tracks journal, handles snapshot |
| API input validation | Manual checks | Zod via `zValidator` (already wired) | All candidate routes already use `updateCandidateSchema` — just extend it |
| Bullet-list rendering | Custom tokenizer | CSS `whitespace-pre-line` or split on `\n` | Simple text with newlines is sufficient for RANK-03 |
---
## Common Pitfalls
### Pitfall 1: Test Helper Column Drift
**What goes wrong:** New columns exist in production schema but are absent from the hardcoded `CREATE TABLE` in `tests/helpers/db.ts`. Tests pass structurally but new-column values are lost.
**Why it happens:** The test helper duplicates the schema in raw SQL, not via Drizzle. There is no automated sync.
**How to avoid:** Update `tests/helpers/db.ts` immediately after editing `schema.ts`, in the same commit wave.
**Warning signs:** `candidate.pros` returns `undefined` in service tests even after saving a value.
### Pitfall 2: Missing Explicit Column in Select Projection
**What goes wrong:** `getThreadWithCandidates` uses `.select({ id: threadCandidates.id, ... })` — an explicit map. New columns are silently excluded.
**Why it happens:** Drizzle's explicit projection doesn't automatically include newly-added columns.
**How to avoid:** Search for every `.select({` that references `threadCandidates` and add `pros` and `cons`.
**Warning signs:** API returns candidate without `pros`/`cons` fields even though they're saved in DB.
### Pitfall 3: updateCandidate Service Type Mismatch
**What goes wrong:** `updateCandidate` in `thread.service.ts` has a hardcoded `Partial<{ name, weightGrams, ... }>` type rather than using the Zod-inferred type. New fields must be manually added to this inline type.
**Why it happens:** The function was written with an inline type, not `UpdateCandidate`.
**How to avoid:** Add `pros: string` and `cons: string` to the `Partial<{...}>` inline type in `updateCandidate`.
**Warning signs:** TypeScript error when trying to set `pros`/`cons` in the `.set({...data})` call.
### Pitfall 4: CandidateCard Prop Not Threaded Through Call Sites
**What goes wrong:** `CandidateCard` receives new `pros`/`cons` props, but the parent component (the thread detail page / candidate list) doesn't pass them.
**Why it happens:** Adding props to a component doesn't update callers.
**How to avoid:** Search for all `<CandidateCard` usages and add the new prop.
**Warning signs:** Indicator never shows even when pros/cons data is present.
---
## Code Examples
### Migration SQL (Generated Output Shape)
```sql
-- Expected output of bun run db:generate
-- drizzle/000X_<tag>.sql
ALTER TABLE `thread_candidates` ADD `pros` text;
ALTER TABLE `thread_candidates` ADD `cons` text;
```
SQLite supports `ADD COLUMN` for nullable columns without a default. Confirmed by existing migration pattern (`0003_misty_mongu.sql` uses `ALTER TABLE setup_items ADD classification text DEFAULT 'base' NOT NULL`).
### Service: createCandidate Values
```typescript
// Source: src/server/services/thread.service.ts
return db
.insert(threadCandidates)
.values({
threadId,
name: data.name,
// ... existing fields ...
pros: data.pros ?? null, // ADD
cons: data.cons ?? null, // ADD
})
.returning()
.get();
```
### Service: updateCandidate Inline Type
```typescript
// Source: src/server/services/thread.service.ts
export function updateCandidate(
db: Db = prodDb,
candidateId: number,
data: Partial<{
name: string;
weightGrams: number;
priceCents: number;
categoryId: number;
notes: string;
productUrl: string;
imageFilename: string;
status: "researching" | "ordered" | "arrived";
pros: string; // ADD
cons: string; // ADD
}>,
) { ... }
```
### Hook: CandidateResponse Interface
```typescript
// Source: src/client/hooks/useCandidates.ts
interface CandidateResponse {
id: number;
// ... existing ...
pros: string | null; // ADD
cons: string | null; // ADD
}
```
---
## State of the Art
| Old Approach | Current Approach | Notes |
|--------------|------------------|-------|
| Manual SQL migrations | Drizzle-kit generate + push | Already established — 4 migrations in project |
| `notes` as freeform text | `pros`/`cons` as separate nullable TEXT columns | Matches how existing `notes` field works; no special type |
**Not applicable in this phase:**
- No new libraries
- No breaking API changes (all new fields are optional)
- Existing candidates will have `pros = null` and `cons = null` after migration — no backfill needed
---
## Open Questions
1. **Bullet list rendering in CandidateCard**
- What we know: RANK-03 says "displayed as bullet lists"
- What's unclear: The card currently shows the pros/cons indicator; does the card need to render the actual bullets, or does that happen elsewhere (e.g., a tooltip, expanded state, or comparison view in Phase 12)?
- Recommendation: Phase 10 success criteria only requires "visual indicator when a candidate has pros or cons entered." Full bullet rendering can be deferred to Phase 12 (Comparison View) or Phase 11. The form's edit view can display raw textarea text.
2. **Maximum text length**
- What we know: SQLite TEXT has no practical length limit; the existing `notes` field has no validation constraint
- What's unclear: Should pros/cons have a max length?
- Recommendation: Omit length constraint to stay consistent with the `notes` field. Add if user feedback indicates issues.
---
## Validation Architecture
`workflow.nyquist_validation` is `true` in `.planning/config.json`.
### Test Framework
| Property | Value |
|----------|-------|
| Framework | Bun test runner (built-in) |
| Config file | None — `bun test` discovers `tests/**/*.test.ts` |
| Quick run command | `bun test tests/services/thread.service.test.ts` |
| Full suite command | `bun test` |
### Phase Requirements → Test Map
| Req ID | Behavior | Test Type | Automated Command | File Exists? |
|--------|----------|-----------|-------------------|-------------|
| RANK-03 | `createCandidate` stores pros/cons and returns them | unit | `bun test tests/services/thread.service.test.ts` | Extend existing |
| RANK-03 | `updateCandidate` can set/clear pros and cons | unit | `bun test tests/services/thread.service.test.ts` | Extend existing |
| RANK-03 | `getThreadWithCandidates` returns pros/cons on each candidate | unit | `bun test tests/services/thread.service.test.ts` | Extend existing |
| RANK-03 | `PUT /api/threads/:id/candidates/:id` accepts pros/cons in body | route | `bun test tests/routes/threads.test.ts` | Extend existing |
| RANK-03 | All existing tests pass (no column drift) | regression | `bun test` | Existing ✅ |
### Sampling Rate
- **Per task commit:** `bun test tests/services/thread.service.test.ts`
- **Per wave merge:** `bun test`
- **Phase gate:** Full suite green before `/gsd:verify-work`
### Wave 0 Gaps
No new test files need to be created. All tests are extensions of existing files:
- `tests/services/thread.service.test.ts` — add `pros`/`cons` test cases to existing `describe("createCandidate")` and `describe("updateCandidate")` blocks
- `tests/routes/threads.test.ts` — add a test case to existing `PUT` candidate describe block
None — existing test infrastructure covers all phase requirements (as extensions).
---
## Sources
### Primary (HIGH confidence)
- Direct code inspection: `src/db/schema.ts` — current `threadCandidates` column layout
- Direct code inspection: `tests/helpers/db.ts``CREATE TABLE thread_candidates` raw SQL
- Direct code inspection: `src/server/services/thread.service.ts``createCandidate`, `updateCandidate`, `getThreadWithCandidates`
- Direct code inspection: `src/shared/schemas.ts``createCandidateSchema`, `updateCandidateSchema`
- Direct code inspection: `src/client/components/CandidateForm.tsx` — form structure and payload
- Direct code inspection: `src/client/components/CandidateCard.tsx` — props interface and badge rendering
- Direct code inspection: `src/client/hooks/useCandidates.ts``CandidateResponse` interface
- Direct code inspection: `drizzle/0003_misty_mongu.sql` — ALTER TABLE migration pattern
- Direct code inspection: `CLAUDE.md` — explicit test-helper sync requirement
### Secondary (MEDIUM confidence)
- SQLite docs: `ALTER TABLE … ADD COLUMN` supports nullable columns without default — verified by existing migration pattern in project
### Tertiary (LOW confidence)
- None
---
## Metadata
**Confidence breakdown:**
- Standard stack: HIGH — no new libraries; all tooling already in use
- Architecture: HIGH — full codebase read confirms exact ladder; no ambiguity
- Pitfalls: HIGH — CLAUDE.md explicitly calls out test helper drift; column projection issue confirmed by reading service code
**Research date:** 2026-03-16
**Valid until:** 2026-06-16 (stable stack — 90 days)

View File

@@ -0,0 +1,78 @@
---
phase: 10
slug: schema-foundation-pros-cons-fields
status: draft
nyquist_compliant: false
wave_0_complete: false
created: 2026-03-16
---
# Phase 10 — Validation Strategy
> Per-phase validation contract for feedback sampling during execution.
---
## Test Infrastructure
| Property | Value |
|----------|-------|
| **Framework** | Bun test runner (built-in) |
| **Config file** | none — `bun test` discovers `tests/**/*.test.ts` |
| **Quick run command** | `bun test tests/services/thread.service.test.ts` |
| **Full suite command** | `bun test` |
| **Estimated runtime** | ~5 seconds |
---
## Sampling Rate
- **After every task commit:** Run `bun test tests/services/thread.service.test.ts`
- **After every plan wave:** Run `bun test`
- **Before `/gsd:verify-work`:** Full suite must be green
- **Max feedback latency:** 5 seconds
---
## Per-Task Verification Map
| Task ID | Plan | Wave | Requirement | Test Type | Automated Command | File Exists | Status |
|---------|------|------|-------------|-----------|-------------------|-------------|--------|
| 10-01-01 | 01 | 1 | RANK-03 | unit | `bun test tests/services/thread.service.test.ts` | Extend existing | ⬜ pending |
| 10-01-02 | 01 | 1 | RANK-03 | unit | `bun test tests/services/thread.service.test.ts` | Extend existing | ⬜ pending |
| 10-01-03 | 01 | 1 | RANK-03 | unit | `bun test tests/services/thread.service.test.ts` | Extend existing | ⬜ pending |
| 10-01-04 | 01 | 1 | RANK-03 | route | `bun test tests/routes/threads.test.ts` | Extend existing | ⬜ pending |
| 10-01-05 | 01 | 1 | RANK-03 | regression | `bun test` | Existing ✅ | ⬜ pending |
*Status: ⬜ pending · ✅ green · ❌ red · ⚠️ flaky*
---
## Wave 0 Requirements
Existing infrastructure covers all phase requirements. All tests are extensions of existing files:
- `tests/services/thread.service.test.ts` — add `pros`/`cons` test cases to existing describe blocks
- `tests/routes/threads.test.ts` — add test case to existing PUT candidate describe block
*No new test files or framework installs required.*
---
## Manual-Only Verifications
| Behavior | Requirement | Why Manual | Test Instructions |
|----------|-------------|------------|-------------------|
| CandidateCard shows visual indicator when pros/cons present | RANK-03 | UI rendering verification | 1. Create thread with candidate 2. Add pros text 3. Verify indicator badge appears on card |
---
## Validation Sign-Off
- [ ] All tasks have `<automated>` verify or Wave 0 dependencies
- [ ] Sampling continuity: no 3 consecutive tasks without automated verify
- [ ] Wave 0 covers all MISSING references
- [ ] No watch-mode flags
- [ ] Feedback latency < 5s
- [ ] `nyquist_compliant: true` set in frontmatter
**Approval:** pending

View File

@@ -0,0 +1,104 @@
---
phase: 10-schema-foundation-pros-cons-fields
verified: 2026-03-16T21:00:00Z
status: passed
score: 4/4 must-haves verified
re_verification: false
---
# Phase 10: Schema Foundation Pros/Cons Fields Verification Report
**Phase Goal:** Candidates can be annotated with pros and cons, and the database is ready for ranking
**Verified:** 2026-03-16T21:00:00Z
**Status:** passed
**Re-verification:** No — initial verification
## Goal Achievement
### Observable Truths
| # | Truth | Status | Evidence |
| --- | ----------------------------------------------------------------------------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| 1 | User can open a candidate edit form and see pros and cons text fields | VERIFIED | `CandidateForm.tsx` lines 250-284: two textarea elements with `id="candidate-pros"` and `id="candidate-cons"`, pre-filled via `candidate.pros ?? ""` in edit useEffect |
| 2 | User can save pros and cons text; the text persists across page refreshes | VERIFIED | Form payload sends `pros: form.pros.trim() || undefined` to API; service stores `data.pros ?? null` in SQLite; migration `0004_soft_synch.sql` adds columns to live DB |
| 3 | CandidateCard shows a visual indicator when a candidate has pros or cons entered | VERIFIED | `CandidateCard.tsx` line 181-185: `{(pros || cons) && <span ...bg-purple-50 text-purple-700...>+/- Notes</span>}` renders conditionally |
| 4 | All existing tests pass after the schema migration (no column drift in test helper) | VERIFIED | `bun test tests/services/thread.service.test.ts` — 28 pass, 0 fail; test helper mirrors `pros TEXT, cons TEXT` columns at lines 58-59 |
**Score:** 4/4 truths verified
---
### Required Artifacts
| Artifact | Expected | Status | Details |
| ---------------------------------------------------- | ------------------------------------------------------------------ | -------- | --------------------------------------------------------------------------------------------------------- |
| `src/db/schema.ts` | pros and cons nullable TEXT columns on threadCandidates | VERIFIED | Lines 62-63: `pros: text("pros"),` and `cons: text("cons"),` present after `status` column |
| `tests/helpers/db.ts` | Mirrored pros/cons columns in test DB CREATE TABLE | VERIFIED | Lines 58-59: `pros TEXT,` and `cons TEXT,` present in `CREATE TABLE thread_candidates` |
| `src/server/services/thread.service.ts` | pros/cons in createCandidate, updateCandidate, getThreadWithCandidates | VERIFIED | createCandidate lines 156-157; updateCandidate Partial type lines 175-176; getThreadWithCandidates select lines 76-77 |
| `src/shared/schemas.ts` | pros and cons optional string fields in createCandidateSchema | VERIFIED | Lines 56-57: `pros: z.string().optional(),` and `cons: z.string().optional(),`; updateCandidateSchema inherits via `.partial()` |
| `src/client/components/CandidateForm.tsx` | Pros and Cons textarea inputs in candidate form | VERIFIED | Lines 250-284: two labeled textareas with ids `candidate-pros` and `candidate-cons`; FormData interface lines 22-23; INITIAL_FORM lines 34-35; pre-fill lines 68-69; payload lines 119-120 |
| `src/client/components/CandidateCard.tsx` | Visual indicator badge when pros or cons are present | VERIFIED | Props interface lines 21-22: `pros?: string | null; cons?: string | null;`; destructured at line 38-39; badge at lines 181-185 using `bg-purple-50 text-purple-700` |
| `tests/services/thread.service.test.ts` | Tests for pros/cons in create, update, and get operations | VERIFIED | 4 new test cases: "stores and returns pros and cons" (line 152), "returns null for pros and cons when not provided" (line 165), "can set and clear pros and cons" (line 200), "includes pros and cons on each candidate" (line 113) |
---
### Key Link Verification
| From | To | Via | Status | Details |
| ----------------------------------- | -------------------------------------- | --------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------- |
| `src/db/schema.ts` | `tests/helpers/db.ts` | Manual column mirroring in CREATE TABLE | VERIFIED | `pros TEXT` and `cons TEXT` present in both locations; test helper lines 58-59 match schema lines 62-63 |
| `src/shared/schemas.ts` | `src/server/services/thread.service.ts` | Zod-inferred CreateCandidate type used in service | VERIFIED | Service imports `CreateCandidate` from `../../shared/types.ts` (line 9); `pros` and `cons` flow through the type into `createCandidate` and `updateCandidate` |
| `src/server/services/thread.service.ts` | `src/client/hooks/useCandidates.ts` | API JSON response includes pros/cons fields | VERIFIED | `getThreadWithCandidates` select projection explicitly includes `pros: threadCandidates.pros` and `cons: threadCandidates.cons`; `CandidateResponse` interface in hook declares `pros: string | null; cons: string | null;` |
| `src/client/hooks/useCandidates.ts` | `src/client/components/CandidateForm.tsx` | CandidateResponse type drives form pre-fill | VERIFIED | `CandidateForm.tsx` uses `useThread` which returns candidates; pre-fill useEffect accesses `candidate.pros` and `candidate.cons` at lines 68-69 |
| `src/client/routes/threads/$threadId.tsx` | `src/client/components/CandidateCard.tsx` | Props threaded from candidate data to card | VERIFIED | Lines 156-157 in thread route: `pros={candidate.pros}` and `cons={candidate.cons}` passed to `<CandidateCard>` |
---
### Requirements Coverage
| Requirement | Source Plan | Description | Status | Evidence |
| ----------- | ----------- | ----------------------------------------------------------------- | --------- | --------------------------------------------------------------------------------------------------------------------- |
| RANK-03 | 10-01-PLAN | User can add pros and cons text per candidate displayed as bullet lists | SATISFIED | Pros/cons fields wired end-to-end: DB columns, migration, service, Zod schema, React form textareas, CandidateCard badge. REQUIREMENTS.md marks it `[x]` at line 21. |
Note: The requirement description says "displayed as bullet lists" — the form stores multi-line text and the card shows a "+/- Notes" badge indicator. The text is stored as-is (one entry per line convention per plan instructions) but is not rendered as an explicit `<ul>` bullet list. This is a visual rendering concern suitable for human verification, but the data model and edit UI fully support it.
**Orphaned requirements check:** REQUIREMENTS.md traceability table maps only RANK-03 to Phase 10. No additional requirements are assigned to this phase. No orphaned requirements.
---
### Anti-Patterns Found
| File | Line | Pattern | Severity | Impact |
| ---- | ---- | ------- | -------- | ------ |
| None detected | — | — | — | — |
Scanned all 9 modified files for TODO/FIXME/placeholder comments, empty implementations, and console.log-only handlers. None found. The `pros: form.pros.trim() || undefined` pattern in `handleSubmit` correctly sends `undefined` (omitting the field) when empty, allowing the server to store `null` — this is intentional, not a stub.
---
### Human Verification Required
#### 1. Pros/Cons Text Renders Usably in Edit Form
**Test:** Open a thread, click "Add Candidate", observe the form. Scroll past Notes field — two textareas labeled "Pros" and "Cons" with placeholder "One pro per line..." and "One con per line..." should appear. Enter multi-line text in each, save, re-open the candidate, and confirm text pre-fills correctly.
**Expected:** Text persists across saves and page refreshes; form pre-fills with saved content in edit mode.
**Why human:** Requires a running browser with API connectivity to confirm round-trip persistence.
#### 2. CandidateCard Badge Visibility
**Test:** With a candidate that has pros or cons text, view the thread candidate grid. The card should show a purple "+/- Notes" badge alongside weight/price/status badges. A candidate without pros or cons should NOT show the badge.
**Expected:** Badge appears conditionally; absent when both fields are null/empty.
**Why human:** Requires browser rendering to verify visual appearance and conditional display.
---
### Gaps Summary
No gaps found. All four observable truths are fully verified. Every artifact exists, is substantive (not a stub), and is properly wired end-to-end. The database migration (`drizzle/0004_soft_synch.sql`) is present and correct. All 28 service tests pass (24 pre-existing + 4 new). The three task commits (719f708, 7a64a18, 4f2aefe) are confirmed in the git log.
RANK-03 is satisfied: pros and cons fields exist in the database, flow through the service layer with full CRUD support, are accepted by Zod validation, are exposed in the API response type, are editable via textarea inputs in `CandidateForm`, pre-fill correctly in edit mode, are sent in the submit payload, and surface as a purple "+/- Notes" visual indicator on `CandidateCard` when either field has content.
---
_Verified: 2026-03-16T21:00:00Z_
_Verifier: Claude (gsd-verifier)_

View File

@@ -0,0 +1,13 @@
# Deferred Items
## Pre-existing Lint Violations (Out of Scope for 10-01)
These Biome lint/format errors existed before phase 10-01 and are not caused by any changes in this plan. They should be addressed in a separate cleanup task.
- `src/client/components/WeightSummaryCard.tsx` - format violation (line length)
- `src/client/routes/collection/index.tsx` - organizeImports, format violations
- `src/client/routes/index.tsx` - organizeImports, format violations
- `src/client/routes/setups/$setupId.tsx` - organizeImports violations
- `.obsidian/workspace.json` - format violations (IDE file, should be excluded from Biome)
Discovered during: Task 2 lint verification

View File

@@ -0,0 +1,285 @@
---
phase: 11-candidate-ranking
plan: "01"
type: execute
wave: 1
depends_on: []
files_modified:
- src/db/schema.ts
- tests/helpers/db.ts
- src/server/services/thread.service.ts
- src/server/routes/threads.ts
- src/shared/schemas.ts
- src/shared/types.ts
- tests/services/thread.service.test.ts
- tests/routes/threads.test.ts
autonomous: true
requirements: [RANK-01, RANK-04, RANK-05]
must_haves:
truths:
- "Candidates returned from getThreadWithCandidates are ordered by sort_order ascending"
- "Calling reorderCandidates with a new ID sequence updates sort_order values to match that sequence"
- "PATCH /api/threads/:id/candidates/reorder returns 200 and persists new order"
- "reorderCandidates returns error when thread status is not active"
- "New candidates created via createCandidate are appended to end of rank (highest sort_order + 1000)"
artifacts:
- path: "src/db/schema.ts"
provides: "sortOrder REAL column on threadCandidates"
contains: "sortOrder"
- path: "src/shared/schemas.ts"
provides: "reorderCandidatesSchema Zod validator"
contains: "reorderCandidatesSchema"
- path: "src/shared/types.ts"
provides: "ReorderCandidates type"
contains: "ReorderCandidates"
- path: "src/server/services/thread.service.ts"
provides: "reorderCandidates function + ORDER BY sort_order + createCandidate sort_order appending"
exports: ["reorderCandidates"]
- path: "src/server/routes/threads.ts"
provides: "PATCH /:id/candidates/reorder endpoint"
contains: "candidates/reorder"
- path: "tests/helpers/db.ts"
provides: "sort_order column in CREATE TABLE thread_candidates"
contains: "sort_order"
key_links:
- from: "src/server/routes/threads.ts"
to: "src/server/services/thread.service.ts"
via: "reorderCandidates(db, threadId, orderedIds)"
pattern: "reorderCandidates"
- from: "src/server/routes/threads.ts"
to: "src/shared/schemas.ts"
via: "zValidator with reorderCandidatesSchema"
pattern: "reorderCandidatesSchema"
- from: "src/server/services/thread.service.ts"
to: "src/db/schema.ts"
via: "threadCandidates.sortOrder in ORDER BY and UPDATE"
pattern: "threadCandidates\\.sortOrder"
---
<objective>
Add sort_order column to thread_candidates, implement reorder service and API endpoint, and update candidate ordering throughout the backend.
Purpose: Provides the persistence layer for drag-to-reorder ranking (RANK-01, RANK-04) and enforces the resolved-thread guard (RANK-05). The frontend plan (11-02) depends on this.
Output: Working PATCH /api/threads/:id/candidates/reorder endpoint, sort_order-based ordering in getThreadWithCandidates, sort_order appending in createCandidate, full test coverage.
</objective>
<execution_context>
@/home/jlmak/.claude/get-shit-done/workflows/execute-plan.md
@/home/jlmak/.claude/get-shit-done/templates/summary.md
</execution_context>
<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/11-candidate-ranking/11-CONTEXT.md
@.planning/phases/11-candidate-ranking/11-RESEARCH.md
<interfaces>
<!-- Key types and contracts the executor needs. Extracted from codebase. -->
From src/db/schema.ts (threadCandidates table — add sortOrder here):
```typescript
export const threadCandidates = sqliteTable("thread_candidates", {
id: integer("id").primaryKey({ autoIncrement: true }),
threadId: integer("thread_id").notNull().references(() => threads.id, { onDelete: "cascade" }),
name: text("name").notNull(),
weightGrams: real("weight_grams"),
priceCents: integer("price_cents"),
categoryId: integer("category_id").notNull().references(() => categories.id),
notes: text("notes"),
productUrl: text("product_url"),
imageFilename: text("image_filename"),
status: text("status").notNull().default("researching"),
pros: text("pros"),
cons: text("cons"),
createdAt: integer("created_at", { mode: "timestamp" }).notNull().$defaultFn(() => new Date()),
updatedAt: integer("updated_at", { mode: "timestamp" }).notNull().$defaultFn(() => new Date()),
});
```
From src/server/services/thread.service.ts (key functions to modify):
```typescript
type Db = typeof prodDb;
export function getThreadWithCandidates(db: Db, threadId: number) // add .orderBy(threadCandidates.sortOrder)
export function createCandidate(db: Db, threadId: number, data: ...) // add sort_order = max + 1000
export function resolveThread(db: Db, threadId: number, candidateId: number) // existing status check pattern to reuse
```
From src/shared/schemas.ts (existing patterns):
```typescript
export const createCandidateSchema = z.object({ ... });
export const resolveThreadSchema = z.object({ candidateId: z.number().int().positive() });
```
From src/shared/types.ts (add new type):
```typescript
export type ResolveThread = z.infer<typeof resolveThreadSchema>;
// Add: export type ReorderCandidates = z.infer<typeof reorderCandidatesSchema>;
```
From src/server/routes/threads.ts (route pattern):
```typescript
type Env = { Variables: { db?: any } };
const app = new Hono<Env>();
// Pattern: app.post("/:id/resolve", zValidator("json", resolveThreadSchema), (c) => { ... });
```
From src/client/lib/api.ts:
```typescript
export async function apiPatch<T>(url: string, body: unknown): Promise<T>;
```
From tests/helpers/db.ts (thread_candidates CREATE TABLE — add sort_order):
```sql
CREATE TABLE thread_candidates (
id INTEGER PRIMARY KEY AUTOINCREMENT,
thread_id INTEGER NOT NULL REFERENCES threads(id) ON DELETE CASCADE,
name TEXT NOT NULL,
weight_grams REAL,
price_cents INTEGER,
category_id INTEGER NOT NULL REFERENCES categories(id),
notes TEXT,
product_url TEXT,
image_filename TEXT,
status TEXT NOT NULL DEFAULT 'researching',
pros TEXT,
cons TEXT,
created_at INTEGER NOT NULL DEFAULT (unixepoch()),
updated_at INTEGER NOT NULL DEFAULT (unixepoch())
)
```
</interfaces>
</context>
<tasks>
<task type="auto" tdd="true">
<name>Task 1: Schema, migration, service layer, and tests for sort_order + reorder</name>
<files>src/db/schema.ts, tests/helpers/db.ts, src/server/services/thread.service.ts, src/shared/schemas.ts, src/shared/types.ts, tests/services/thread.service.test.ts</files>
<behavior>
- Test: getThreadWithCandidates returns candidates ordered by sort_order ascending (create 3 candidates with different sort_orders, verify order)
- Test: reorderCandidates(db, threadId, [id3, id1, id2]) updates sort_order so querying returns [id3, id1, id2]
- Test: reorderCandidates returns { success: false, error } when thread status is "resolved"
- Test: createCandidate assigns sort_order = max existing sort_order + 1000 (first candidate gets 1000, second gets 2000)
- Test: reorderCandidates returns { success: false } when thread does not exist
</behavior>
<action>
1. **Schema** (`src/db/schema.ts`): Add `sortOrder: real("sort_order").notNull().default(0)` to the `threadCandidates` table definition.
2. **Migration**: Run `bun run db:generate` to produce the Drizzle migration SQL. Then apply it with `bun run db:push`. After applying, run a data backfill to space existing candidates:
```sql
UPDATE thread_candidates SET sort_order = (
SELECT (ROW_NUMBER() OVER (PARTITION BY thread_id ORDER BY created_at)) * 1000
FROM thread_candidates AS tc2 WHERE tc2.id = thread_candidates.id
);
```
Execute this backfill via the Drizzle migration custom SQL or a small script.
3. **Test helper** (`tests/helpers/db.ts`): Add `sort_order REAL NOT NULL DEFAULT 0` to the CREATE TABLE thread_candidates statement (after the `cons TEXT` line, before `created_at`).
4. **Zod schema** (`src/shared/schemas.ts`): Add:
```typescript
export const reorderCandidatesSchema = z.object({
orderedIds: z.array(z.number().int().positive()).min(1),
});
```
5. **Types** (`src/shared/types.ts`): Add import of `reorderCandidatesSchema` and:
```typescript
export type ReorderCandidates = z.infer<typeof reorderCandidatesSchema>;
```
6. **Service** (`src/server/services/thread.service.ts`):
- In `getThreadWithCandidates`: Add `.orderBy(threadCandidates.sortOrder)` to the candidateList query (after `.where()`).
- In `createCandidate`: Before inserting, query `MAX(sort_order)` from threadCandidates where threadId matches. Set `sortOrder: (maxRow?.maxOrder ?? 0) + 1000` in the `.values()` call. Use `sql<number>` template for the MAX query.
- Add new exported function `reorderCandidates(db, threadId, orderedIds)`:
- Wrap in `db.transaction()`.
- Verify thread exists and `status === "active"` (return `{ success: false, error: "Thread not active" }` if not).
- Loop through `orderedIds`, UPDATE each candidate's `sortOrder` to `(index + 1) * 1000`.
- Return `{ success: true }`.
7. **Tests** (`tests/services/thread.service.test.ts`):
- Import `reorderCandidates` from the service.
- Add a new `describe("reorderCandidates", () => { ... })` block with the behavior tests listed above.
- Add test for `getThreadWithCandidates` ordering by sort_order (create candidates, set different sort_orders manually via db, verify order).
- Add test for `createCandidate` sort_order appending.
</action>
<verify>
<automated>bun test tests/services/thread.service.test.ts</automated>
</verify>
<done>All existing thread service tests pass (28+) plus 5+ new tests for reorderCandidates, sort_order ordering, sort_order appending. sortOrder column exists in schema with REAL type.</done>
</task>
<task type="auto" tdd="true">
<name>Task 2: PATCH reorder route + route tests</name>
<files>src/server/routes/threads.ts, tests/routes/threads.test.ts</files>
<behavior>
- Test: PATCH /api/threads/:id/candidates/reorder with valid orderedIds returns 200 + { success: true }
- Test: After PATCH reorder, GET /api/threads/:id returns candidates in the new order
- Test: PATCH /api/threads/:id/candidates/reorder on a resolved thread returns 400
- Test: PATCH /api/threads/:id/candidates/reorder with empty body returns 400 (Zod validation)
</behavior>
<action>
1. **Route** (`src/server/routes/threads.ts`):
- Import `reorderCandidatesSchema` from `../../shared/schemas.ts`.
- Import `reorderCandidates` from `../services/thread.service.ts`.
- Add PATCH route BEFORE the resolution route (to avoid param conflicts):
```typescript
app.patch(
"/:id/candidates/reorder",
zValidator("json", reorderCandidatesSchema),
(c) => {
const db = c.get("db");
const threadId = Number(c.req.param("id"));
const { orderedIds } = c.req.valid("json");
const result = reorderCandidates(db, threadId, orderedIds);
if (!result.success) return c.json({ error: result.error }, 400);
return c.json({ success: true });
},
);
```
2. **Route tests** (`tests/routes/threads.test.ts`):
- Add a new `describe("PATCH /api/threads/:id/candidates/reorder", () => { ... })` block.
- Test: Create a thread with 3 candidates via API, PATCH reorder with reversed IDs, GET thread and verify candidates array is in the new order.
- Test: Resolve a thread, then PATCH reorder returns 400.
- Test: PATCH with invalid body (empty orderedIds array or missing field) returns 400.
</action>
<verify>
<automated>bun test tests/routes/threads.test.ts</automated>
</verify>
<done>PATCH /api/threads/:id/candidates/reorder returns 200 on active thread + persists order. Returns 400 on resolved thread. All existing route tests still pass.</done>
</task>
</tasks>
<verification>
```bash
# Full test suite — all existing + new tests green
bun test
# Verify sort_order column exists in schema
grep -n "sortOrder" src/db/schema.ts
# Verify reorder endpoint registered
grep -n "candidates/reorder" src/server/routes/threads.ts
# Verify test helper updated
grep -n "sort_order" tests/helpers/db.ts
```
</verification>
<success_criteria>
- sort_order REAL column added to threadCandidates schema and test helper
- getThreadWithCandidates returns candidates sorted by sort_order ascending
- createCandidate appends new candidates at max sort_order + 1000
- reorderCandidates service function updates sort_order in transaction, rejects resolved threads
- PATCH /api/threads/:id/candidates/reorder validated with Zod, returns 200/400 correctly
- All existing tests pass with zero regressions + 8+ new tests
</success_criteria>
<output>
After completion, create `.planning/phases/11-candidate-ranking/11-01-SUMMARY.md`
</output>

View File

@@ -0,0 +1,117 @@
---
phase: 11-candidate-ranking
plan: "01"
subsystem: database, api
tags: [drizzle, sqlite, hono, zod, sort-order, reorder, candidates]
# Dependency graph
requires: []
provides:
- sortOrder REAL column on threadCandidates with default 0
- reorderCandidates service function (transaction, active-only guard)
- PATCH /api/threads/:id/candidates/reorder endpoint with Zod validation
- getThreadWithCandidates returns candidates ordered by sort_order ASC
- createCandidate appends at max sort_order + 1000 (first=1000, second=2000)
- reorderCandidatesSchema Zod validator in shared/schemas.ts
- ReorderCandidates type in shared/types.ts
affects: [11-02, frontend-drag-reorder, candidate-lists]
# Tech tracking
tech-stack:
added: []
patterns:
- "Append-at-end sort_order: query MAX(sort_order), insert at +1000 gap"
- "Reorder transaction pattern: verify active thread, loop UPDATE sort_order = (index+1)*1000"
- "Active-only guard in reorder: return { success: false, error } when thread status != active"
key-files:
created:
- drizzle/0005_clear_micromax.sql
- drizzle/meta/0005_snapshot.json
modified:
- src/db/schema.ts
- tests/helpers/db.ts
- src/shared/schemas.ts
- src/shared/types.ts
- src/server/services/thread.service.ts
- src/server/routes/threads.ts
- tests/services/thread.service.test.ts
- tests/routes/threads.test.ts
key-decisions:
- "sortOrder uses REAL type (not INTEGER) to allow fractional values for future midpoint insertions without bulk rewrites"
- "First candidate gets sort_order=1000, subsequent at +1000 gaps, giving room for future insertions"
- "reorderCandidates uses (index+1)*1000 to space out assignments and reset gaps after each reorder"
- "Applied migration directly via sqlite3 CLI + data backfill instead of db:push (avoided data-loss warning on existing rows)"
patterns-established:
- "Reorder endpoint pattern: PATCH /:id/candidates/reorder, Zod validates orderedIds array, service returns {success, error}"
- "Service active-only guard: check thread.status !== 'active', return {success: false, error: 'Thread not active'}"
requirements-completed: [RANK-01, RANK-04, RANK-05]
# Metrics
duration: 4min
completed: 2026-03-16
---
# Phase 11 Plan 01: Candidate Ranking Backend Summary
**sortOrder REAL column, reorderCandidates transaction service, and PATCH /api/threads/:id/candidates/reorder endpoint with active-thread guard**
## Performance
- **Duration:** ~4 min
- **Started:** 2026-03-16T21:19:26Z
- **Completed:** 2026-03-16T21:22:46Z
- **Tasks:** 2 of 2
- **Files modified:** 8
## Accomplishments
- Added sortOrder REAL column to threadCandidates with 1000-gap append strategy
- Implemented reorderCandidates service with transaction and active-thread guard
- Added PATCH /api/threads/:id/candidates/reorder endpoint with Zod validation
- getThreadWithCandidates now orders candidates by sort_order ASC
- 10 new tests (5 service + 5 route) added; all 135 tests pass with zero regressions
## Task Commits
Each task was committed atomically:
1. **Task 1: Schema, migration, service layer, and tests for sort_order + reorder** - `f01d71d` (feat)
2. **Task 2: PATCH reorder route + route tests** - `d6acfcb` (feat)
_Note: TDD tasks each committed after GREEN phase._
## Files Created/Modified
- `src/db/schema.ts` - Added sortOrder REAL column to threadCandidates
- `tests/helpers/db.ts` - Added sort_order REAL NOT NULL DEFAULT 0 to CREATE TABLE
- `src/shared/schemas.ts` - Added reorderCandidatesSchema
- `src/shared/types.ts` - Added ReorderCandidates type, imported reorderCandidatesSchema
- `src/server/services/thread.service.ts` - Added reorderCandidates, updated createCandidate + getThreadWithCandidates
- `src/server/routes/threads.ts` - Added PATCH /:id/candidates/reorder route
- `tests/services/thread.service.test.ts` - Added 5 new tests for sort_order behavior
- `tests/routes/threads.test.ts` - Added 5 new route tests for reorder endpoint
- `drizzle/0005_clear_micromax.sql` - Generated migration SQL for sort_order column
- `drizzle/meta/0005_snapshot.json` - Drizzle schema snapshot
## Decisions Made
- Used REAL type for sort_order (not INTEGER) to allow fractional values for future midpoint insertions
- 1000-gap strategy: first candidate = 1000, each subsequent += 1000; reorder resets to (index+1)*1000
- Applied migration directly via sqlite3 CLI to avoid Drizzle's data-loss warning on existing rows (db had 2 rows; column has DEFAULT 0 so no actual data loss)
- Backfilled existing candidates with ROW_NUMBER * 1000 per thread to give proper initial ordering
## Deviations from Plan
None - plan executed exactly as written.
## Issues Encountered
- `bun run db:push` showed data-loss warning for adding NOT NULL column to existing rows. Applied the migration directly via sqlite3 CLI instead (`ALTER TABLE thread_candidates ADD COLUMN sort_order REAL NOT NULL DEFAULT 0`). The column has DEFAULT 0 so no actual data loss; existing rows got 0 then were backfilled to proper 1000-gap values.
## Next Phase Readiness
- Backend reorder API fully operational; frontend drag-to-reorder (11-02) can now consume PATCH /api/threads/:id/candidates/reorder
- sort_order values returned in getThreadWithCandidates response, available to frontend for drag state initialization
---
*Phase: 11-candidate-ranking*
*Completed: 2026-03-16*

View File

@@ -0,0 +1,378 @@
---
phase: 11-candidate-ranking
plan: "02"
type: execute
wave: 2
depends_on: ["11-01"]
files_modified:
- src/client/stores/uiStore.ts
- src/client/hooks/useCandidates.ts
- src/client/components/CandidateListItem.tsx
- src/client/components/CandidateCard.tsx
- src/client/routes/threads/$threadId.tsx
autonomous: false
requirements: [RANK-01, RANK-02, RANK-04, RANK-05]
must_haves:
truths:
- "User can drag a candidate card to a new position in list view and it persists after page refresh"
- "Top 3 candidates display gold, silver, and bronze medal badges"
- "Rank badges appear in both list view and grid view"
- "Drag handles are hidden and drag is disabled on resolved threads"
- "Rank badges remain visible on resolved threads"
- "User can toggle between list and grid view"
- "List view is the default view"
artifacts:
- path: "src/client/components/CandidateListItem.tsx"
provides: "Horizontal list-view candidate card with drag handle and rank badge"
min_lines: 60
- path: "src/client/routes/threads/$threadId.tsx"
provides: "View toggle + Reorder.Group wrapping candidates + tempItems flicker prevention"
contains: "Reorder.Group"
- path: "src/client/hooks/useCandidates.ts"
provides: "useReorderCandidates mutation hook"
contains: "useReorderCandidates"
- path: "src/client/stores/uiStore.ts"
provides: "candidateViewMode state"
contains: "candidateViewMode"
- path: "src/client/components/CandidateCard.tsx"
provides: "Rank badge on grid-view cards"
contains: "RankBadge"
key_links:
- from: "src/client/routes/threads/$threadId.tsx"
to: "src/client/hooks/useCandidates.ts"
via: "useReorderCandidates(threadId)"
pattern: "useReorderCandidates"
- from: "src/client/hooks/useCandidates.ts"
to: "/api/threads/:id/candidates/reorder"
via: "apiPatch"
pattern: "apiPatch.*candidates/reorder"
- from: "src/client/routes/threads/$threadId.tsx"
to: "framer-motion"
via: "Reorder.Group + Reorder.Item"
pattern: "Reorder\\.Group"
- from: "src/client/components/CandidateListItem.tsx"
to: "framer-motion"
via: "Reorder.Item + useDragControls"
pattern: "useDragControls"
- from: "src/client/stores/uiStore.ts"
to: "src/client/routes/threads/$threadId.tsx"
via: "candidateViewMode state"
pattern: "candidateViewMode"
---
<objective>
Build the drag-to-reorder UI with list/grid view toggle, CandidateListItem component, framer-motion Reorder integration, rank badges, and resolved-thread guard.
Purpose: Delivers the user-facing ranking experience: drag candidates to prioritize, see gold/silver/bronze medals, toggle between compact list and card grid views. All four RANK requirements are covered.
Output: Working drag-to-reorder in list view, rank badges in both views, view toggle, resolved-thread readonly mode.
</objective>
<execution_context>
@/home/jlmak/.claude/get-shit-done/workflows/execute-plan.md
@/home/jlmak/.claude/get-shit-done/templates/summary.md
</execution_context>
<context>
@.planning/PROJECT.md
@.planning/ROADMAP.md
@.planning/STATE.md
@.planning/phases/11-candidate-ranking/11-CONTEXT.md
@.planning/phases/11-candidate-ranking/11-RESEARCH.md
@.planning/phases/11-candidate-ranking/11-01-SUMMARY.md
<interfaces>
<!-- Interfaces created by Plan 01 that this plan depends on -->
From src/shared/schemas.ts (created in 11-01):
```typescript
export const reorderCandidatesSchema = z.object({
orderedIds: z.array(z.number().int().positive()).min(1),
});
```
From src/shared/types.ts (created in 11-01):
```typescript
export type ReorderCandidates = z.infer<typeof reorderCandidatesSchema>;
```
From src/server/services/thread.service.ts (modified in 11-01):
```typescript
export function reorderCandidates(db, threadId, orderedIds): { success: boolean; error?: string }
// getThreadWithCandidates now returns candidates sorted by sort_order ascending
// createCandidate now assigns sort_order = max + 1000 (appends to bottom)
```
API endpoint (created in 11-01):
```
PATCH /api/threads/:id/candidates/reorder
Body: { orderedIds: number[] }
Response: { success: true } | { error: string } (400)
```
From src/client/lib/api.ts:
```typescript
export async function apiPatch<T>(url: string, body: unknown): Promise<T>;
```
From src/client/hooks/useCandidates.ts (existing):
```typescript
interface CandidateResponse {
id: number; threadId: number; name: string;
weightGrams: number | null; priceCents: number | null;
categoryId: number; notes: string | null; productUrl: string | null;
imageFilename: string | null; status: "researching" | "ordered" | "arrived";
pros: string | null; cons: string | null;
createdAt: string; updatedAt: string;
}
```
From src/client/components/CandidateCard.tsx (existing props):
```typescript
interface CandidateCardProps {
id: number; name: string; weightGrams: number | null; priceCents: number | null;
categoryName: string; categoryIcon: string; imageFilename: string | null;
productUrl?: string | null; threadId: number; isActive: boolean;
status: "researching" | "ordered" | "arrived";
onStatusChange: (status: "researching" | "ordered" | "arrived") => void;
pros?: string | null; cons?: string | null;
}
```
From src/client/stores/uiStore.ts (existing patterns):
```typescript
interface UIState {
// ... existing state
// Add: candidateViewMode: "list" | "grid"
// Add: setCandidateViewMode: (mode: "list" | "grid") => void
}
```
From framer-motion (installed v12.37.0):
```typescript
import { Reorder, useDragControls } from "framer-motion";
// Reorder.Group: axis="y", values={items}, onReorder={setItems}
// Reorder.Item: value={item}, dragControls={controls}, dragListener={false}
// useDragControls: controls.start(pointerEvent) on handle's onPointerDown
```
From lucide-react (confirmed available icons):
- grip-vertical (drag handle)
- medal (rank badge)
- layout-list (list view toggle)
- layout-grid (grid view toggle)
</interfaces>
</context>
<tasks>
<task type="auto">
<name>Task 1: useReorderCandidates hook + uiStore view mode + CandidateListItem component</name>
<files>src/client/hooks/useCandidates.ts, src/client/stores/uiStore.ts, src/client/components/CandidateListItem.tsx</files>
<action>
1. **useReorderCandidates hook** (`src/client/hooks/useCandidates.ts`):
- Import `apiPatch` from `../lib/api`.
- Add new exported function:
```typescript
export function useReorderCandidates(threadId: number) {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: { orderedIds: number[] }) =>
apiPatch<{ success: boolean }>(
`/api/threads/${threadId}/candidates/reorder`,
data,
),
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ["threads", threadId] });
},
});
}
```
2. **uiStore** (`src/client/stores/uiStore.ts`):
- Add to the UIState interface:
```typescript
candidateViewMode: "list" | "grid";
setCandidateViewMode: (mode: "list" | "grid") => void;
```
- Add to the create block:
```typescript
candidateViewMode: "list",
setCandidateViewMode: (mode) => set({ candidateViewMode: mode }),
```
3. **CandidateListItem** (`src/client/components/CandidateListItem.tsx`) — NEW FILE:
- Create a horizontal card component for list view.
- Import `{ Reorder, useDragControls }` from `framer-motion`.
- Import `LucideIcon` from `../lib/iconData`, formatters, hooks (useWeightUnit, useCurrency), useUIStore, StatusBadge.
- Props interface:
```typescript
interface CandidateListItemProps {
candidate: CandidateWithCategory; // The full candidate object from thread.candidates
rank: number; // 1-based position index
isActive: boolean; // thread.status === "active"
onStatusChange: (status: "researching" | "ordered" | "arrived") => void;
}
```
Where `CandidateWithCategory` is the candidate shape from `useThread` response (id, name, weightGrams, priceCents, categoryName, categoryIcon, imageFilename, productUrl, status, pros, cons, etc.). Define this type locally or reference the CandidateResponse + category fields.
- Use `useDragControls()` hook. Return a `Reorder.Item` with `value={candidate}` (the full candidate object, same reference used in Reorder.Group values), `dragControls={controls}`, `dragListener={false}`.
- Layout (horizontal card):
- Outer: `flex items-center gap-3 bg-white rounded-xl border border-gray-100 p-3 hover:border-gray-200 hover:shadow-sm transition-all group`
- LEFT: Drag handle (only if `isActive`): GripVertical icon (size 16), `onPointerDown={(e) => controls.start(e)}`, classes: `cursor-grab active:cursor-grabbing text-gray-300 hover:text-gray-500 touch-none shrink-0`
- RANK BADGE: Inline `RankBadge` component (see below). Shows medal icon for rank 1-3 with gold/silver/bronze colors. Returns null for rank > 3.
- IMAGE THUMBNAIL: 48x48 rounded-lg overflow-hidden shrink-0. If `imageFilename`, show `<img src="/uploads/${imageFilename}" />` with object-cover. Else show `LucideIcon` of `categoryIcon` (size 20) in gray on gray-50 background.
- NAME + BADGES: `flex-1 min-w-0` container.
- Name: `text-sm font-semibold text-gray-900 truncate`
- Badge row: `flex flex-wrap gap-1.5 mt-1` with weight (blue), price (green), category (gray + icon), StatusBadge, pros/cons badge (purple "+/- Notes").
- Use same badge pill classes as CandidateCard.
- ACTION BUTTONS (hover-reveal, right side): Winner (if isActive), Delete, External link (if productUrl). Use same click handlers as CandidateCard (openResolveDialog, openConfirmDeleteCandidate, openExternalLink from uiStore). Classes: `opacity-0 group-hover:opacity-100 transition-opacity` on a flex container.
- Clicking the card body (not handle or action buttons) opens the edit panel: wrap in a clickable area that calls `openCandidateEditPanel(candidate.id)`.
- **RankBadge** (inline helper or small component in same file):
```typescript
const RANK_COLORS = ["#D4AF37", "#C0C0C0", "#CD7F32"]; // gold, silver, bronze
function RankBadge({ rank }: { rank: number }) {
if (rank > 3) return null;
return <LucideIcon name="medal" size={16} className="shrink-0" style={{ color: RANK_COLORS[rank - 1] }} />;
}
```
Export `RankBadge` so it can be reused by CandidateCard in grid view.
</action>
<verify>
<automated>cd /home/jlmak/Projects/jlmak/GearBox && bun run lint 2>&1 | head -30</automated>
</verify>
<done>CandidateListItem.tsx created with drag handle, rank badge, horizontal layout. useReorderCandidates hook created. uiStore has candidateViewMode. RankBadge exported. Lint passes.</done>
</task>
<task type="auto">
<name>Task 2: Thread detail page with view toggle, Reorder.Group, rank badges in grid view</name>
<files>src/client/routes/threads/$threadId.tsx, src/client/components/CandidateCard.tsx</files>
<action>
1. **CandidateCard rank badge** (`src/client/components/CandidateCard.tsx`):
- Import `RankBadge` from `./CandidateListItem` (or wherever it's exported).
- Add `rank?: number` to `CandidateCardProps`.
- In the card layout, add `{rank != null && <RankBadge rank={rank} />}` in the badge row (flex-wrap area), positioned as the first badge before weight/price.
2. **Thread detail page** (`src/client/routes/threads/$threadId.tsx`):
- Import `{ Reorder }` from `framer-motion`.
- Import `{ useState, useEffect }` from `react`.
- Import `CandidateListItem` from `../../components/CandidateListItem`.
- Import `useReorderCandidates` from `../../hooks/useCandidates`.
- Import `useUIStore` selector for `candidateViewMode` and `setCandidateViewMode`.
- Import `LucideIcon` (already imported).
- **View toggle** in the header area (after the "Add Candidate" button, or in the thread header row):
- Two icon buttons: LayoutList and LayoutGrid (from Lucide).
- Active button has `bg-gray-200 text-gray-900`, inactive has `text-gray-400 hover:text-gray-600`.
- `onClick` calls `setCandidateViewMode("list")` or `setCandidateViewMode("grid")`.
- Placed inline in a small toggle group: `flex items-center gap-1 bg-gray-100 rounded-lg p-0.5`
- **tempItems pattern** for flicker prevention:
```typescript
const [tempItems, setTempItems] = useState<typeof thread.candidates | null>(null);
const displayItems = tempItems ?? thread.candidates;
// thread.candidates is already sorted by sort_order from server (11-01)
```
Reset tempItems to null whenever `thread.candidates` reference changes (use useEffect if needed, or rely on onSettled clearing).
- **Reorder.Group** (list view, active threads only):
- When `candidateViewMode === "list"` AND candidates exist:
- If `isActive`: Wrap candidates in `<Reorder.Group axis="y" values={displayItems} onReorder={setTempItems} className="flex flex-col gap-2">`.
- Each candidate renders `<CandidateListItem key={candidate.id} candidate={candidate} rank={index + 1} isActive={isActive} onStatusChange={...} />`.
- On Reorder.Item `onDragEnd`, trigger the save. The save function:
```typescript
function handleDragEnd() {
if (!tempItems) return;
reorderMutation.mutate(
{ orderedIds: tempItems.map((c) => c.id) },
{ onSettled: () => setTempItems(null) }
);
}
```
Attach this to `Reorder.Group` via a wrapper that uses `onPointerUp` or pass as prop to `CandidateListItem`. The cleanest approach: use framer-motion's `onDragEnd` prop on each `Reorder.Item` — when any item finishes dragging, if tempItems differs from server data, fire the mutation.
- If `!isActive` (resolved): Render the same `CandidateListItem` components but WITHOUT `Reorder.Group` — just a plain `<div className="flex flex-col gap-2">`. The `isActive={false}` prop hides drag handles. Rank badges remain visible per user decision.
- When `candidateViewMode === "grid"` AND candidates exist:
- Render the existing `<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">` with `CandidateCard` components.
- Pass `rank={index + 1}` to each CandidateCard so rank badges appear in grid view too.
- Both active and resolved threads use static grid (no drag in grid view per user decision).
- **Important framer-motion detail**: `Reorder.Group` `values` must be the same array reference as what you iterate. Use `displayItems` for both `values` and `.map()`. The `Reorder.Item` `value` must be the same object reference (not a copy). Since we use the full candidate object, `value={candidate}` where candidate comes from `displayItems.map(...)`.
- **Empty state**: Keep the existing empty state rendering for both views.
- **useEffect to clear tempItems**: When `thread.candidates` changes (new data from server), clear tempItems:
```typescript
useEffect(() => {
setTempItems(null);
}, [thread?.candidates]);
```
This ensures that when React Query refetches, tempItems is cleared and we render fresh server data.
</action>
<verify>
<automated>cd /home/jlmak/Projects/jlmak/GearBox && bun run lint 2>&1 | head -30</automated>
</verify>
<done>Thread detail page renders list/grid toggle. List view has drag-to-reorder via Reorder.Group with tempItems flicker prevention. Grid view shows rank badges. Resolved threads show static list/grid with rank badges but no drag handles. Lint passes.</done>
</task>
<task type="checkpoint:human-verify" gate="blocking">
<name>Task 3: Verify drag-to-reorder ranking experience</name>
<files>none</files>
<action>
Human verifies the complete drag-to-reorder candidate ranking with list/grid view toggle, rank badges (gold/silver/bronze), auto-save persistence, and resolved thread guard.
</action>
<what-built>Complete drag-to-reorder candidate ranking with list/grid view toggle, rank badges (gold/silver/bronze), auto-save persistence, and resolved thread guard.</what-built>
<how-to-verify>
1. Start dev servers: `bun run dev:client` and `bun run dev:server`
2. Navigate to an existing active thread with 3+ candidates (or create one)
3. Verify list view is the default (vertical stack of horizontal cards)
4. Verify drag handles (grip icon) appear on the left of each card
5. Drag a candidate to a new position — verify it moves smoothly with gap animation
6. Release — verify the new order persists (refresh the page to confirm)
7. Verify the top 3 candidates show gold, silver, bronze medal icons before their names
8. Toggle to grid view — verify rank badges also appear on grid cards
9. Toggle back to list view — verify drag still works
10. Navigate to a resolved thread — verify NO drag handles, but rank badges ARE visible
11. Verify candidates on resolved thread render in their ranked order (static)
</how-to-verify>
<verify>Human confirms all 11 verification steps pass</verify>
<done>All ranking features verified: drag reorder works, persists, shows rank badges in both views, disabled on resolved threads</done>
<resume-signal>Type "approved" or describe any issues</resume-signal>
</task>
</tasks>
<verification>
```bash
# Full test suite green
bun test
# Verify all key files exist
ls src/client/components/CandidateListItem.tsx
grep -n "useReorderCandidates" src/client/hooks/useCandidates.ts
grep -n "candidateViewMode" src/client/stores/uiStore.ts
grep -n "Reorder.Group" src/client/routes/threads/\$threadId.tsx
grep -n "RankBadge" src/client/components/CandidateCard.tsx
# Lint clean
bun run lint
```
</verification>
<success_criteria>
- List view shows horizontal cards with drag handles on active threads
- Drag-to-reorder works via framer-motion Reorder.Group with grip handle
- Order persists after page refresh via PATCH /api/threads/:id/candidates/reorder
- tempItems pattern prevents React Query flicker
- Top 3 candidates display gold (#D4AF37), silver (#C0C0C0), bronze (#CD7F32) medal badges
- Rank badges visible in both list and grid views
- Grid/list toggle works with list as default
- Resolved threads: no drag handles, rank badges visible, static order
- All tests pass, lint clean
</success_criteria>
<output>
After completion, create `.planning/phases/11-candidate-ranking/11-02-SUMMARY.md`
</output>

View File

@@ -0,0 +1,85 @@
---
phase: 11-candidate-ranking
plan: "02"
subsystem: client-ui
tags: [drag-reorder, framer-motion, rank-badges, view-toggle, list-view]
dependency_graph:
requires: [11-01]
provides: [drag-to-reorder-ui, rank-badges, list-grid-toggle]
affects: [threads/$threadId.tsx, CandidateCard, CandidateListItem, uiStore, useCandidates]
tech_stack:
added: []
patterns:
- framer-motion Reorder.Group + Reorder.Item with useDragControls for drag handle
- tempItems pattern to prevent React Query flicker during optimistic drag
- RankBadge exported from CandidateListItem for reuse across views
- candidateViewMode in uiStore for list/grid toggle state
key_files:
created:
- src/client/components/CandidateListItem.tsx
modified:
- src/client/hooks/useCandidates.ts
- src/client/stores/uiStore.ts
- src/client/components/CandidateCard.tsx
- src/client/routes/threads/$threadId.tsx
- src/client/lib/iconData.tsx
- src/client/hooks/useThreads.ts
decisions:
- Resolved thread list view uses plain div (not Reorder.Group) — no drag, rank badges visible
- handleDragEnd fires on Reorder.Group onPointerUp to debounce reorder API call
- biome-ignore applied to useExhaustiveDependencies for thread?.candidates dep — intentional trigger
metrics:
duration: 4min
completed: 2026-03-16T21:29:07Z
tasks_completed: 3
files_changed: 7
---
# Phase 11 Plan 02: Drag-to-Reorder UI Summary
Drag-to-reorder candidate ranking with list/grid view toggle, gold/silver/bronze rank badges, and framer-motion Reorder.Group with tempItems flicker prevention.
## What Was Built
### Task 1: useReorderCandidates hook + uiStore view mode + CandidateListItem component
- Added `useReorderCandidates` mutation hook to `useCandidates.ts` using `apiPatch` to hit `PATCH /api/threads/:id/candidates/reorder`
- Added `candidateViewMode: "list" | "grid"` and `setCandidateViewMode` to `uiStore.ts`
- Created `CandidateListItem.tsx` — horizontal card for list view with drag handle (GripVertical), RankBadge (medal icon), 48x48 image thumbnail, badge row (weight/price/category/status/pros-cons), and hover-reveal action buttons
- Exported `RankBadge` component (gold `#D4AF37`, silver `#C0C0C0`, bronze `#CD7F32`) for reuse
- Added `style` prop support to `LucideIcon` for colored medal icons
- Added `pros` and `cons` fields to `CandidateWithCategory` in `useThreads.ts` (Rule 2 auto-fix — missing after Phase 10)
### Task 2: Thread detail page with view toggle, Reorder.Group, rank badges in grid view
- Updated `CandidateCard.tsx`: added `rank?: number` prop and renders `<RankBadge rank={rank} />` in badge row
- Updated `threads/$threadId.tsx`:
- List/grid view toggle (LayoutList / LayoutGrid icons) using `candidateViewMode` from uiStore
- Active list view: `<Reorder.Group>` wrapping `<CandidateListItem>` instances for drag-to-reorder
- Resolved list view: plain `<div>` with `<CandidateListItem isActive={false}>` — rank badges visible, drag handles hidden
- Grid view: existing `<CandidateCard>` grid with `rank={index + 1}` passed to each card
- `tempItems` state: holds in-progress drag order, falls back to `thread.candidates` when null
- `handleDragEnd`: fires `reorderMutation.mutate({ orderedIds })` and clears tempItems on settled
- `useEffect` clears tempItems when `thread?.candidates` reference changes (fresh server data)
### Task 3: Human verification (auto-approved — auto_chain_active)
## Deviations from Plan
### Auto-fixed Issues
**1. [Rule 2 - Missing] Added pros/cons fields to CandidateWithCategory in useThreads.ts**
- **Found during:** Task 1 (needed by CandidateListItem)
- **Issue:** `CandidateWithCategory` interface in `useThreads.ts` was missing `pros` and `cons` fields added in Phase 10. CandidateListItem needed these to render the "+/- Notes" badge.
- **Fix:** Added `pros: string | null` and `cons: string | null` to the interface
- **Files modified:** `src/client/hooks/useThreads.ts`
- **Commit:** acfa995
**2. [Rule 2 - Missing] Added style prop to LucideIcon component**
- **Found during:** Task 1 (needed by RankBadge for medal colors)
- **Issue:** LucideIcon only accepted `className` for styling; RankBadge needed inline `style={{ color }}` for gold/silver/bronze hex colors not achievable via Tailwind
- **Fix:** Added optional `style?: React.CSSProperties` prop to LucideIcon and passed through to icon component
- **Files modified:** `src/client/lib/iconData.tsx`
- **Commit:** acfa995
## Self-Check: PASSED
All created/modified files exist. Both task commits (acfa995, 94c07e7) confirmed in git log.

View File

@@ -0,0 +1,107 @@
# Phase 11: Candidate Ranking - Context
**Gathered:** 2026-03-16
**Status:** Ready for planning
<domain>
## Phase Boundary
Users can drag candidates into a priority order within a thread. The rank persists across sessions and is visually communicated with medal badges on the top 3. Drag handles and reordering are disabled on resolved threads. Comparison view, impact preview, and pros/cons editing are separate phases.
</domain>
<decisions>
## Implementation Decisions
### Card layout and view toggle
- Add a grid/list view toggle in the thread header (list view is default)
- List view: vertical stack of horizontal cards (image thumbnail on left, name + badges on right) — enables drag-to-reorder
- Grid view: current 3-column responsive card layout preserved
- Both views render candidates in rank order (sort_order ascending)
- Rank badges visible in both views
### Drag handle design
- Always-visible GripVertical icon (Lucide) on the left side of each list-view card
- Grip icon color: muted gray (text-gray-300), darkens to text-gray-500 on hover
- Cursor changes to 'grab' on hover, 'grabbing' during drag
- Drag feedback: elevated card with shadow + scale-up effect; other cards animate to show drop target gap (standard framer-motion Reorder behavior)
- On resolved threads: grip icon disappears entirely (not disabled/grayed)
- Drag only available in list view (grid view has no drag handles)
### Rank badge style
- Medal icons (Lucide 'medal' or 'trophy') in gold (#D4AF37), silver (#C0C0C0), bronze (#CD7F32) for top 3 candidates
- Positioned inline before the candidate name text
- Candidates ranked 4th and below show no rank indicator — position implied by list order
- On resolved threads: rank badges remain visible (static, read-only) — **overrides roadmap success criteria #4 which said "rank badges absent on resolved thread"**; user prefers retrospective visibility
### Sort order and persistence
- Schema migration adds `sort_order REAL NOT NULL DEFAULT 0` to `thread_candidates`
- Migration initializes existing candidates with spaced values (1000, 2000, 3000...) ordered by `created_at` — ensures immediate correct ordering
- Fractional indexing: only the moved item gets a single UPDATE (midpoint between neighbors)
- New candidates added to a thread get the highest sort_order (appended to bottom of rank)
- Auto-save on drop — no "Save order" button; reorder persists immediately via `PATCH /api/threads/:id/candidates/reorder`
- `tempItems` local state pattern: render from `tempItems ?? queryData.candidates`; clear on mutation `onSettled` — prevents React Query flicker
### Claude's Discretion
- Exact horizontal card dimensions and spacing in list view
- Grid/list toggle icon style and placement
- Drag animation timing and spring config
- Image thumbnail size in list view cards
- How action buttons (Winner, Delete, Link) adapt to horizontal card layout
- Keyboard accessibility for reordering (arrow keys to move)
</decisions>
<code_context>
## Existing Code Insights
### Reusable Assets
- `CandidateCard` (`src/client/components/CandidateCard.tsx`): Current card component — needs horizontal variant for list view, or a new `CandidateListItem` component
- `StatusBadge` (`src/client/components/StatusBadge.tsx`): Click-to-cycle pattern reusable in list view
- `useCandidates.ts` hooks: `useCreateCandidate`, `useUpdateCandidate`, `useDeleteCandidate` — need new `useReorderCandidates` mutation
- `useThread` hook: Returns thread with `candidates[]` array — already has all data needed, just needs sort_order ordering
- `formatWeight`/`formatPrice` formatters: Reuse in list view card badges
- `useWeightUnit`/`useCurrency` hooks: Already used by CandidateCard
- `LucideIcon` helper: For GripVertical drag handle and medal rank badges
- `uiStore` (Zustand): Add `candidateViewMode: 'list' | 'grid'` for view toggle persistence
### Established Patterns
- framer-motion@12.37.0 already installed — `Reorder.Group`/`Reorder.Item` for drag ordering
- React Query for server data, Zustand for UI-only state
- Pill badges: blue for weight, green for price, gray for category, purple for pros/cons
- Services accept db as first param (DI pattern for testability)
- API validation via `@hono/zod-validator` with Zod schemas
- Hover-reveal action buttons on CandidateCard (Winner, Delete, External link)
### Integration Points
- `src/db/schema.ts`: Add `sortOrder: real("sort_order").notNull().default(0)` to `threadCandidates`
- `src/server/services/thread.service.ts`: New `reorderCandidates()` function (transactional); update `getCandidates` to ORDER BY sort_order
- `src/server/routes/threads.ts`: New `PATCH /:id/candidates/reorder` endpoint; reject if thread is resolved
- `src/shared/schemas.ts`: New `reorderCandidatesSchema` (z.object with orderedIds array)
- `src/client/routes/threads/$threadId.tsx`: Wrap candidates in `Reorder.Group`, add view toggle, use tempItems pattern
- `src/client/hooks/useCandidates.ts`: New `useReorderCandidates` mutation hook
- `tests/helpers/db.ts`: Update CREATE TABLE for thread_candidates to include sort_order column
- Drizzle migration: `sort_order REAL NOT NULL DEFAULT 0` + data migration to space existing rows
</code_context>
<specifics>
## Specific Ideas
- List view cards should feel like Trello or Linear cards — horizontal layout, grip handle on the left, compact but informative
- Drag feedback should use standard framer-motion spring animations (elevated + gap), not custom physics
- Medal badges should use actual metallic-feeling colors (gold #D4AF37, silver #C0C0C0, bronze #CD7F32), not generic highlight colors
</specifics>
<deferred>
## Deferred Ideas
None — discussion stayed within phase scope
</deferred>
---
*Phase: 11-candidate-ranking*
*Context gathered: 2026-03-16*

View File

@@ -0,0 +1,540 @@
# Phase 11: Candidate Ranking - Research
**Researched:** 2026-03-16
**Domain:** Drag-to-reorder UI + fractional indexing persistence
**Confidence:** HIGH
<user_constraints>
## User Constraints (from CONTEXT.md)
### Locked Decisions
**Card layout and view toggle**
- Add a grid/list view toggle in the thread header (list view is default)
- List view: vertical stack of horizontal cards (image thumbnail on left, name + badges on right) — enables drag-to-reorder
- Grid view: current 3-column responsive card layout preserved
- Both views render candidates in rank order (sort_order ascending)
- Rank badges visible in both views
**Drag handle design**
- Always-visible GripVertical icon (Lucide) on the left side of each list-view card
- Grip icon color: muted gray (text-gray-300), darkens to text-gray-500 on hover
- Cursor changes to 'grab' on hover, 'grabbing' during drag
- Drag feedback: elevated card with shadow + scale-up effect; other cards animate to show drop target gap (standard framer-motion Reorder behavior)
- On resolved threads: grip icon disappears entirely (not disabled/grayed)
- Drag only available in list view (grid view has no drag handles)
**Rank badge style**
- Medal icons (Lucide 'medal') in gold (#D4AF37), silver (#C0C0C0), bronze (#CD7F32) for top 3 candidates
- Positioned inline before the candidate name text
- Candidates ranked 4th and below show no rank indicator — position implied by list order
- On resolved threads: rank badges remain visible (static, read-only) — user prefers retrospective visibility
**Sort order and persistence**
- Schema migration adds `sort_order REAL NOT NULL DEFAULT 0` to `thread_candidates`
- Migration initializes existing candidates with spaced values (1000, 2000, 3000...) ordered by `created_at`
- Fractional indexing: only the moved item gets a single UPDATE (midpoint between neighbors)
- New candidates added to a thread get the highest sort_order (appended to bottom of rank)
- Auto-save on drop — no "Save order" button; reorder persists immediately via `PATCH /api/threads/:id/candidates/reorder`
- `tempItems` local state pattern: render from `tempItems ?? queryData.candidates`; clear on mutation `onSettled` — prevents React Query flicker
### Claude's Discretion
- Exact horizontal card dimensions and spacing in list view
- Grid/list toggle icon style and placement
- Drag animation timing and spring config
- Image thumbnail size in list view cards
- How action buttons (Winner, Delete, Link) adapt to horizontal card layout
- Keyboard accessibility for reordering (arrow keys to move)
### Deferred Ideas (OUT OF SCOPE)
None — discussion stayed within phase scope
</user_constraints>
<phase_requirements>
## Phase Requirements
| ID | Description | Research Support |
|----|-------------|-----------------|
| RANK-01 | User can drag candidates to reorder priority ranking within a thread | framer-motion Reorder.Group/Item handles drag + onReorder callback; fractional indexing PATCH saves order |
| RANK-02 | Top 3 ranked candidates display rank badges (gold, silver, bronze) | sort_order ascending sort gives rank position; Lucide `medal` icon confirmed available; CSS inline-color via style prop |
| RANK-04 | Candidate rank order persists across sessions | `sort_order REAL` column + Drizzle migration + `getThreadWithCandidates` ORDER BY sort_order; tempItems pattern prevents RQ flicker |
| RANK-05 | Drag handles and ranking are disabled on resolved threads | `isActive` prop already flows through `$threadId.tsx`; grip icon conditional render; Reorder.Group only rendered when isActive |
</phase_requirements>
---
## Summary
Phase 11 adds drag-to-reorder ranking for research thread candidates. The core mechanism is framer-motion's `Reorder.Group` / `Reorder.Item` components (already installed at v12.37.0 — no new dependencies), combined with a `sort_order REAL` column on `thread_candidates` and a fractional indexing strategy that writes only one row per reorder.
The drag handle pattern requires `useDragControls` from framer-motion so the drag is initiated only from the GripVertical icon, not from tapping anywhere on the card. The `tempItems` local state pattern prevents a visible flicker between optimistic UI and React Query re-fetch.
The phase introduces a grid/list view toggle (defaulting to list). The existing `CandidateCard` component handles grid view unchanged; a new `CandidateListItem` component (or a variant prop on `CandidateCard`) provides the horizontal list-view layout with the drag handle and rank badge.
**Primary recommendation:** Implement in this order — schema migration, service update, Zod schema + route, hook, then UI (view toggle, `CandidateListItem`, rank badge). This matches the established field-addition ladder pattern.
---
## Standard Stack
### Core
| Library | Version | Purpose | Why Standard |
|---------|---------|---------|--------------|
| framer-motion | ^12.37.0 (installed) | Drag-to-reorder via `Reorder.Group`/`Reorder.Item`; `useDragControls` for handle-based drag | Already in project; Reorder API is purpose-built for this pattern — no additional install |
| Drizzle ORM | installed | Schema migration + `ORDER BY sort_order` query | Project ORM; REAL type required for fractional indexing |
| @tanstack/react-query | installed | `useReorderCandidates` mutation + cache invalidation | Project data-fetch layer |
| Zustand | installed | `candidateViewMode: 'list' | 'grid'` in uiStore | Project UI state pattern |
| lucide-react | installed | GripVertical, Medal, LayoutList, LayoutGrid icons | All icons confirmed present in installed version |
### No New Dependencies
This phase requires zero new npm packages. framer-motion, React Query, Zustand, and Lucide are all already installed.
---
## Architecture Patterns
### Recommended Project Structure Changes
```
src/
├── db/schema.ts # Add sortOrder: real("sort_order")
├── server/
│ ├── services/thread.service.ts # Add reorderCandidates(), update getCandidates ORDER BY
│ └── routes/threads.ts # Add PATCH /:id/candidates/reorder
├── shared/
│ ├── schemas.ts # Add reorderCandidatesSchema
│ └── types.ts # Add ReorderCandidates type
├── client/
│ ├── components/
│ │ ├── CandidateCard.tsx # Unchanged (grid view)
│ │ └── CandidateListItem.tsx # NEW: horizontal list-view card with drag handle
│ ├── hooks/useCandidates.ts # Add useReorderCandidates mutation
│ ├── routes/threads/$threadId.tsx # Add view toggle, Reorder.Group, tempItems pattern
│ └── stores/uiStore.ts # Add candidateViewMode state
└── tests/
├── helpers/db.ts # Add sort_order column to CREATE TABLE
└── services/thread.service.test.ts # Tests for reorderCandidates()
```
### Pattern 1: framer-motion Reorder with Drag Handle
The `Reorder.Group` fires `onReorder` whenever a drag completes. The `useDragControls` hook
lets the drag be triggered only from the grip icon. Wrap each item with `Reorder.Item` and
attach `dragControls` to it.
```typescript
// Source: framer-motion dist/types/index.d.ts (confirmed in installed v12.37.0)
import { Reorder, useDragControls } from "framer-motion";
// In ThreadDetailPage — list view:
const [tempItems, setTempItems] = useState<Candidate[] | null>(null);
const displayItems = tempItems ?? thread.candidates; // sorted by sort_order from server
<Reorder.Group
axis="y"
values={displayItems}
onReorder={setTempItems} // updates local order instantly
className="flex flex-col gap-2"
>
{displayItems.map((candidate, index) => (
<CandidateListItem
key={candidate.id}
candidate={candidate}
rank={index + 1}
isActive={isActive}
onReorderSave={() => saveOrder(tempItems)} // called onDragEnd
/>
))}
</Reorder.Group>
```
```typescript
// In CandidateListItem — drag handle via useDragControls:
// Source: framer-motion dist/types/index.d.ts
import { Reorder, useDragControls } from "framer-motion";
function CandidateListItem({ candidate, rank, isActive, ... }) {
const controls = useDragControls();
return (
<Reorder.Item value={candidate} dragControls={controls} dragListener={false}>
<div className="flex items-center gap-3 bg-white rounded-xl border border-gray-100 p-3">
{/* Drag handle — only visible on active threads */}
{isActive && (
<div
onPointerDown={(e) => controls.start(e)}
className="cursor-grab active:cursor-grabbing text-gray-300 hover:text-gray-500 touch-none"
>
<LucideIcon name="grip-vertical" size={16} />
</div>
)}
{/* Rank badge — top 3 only, visible on resolved too */}
{rank <= 3 && <RankBadge rank={rank} />}
{/* ... rest of card content */}
</div>
</Reorder.Item>
);
}
```
**Key flag:** `dragListener={false}` on `Reorder.Item` disables the default "drag anywhere on the item" behavior, restricting drag to the handle only. This is the critical prop for handle-based reordering.
**Key flag:** `touch-none` Tailwind class on the handle prevents scroll interference on mobile (`touch-action: none`).
### Pattern 2: Fractional Indexing for sort_order
Fractional indexing avoids rewriting all rows on every drag. Only the moved item's `sort_order` changes.
```typescript
// Service function — reorderCandidates
// Computes new sort_order as midpoint between neighbors
export function reorderCandidates(
db: Db,
threadId: number,
orderedIds: number[],
): { success: boolean; error?: string } {
return db.transaction((tx) => {
// Verify thread is active
const thread = tx.select().from(threads).where(eq(threads.id, threadId)).get();
if (!thread || thread.status !== "active") {
return { success: false, error: "Thread not active" };
}
// Fetch current sort_orders keyed by id
const rows = tx
.select({ id: threadCandidates.id, sortOrder: threadCandidates.sortOrder })
.from(threadCandidates)
.where(eq(threadCandidates.threadId, threadId))
.all();
const sortMap = new Map(rows.map((r) => [r.id, r.sortOrder]));
const sortedExisting = [...sortMap.entries()].sort((a, b) => a[1] - b[1]);
// Re-assign spaced values in the requested order
// (Simpler than midpoint for full reorder; midpoint for single-item moves is optimization)
orderedIds.forEach((id, index) => {
const newOrder = (index + 1) * 1000;
tx.update(threadCandidates)
.set({ sortOrder: newOrder })
.where(eq(threadCandidates.id, id))
.run();
});
return { success: true };
});
}
```
**Note:** The CONTEXT.md specifies midpoint-only for single-item moves. For the PATCH endpoint
receiving a full ordered list, re-spacing at 1000 intervals is simpler and still correct.
Midpoint optimization matters if the API receives only (id, position) for a single move —
confirm which approach the planner selects.
### Pattern 3: tempItems Flicker Prevention
React Query refetch after mutation causes a visible reorder "snap back" unless tempItems absorbs the transition.
```typescript
// In ThreadDetailPage:
const [tempItems, setTempItems] = useState<typeof thread.candidates | null>(null);
const displayItems = tempItems ?? thread.candidates; // server data already sorted by sort_order
const reorderMutation = useReorderCandidates(threadId);
function handleReorder(newOrder: typeof thread.candidates) {
setTempItems(newOrder);
}
function handleDragEnd() {
if (!tempItems) return;
reorderMutation.mutate(
{ orderedIds: tempItems.map((c) => c.id) },
{
onSettled: () => setTempItems(null), // clear after server confirms or fails
}
);
}
```
### Pattern 4: Drizzle Migration + Data Backfill
Migration must add column AND backfill existing rows with spaced values to avoid all-zero sort_order.
```sql
-- Migration SQL (generated by bun run db:generate):
ALTER TABLE `thread_candidates` ADD `sort_order` real NOT NULL DEFAULT 0;
-- Data backfill SQL (run as separate statement in migration or seed script):
-- SQLite window functions assign rank per thread, multiply by 1000
UPDATE thread_candidates
SET sort_order = (
SELECT (ROW_NUMBER() OVER (PARTITION BY thread_id ORDER BY created_at)) * 1000
FROM thread_candidates AS tc2
WHERE tc2.id = thread_candidates.id
);
```
**SQLite version note:** SQLite supports window functions since version 3.25.0 (2018). Bun
ships with a recent SQLite — this query is safe. Verify with `bun -e "import { Database } from 'bun:sqlite'; const db = new Database(':memory:'); console.log(db.query('SELECT sqlite_version()').get())"`.
### Anti-Patterns to Avoid
- **Drag from anywhere on the card:** Without `dragListener={false}` on `Reorder.Item`, clicking the card to edit it triggers a drag. Always pair with `useDragControls`.
- **Ordering by integer with bulk update:** Updating all rows on every drag is O(n) writes. Use REAL (float) sort_order for midpoint single-update.
- **Storing order in the React Query cache only:** Sort order must persist to the server; local-only ordering is lost on page refresh.
- **Rendering `Reorder.Group` without `layout` on inner elements:** framer-motion needs `layout` prop on animated children to perform smooth gap animation. `Reorder.Item` handles this internally — do not nest another `motion.div` with conflicting layout props.
- **Missing `key` on Reorder.Item:** The key must be stable (candidate.id), not index — framer-motion uses it to track item identity across reorders.
---
## Don't Hand-Roll
| Problem | Don't Build | Use Instead | Why |
|---------|-------------|-------------|-----|
| Drag-to-reorder list | Custom mousedown/mousemove/mouseup handlers | `framer-motion` Reorder.Group/Item | Handles pointer capture, scroll suppression, layout animation, keyboard fallback |
| Drag handle restriction | Event.stopPropagation tricks | `useDragControls` + `dragListener={false}` | Official framer-motion API; handles touch events correctly |
| Smooth gap animation during drag | CSS transform calculations | `Reorder.Item` layout animation | Built-in spring physics; other items animate to fill the gap automatically |
| Sort order persistence strategy | Custom complex state | Fractional indexing (REAL column, midpoint) | One write per drop; no full-list rewrite; proven pattern from Linear/Trello |
---
## Common Pitfalls
### Pitfall 1: All-Zero sort_order After Migration
**What goes wrong:** ALTERing the column with `DEFAULT 0` sets all existing rows to 0. `ORDER BY sort_order` returns them in arbitrary order.
**Why it happens:** SQLite sets new column values to the DEFAULT for existing rows.
**How to avoid:** Run the window-function UPDATE backfill as part of the migration or immediately after.
**Warning signs:** Candidates render in seemingly random or creation-id order after migration.
### Pitfall 2: Drag Initiates on Card Click
**What goes wrong:** User clicks to open the edit panel and the card starts dragging instead.
**Why it happens:** `Reorder.Item` defaults `dragListener={true}` — any pointer-down on the item starts dragging.
**How to avoid:** Set `dragListener={false}` on `Reorder.Item` and use `useDragControls` to start drag only from the grip handle's `onPointerDown`.
**Warning signs:** Click on candidate name opens drag instead of edit panel.
### Pitfall 3: React Query Flicker After Save
**What goes wrong:** After `reorderMutation` completes and React Query refetches, candidates visually snap back to server order for a frame.
**Why it happens:** React Query invalidates and refetches; server returns the new order but there's a brief moment where old cache is used.
**How to avoid:** Use `tempItems` local state pattern. Render `tempItems ?? thread.candidates`. Clear `tempItems` in `onSettled` (not `onSuccess`) so it covers both success and error cases.
**Warning signs:** Items visually "jump" after a drop.
### Pitfall 4: touch-none Missing on Drag Handle
**What goes wrong:** On mobile, dragging the grip handle scrolls the page instead of reordering.
**Why it happens:** Browser default: `touch-action` allows scroll on pointer-down.
**How to avoid:** Add `className="touch-none"` (Tailwind) or `style={{ touchAction: "none" }}` on the drag handle element.
**Warning signs:** Mobile drag scrolls page; items don't reorder on touch devices.
### Pitfall 5: Resolved Thread Reorder Accepted by API
**What goes wrong:** A resolved thread's candidates can be reordered if the server does not check thread status.
**Why it happens:** The API endpoint receives a valid payload and processes it without checking `thread.status`.
**How to avoid:** In `reorderCandidates()` service, verify `thread.status === "active"` and return error if not. Match pattern of `resolveThread()` which already does this check.
**Warning signs:** PATCH succeeds on a resolved thread; RANK-05 test fails.
---
## Code Examples
### Zod Schema for Reorder Endpoint
```typescript
// src/shared/schemas.ts — add:
// Source: existing schema.ts patterns in project
export const reorderCandidatesSchema = z.object({
orderedIds: z.array(z.number().int().positive()).min(1),
});
```
### Shared Type
```typescript
// src/shared/types.ts — add:
export type ReorderCandidates = z.infer<typeof reorderCandidatesSchema>;
```
### Drizzle Schema Column
```typescript
// src/db/schema.ts — in threadCandidates table:
sortOrder: real("sort_order").notNull().default(0),
```
### getThreadWithCandidates ORDER BY Fix
```typescript
// src/server/services/thread.service.ts
// Change the candidateList query to order by sort_order:
.from(threadCandidates)
.innerJoin(categories, eq(threadCandidates.categoryId, categories.id))
.where(eq(threadCandidates.threadId, threadId))
.orderBy(threadCandidates.sortOrder) // add this
.all();
```
### createCandidate sort_order for New Candidates
```typescript
// src/server/services/thread.service.ts
// New candidates append to bottom — find current max and add 1000:
export function createCandidate(db, threadId, data) {
const maxRow = db
.select({ maxOrder: sql<number>`MAX(sort_order)` })
.from(threadCandidates)
.where(eq(threadCandidates.threadId, threadId))
.get();
const newSortOrder = (maxRow?.maxOrder ?? 0) + 1000;
return db.insert(threadCandidates).values({
...data,
sortOrder: newSortOrder,
}).returning().get();
}
```
### Hono PATCH Route
```typescript
// src/server/routes/threads.ts — add:
app.patch(
"/:id/candidates/reorder",
zValidator("json", reorderCandidatesSchema),
(c) => {
const db = c.get("db");
const threadId = Number(c.req.param("id"));
const { orderedIds } = c.req.valid("json");
const result = reorderCandidates(db, threadId, orderedIds);
if (!result.success) return c.json({ error: result.error }, 400);
return c.json({ success: true });
},
);
```
### useReorderCandidates Hook
```typescript
// src/client/hooks/useCandidates.ts — add:
export function useReorderCandidates(threadId: number) {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: { orderedIds: number[] }) =>
apiPatch<{ success: boolean }>(
`/api/threads/${threadId}/candidates/reorder`,
data,
),
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ["threads", threadId] });
},
});
}
```
### RankBadge Component (inline)
```typescript
// Inline in CandidateListItem or extract as small component
const RANK_STYLES = [
{ color: "#D4AF37", label: "1st" }, // gold
{ color: "#C0C0C0", label: "2nd" }, // silver
{ color: "#CD7F32", label: "3rd" }, // bronze
];
function RankBadge({ rank }: { rank: number }) {
if (rank > 3) return null;
const { color } = RANK_STYLES[rank - 1];
return (
<LucideIcon
name="medal"
size={16}
className="shrink-0"
style={{ color }}
/>
);
}
```
### tests/helpers/db.ts: thread_candidates table update
```sql
-- Add to CREATE TABLE thread_candidates in tests/helpers/db.ts:
sort_order REAL NOT NULL DEFAULT 0,
```
---
## State of the Art
| Old Approach | Current Approach | When Changed | Impact |
|--------------|------------------|--------------|--------|
| `react-beautiful-dnd` | framer-motion Reorder | framer-motion v5+ Reorder API | Simpler API, same bundle already present, maintained by Framer |
| Integer sort_order with bulk UPDATE | REAL (float) fractional indexing | Best practice since ~2015 (Linear, Figma) | O(1) writes per drag vs O(n) |
| "Save order" button | Auto-save on drop | UX convention | Reduces friction; matches Trello/Linear behavior |
**Deprecated/outdated:**
- `react-beautiful-dnd`: No longer actively maintained; framer-motion Reorder is the modern replacement in React 18+ projects.
---
## Open Questions
1. **Full-list reorder vs single-item fractional update in PATCH body**
- What we know: CONTEXT.md says "only the moved item gets a single UPDATE (midpoint between neighbors)" but also says PATCH receives `orderedIds` array
- What's unclear: If the server receives the full ordered list, re-spacing at 1000-intervals is simpler than computing midpoints server-side
- Recommendation: Accept full `orderedIds` array in PATCH, re-space all at 1000-intervals; this is correct and simpler. Midpoint is only an optimization for very large lists (not relevant here).
2. **View toggle persistence scope**
- What we know: CONTEXT.md says use Zustand `candidateViewMode` for view toggle
- What's unclear: Whether to also persist in `localStorage` across page refreshes
- Recommendation: Zustand in-memory only (resets to list on refresh) is sufficient; no localStorage needed unless user reports preference loss as pain point.
---
## Validation Architecture
### Test Framework
| Property | Value |
|----------|-------|
| Framework | Bun test (built-in) |
| Config file | none — `bun test` auto-discovers `*.test.ts` |
| Quick run command | `bun test tests/services/thread.service.test.ts` |
| Full suite command | `bun test` |
### Phase Requirements → Test Map
| Req ID | Behavior | Test Type | Automated Command | File Exists? |
|--------|----------|-----------|-------------------|-------------|
| RANK-01 | `reorderCandidates()` updates sort_order in DB in requested sequence | unit | `bun test tests/services/thread.service.test.ts` | ❌ Wave 0 (new test cases) |
| RANK-01 | `PATCH /api/threads/:id/candidates/reorder` returns 200 + reorders candidates | integration | `bun test tests/routes/threads.test.ts` | ❌ Wave 0 (new test cases) |
| RANK-02 | Rank badge rendering logic (index → medal color) | unit (component logic) | `bun test` | Manual-only — no component test infra |
| RANK-04 | `getThreadWithCandidates` returns candidates ordered by sort_order ascending | unit | `bun test tests/services/thread.service.test.ts` | ❌ Wave 0 |
| RANK-05 | `reorderCandidates()` returns error when thread is resolved | unit | `bun test tests/services/thread.service.test.ts` | ❌ Wave 0 |
| RANK-05 | `PATCH /api/threads/:id/candidates/reorder` returns 400 for resolved thread | integration | `bun test tests/routes/threads.test.ts` | ❌ Wave 0 |
### Sampling Rate
- **Per task commit:** `bun test tests/services/thread.service.test.ts`
- **Per wave merge:** `bun test`
- **Phase gate:** Full suite green before `/gsd:verify-work`
### Wave 0 Gaps
- [ ] New test cases in `tests/services/thread.service.test.ts` — covers RANK-01, RANK-04, RANK-05 service behavior
- [ ] New test cases in `tests/routes/threads.test.ts` — covers RANK-01, RANK-05 route behavior
- [ ] Update `tests/helpers/db.ts` CREATE TABLE for `thread_candidates` to add `sort_order REAL NOT NULL DEFAULT 0`
---
## Sources
### Primary (HIGH confidence)
- framer-motion `dist/types/index.d.ts` (v12.37.0 installed) — `Reorder.Group`, `Reorder.Item`, `useDragControls`, `dragListener` prop confirmed
- `src/client/lib/api.ts``apiPatch` confirmed available
- `src/client/lib/iconData.tsx` + lucide-react installed — `medal`, `grip-vertical`, `layout-list`, `layout-grid` icons confirmed via `bun -e` introspection
- `src/db/schema.ts` — current schema confirmed; `sort_order` column absent (needs migration)
- `tests/helpers/db.ts` — CREATE TABLE confirmed; needs `sort_order` column added
- `src/server/services/thread.service.ts``resolveThread()` pattern for status check reused in `reorderCandidates()`
- `.planning/phases/11-candidate-ranking/11-CONTEXT.md` — all locked decisions applied
### Secondary (MEDIUM confidence)
- framer-motion Reorder documentation patterns (consistent with installed type definitions)
- Fractional indexing / REAL sort_order pattern well-established in Linear, Trello, Figma implementations
### Tertiary (LOW confidence)
- None
---
## Metadata
**Confidence breakdown:**
- Standard stack: HIGH — all libraries confirmed installed and API-verified from local node_modules
- Architecture: HIGH — patterns derived from existing codebase + confirmed framer-motion type signatures
- Pitfalls: HIGH — derived from direct API analysis (dragListener, touch-none) and known SQLite migration behavior
**Research date:** 2026-03-16
**Valid until:** 2026-04-16 (stable dependencies; framer-motion Reorder API is mature)

View File

@@ -0,0 +1,79 @@
---
phase: 11
slug: candidate-ranking
status: draft
nyquist_compliant: false
wave_0_complete: false
created: 2026-03-16
---
# Phase 11 — Validation Strategy
> Per-phase validation contract for feedback sampling during execution.
---
## Test Infrastructure
| Property | Value |
|----------|-------|
| **Framework** | Bun test (built-in) |
| **Config file** | none — `bun test` auto-discovers `*.test.ts` |
| **Quick run command** | `bun test tests/services/thread.service.test.ts` |
| **Full suite command** | `bun test` |
| **Estimated runtime** | ~5 seconds |
---
## Sampling Rate
- **After every task commit:** Run `bun test tests/services/thread.service.test.ts`
- **After every plan wave:** Run `bun test`
- **Before `/gsd:verify-work`:** Full suite must be green
- **Max feedback latency:** 5 seconds
---
## Per-Task Verification Map
| Task ID | Plan | Wave | Requirement | Test Type | Automated Command | File Exists | Status |
|---------|------|------|-------------|-----------|-------------------|-------------|--------|
| TBD | 01 | 1 | RANK-01 | unit | `bun test tests/services/thread.service.test.ts` | ❌ W0 | ⬜ pending |
| TBD | 01 | 1 | RANK-01 | integration | `bun test tests/routes/threads.test.ts` | ❌ W0 | ⬜ pending |
| TBD | 01 | 1 | RANK-04 | unit | `bun test tests/services/thread.service.test.ts` | ❌ W0 | ⬜ pending |
| TBD | 01 | 1 | RANK-05 | unit | `bun test tests/services/thread.service.test.ts` | ❌ W0 | ⬜ pending |
| TBD | 01 | 1 | RANK-05 | integration | `bun test tests/routes/threads.test.ts` | ❌ W0 | ⬜ pending |
| TBD | 02 | 1 | RANK-02 | manual | Visual inspection | N/A | ⬜ pending |
*Status: ⬜ pending · ✅ green · ❌ red · ⚠️ flaky*
---
## Wave 0 Requirements
- [ ] New test cases in `tests/services/thread.service.test.ts` — covers RANK-01, RANK-04, RANK-05 service behavior
- [ ] New test cases in `tests/routes/threads.test.ts` — covers RANK-01, RANK-05 route behavior
- [ ] Update `tests/helpers/db.ts` CREATE TABLE for `thread_candidates` to add `sort_order REAL NOT NULL DEFAULT 0`
---
## Manual-Only Verifications
| Behavior | Requirement | Why Manual | Test Instructions |
|----------|-------------|------------|-------------------|
| Rank badge rendering (gold/silver/bronze medal icons on top 3) | RANK-02 | No component test infrastructure; visual verification required | Open thread with 3+ candidates, verify top 3 show medal icons with correct colors |
| Drag handle visibility and interaction | RANK-01 | Visual/interaction verification | Open active thread in list view, verify grip icons visible, drag to reorder |
| Drag handle absent on resolved thread | RANK-05 | Visual verification | Open resolved thread, verify no grip icons, rank badges still visible (static) |
---
## Validation Sign-Off
- [ ] All tasks have `<automated>` verify or Wave 0 dependencies
- [ ] Sampling continuity: no 3 consecutive tasks without automated verify
- [ ] Wave 0 covers all MISSING references
- [ ] No watch-mode flags
- [ ] Feedback latency < 5s
- [ ] `nyquist_compliant: true` set in frontmatter
**Approval:** pending

View File

@@ -0,0 +1,175 @@
---
phase: 11-candidate-ranking
verified: 2026-03-16T23:30:00Z
status: human_needed
score: 11/11 must-haves verified
re_verification:
previous_status: gaps_found
previous_score: 9/11
gaps_closed:
- "User can drag a candidate card to a new position in list view and it persists after page refresh — onPointerUp={handleDragEnd} is now correctly on the active <Reorder.Group> (line 198)"
gaps_remaining: []
regressions: []
human_verification:
- test: "Drag a candidate on an active thread and refresh"
expected: "Dragged order is preserved after page reload (new order loaded from server)"
why_human: "Smooth drag animation, gap preview, pointer-event timing, and actual persistence need visual inspection and interaction"
- test: "Drag handles visibility on resolved vs active threads"
expected: "Active threads show GripVertical drag handles; resolved threads show no drag handles but rank badges remain"
why_human: "CSS visibility and conditional rendering need visual verification"
- test: "Top 3 rank badges appearance"
expected: "Gold (#D4AF37), silver (#C0C0C0), bronze (#CD7F32) medal icons appear on positions 1, 2, 3 in both list and grid views"
why_human: "Color rendering and icon display need visual confirmation"
---
# Phase 11: Candidate Ranking Verification Report
**Phase Goal:** Users can drag candidates into a priority order that persists and is visually communicated
**Verified:** 2026-03-16T23:30:00Z
**Status:** human_needed
**Re-verification:** Yes — after gap closure
## Re-verification Summary
Previous status was `gaps_found` (score 9/11). The one critical blocker was:
> `handleDragEnd` (which calls `reorderMutation.mutate`) was wired to the resolved-thread `<div>` via `onPointerUp`, not to the active-thread `<Reorder.Group>`. Dragging updated `tempItems` visually but never fired the mutation.
**Fix verified:** `src/client/routes/threads/$threadId.tsx` line 198 now has `onPointerUp={handleDragEnd}` on the `<Reorder.Group>` for the active-thread path. The resolved-thread `<div>` (lines 217-233) has no `onPointerUp` handler. The fix is correct and complete.
All 11 truths now pass automated checks. 135/135 tests pass. No regressions detected.
---
## Goal Achievement
### Observable Truths
| # | Truth | Status | Evidence |
|---|-------|--------|----------|
| 1 | Candidates returned from getThreadWithCandidates are ordered by sort_order ascending | VERIFIED | `thread.service.ts:90` uses `.orderBy(asc(threadCandidates.sortOrder))` |
| 2 | Calling reorderCandidates with a new ID sequence updates sort_order values | VERIFIED | `reorderCandidates` loops `orderedIds`, sets `sortOrder: (i+1)*1000` per candidate in a transaction (`thread.service.ts:240`) |
| 3 | PATCH /api/threads/:id/candidates/reorder returns 200 and persists new order | VERIFIED | Route at `threads.ts:129-140`; Zod-validated; returns `{ success: true }` or 400 |
| 4 | reorderCandidates returns error when thread status is not active | VERIFIED | `thread.service.ts:234` checks `thread.status !== "active"`, returns `{ success: false, error: "Thread not active" }` |
| 5 | New candidates appended to end of rank (max sort_order + 1000) | VERIFIED | `createCandidate` queries MAX, sets `sortOrder: (maxRow?.maxOrder ?? 0) + 1000` (`thread.service.ts:150,171`) |
| 6 | User can drag a candidate card to a new position in list view and it persists after page refresh | VERIFIED (code) | `handleDragEnd` is now wired via `onPointerUp={handleDragEnd}` on `<Reorder.Group>` at `$threadId.tsx:198`. Mutation fires on pointer-up after drag. Persistence needs human confirmation. |
| 7 | Top 3 candidates display gold, silver, and bronze medal badges | VERIFIED (code) | `RankBadge` in `CandidateListItem.tsx:37-47` renders medal icon with `RANK_COLORS` for rank 1-3, returns null for rank > 3. Visual confirmation needed. |
| 8 | Rank badges appear in both list view and grid view | VERIFIED | `CandidateCard.tsx:165` renders `{rank != null && <RankBadge rank={rank} />}`; `$threadId.tsx:258` passes `rank={index + 1}` to all grid cards |
| 9 | Drag handles are hidden and drag is disabled on resolved threads | VERIFIED | `CandidateListItem.tsx:73` renders drag handle only if `isActive`; resolved threads render plain `<div>` (not `Reorder.Group`) at `$threadId.tsx:217` |
| 10 | Rank badges remain visible on resolved threads | VERIFIED | Resolved thread renders `<CandidateListItem isActive={false}>` which always renders `<RankBadge rank={rank} />` at line 85 |
| 11 | User can toggle between list and grid view with list as default | VERIFIED | `uiStore.ts:112` initializes `candidateViewMode: "list"`; toggle buttons in `$threadId.tsx:146-172` call `setCandidateViewMode` |
**Score:** 11/11 truths verified (all pass automated checks; 3 require human visual confirmation)
---
## Required Artifacts
### Plan 11-01 Artifacts
| Artifact | Expected | Status | Details |
|----------|----------|--------|---------|
| `src/db/schema.ts` | sortOrder REAL column on threadCandidates | VERIFIED | Line 64: `sortOrder: real("sort_order").notNull().default(0)` |
| `src/shared/schemas.ts` | reorderCandidatesSchema Zod validator | VERIFIED | Line 66: `export const reorderCandidatesSchema = z.object({ orderedIds: ... })` |
| `src/shared/types.ts` | ReorderCandidates type | VERIFIED | Line 37: `export type ReorderCandidates = z.infer<typeof reorderCandidatesSchema>` |
| `src/server/services/thread.service.ts` | reorderCandidates function exported | VERIFIED | Lines 220+: full implementation exported; sortOrder used at lines 90, 150, 171, 240 |
| `src/server/routes/threads.ts` | PATCH /:id/candidates/reorder endpoint | VERIFIED | Lines 129-140: registered with Zod validation |
| `tests/helpers/db.ts` | sort_order column in CREATE TABLE | VERIFIED | Line 60: `sort_order REAL NOT NULL DEFAULT 0` |
### Plan 11-02 Artifacts
| Artifact | Expected | Status | Details |
|----------|----------|--------|---------|
| `src/client/components/CandidateListItem.tsx` | Horizontal list card with drag handle and rank badge (min 60 lines) | VERIFIED | 211 lines; `Reorder.Item` with `useDragControls`, drag handle (lines 73-82), `RankBadge` (line 85) |
| `src/client/routes/threads/$threadId.tsx` | Reorder.Group wrapping + tempItems pattern + handleDragEnd on Reorder.Group | VERIFIED | `Reorder.Group` at line 194 with `onPointerUp={handleDragEnd}` at line 198; `tempItems` pattern at lines 28-37, 76 |
| `src/client/hooks/useCandidates.ts` | useReorderCandidates mutation hook | VERIFIED | Lines 66-78: calls `apiPatch` to `candidates/reorder`, invalidates query on settled |
| `src/client/stores/uiStore.ts` | candidateViewMode state | VERIFIED | Lines 53-54 (interface), 112-113 (implementation): default "list" |
| `src/client/components/CandidateCard.tsx` | RankBadge on grid cards | VERIFIED | Imports `RankBadge` from `CandidateListItem` (line 6); renders at line 165 when `rank != null` |
---
## Key Link Verification
### Plan 11-01 Key Links
| From | To | Via | Status | Details |
|------|----|-----|--------|---------|
| `threads.ts` | `thread.service.ts` | `reorderCandidates(db, threadId, orderedIds)` | WIRED | Line 136 imports and calls `reorderCandidates` |
| `threads.ts` | `schemas.ts` | `zValidator with reorderCandidatesSchema` | WIRED | Line 8 imports `reorderCandidatesSchema`; line 131 uses `zValidator("json", reorderCandidatesSchema)` |
| `thread.service.ts` | `schema.ts` | `threadCandidates.sortOrder in ORDER BY and UPDATE` | WIRED | Line 90 uses `asc(threadCandidates.sortOrder)`; line 240 sets `sortOrder: (i+1)*1000` |
### Plan 11-02 Key Links
| From | To | Via | Status | Details |
|------|----|-----|--------|---------|
| `threads/$threadId.tsx` | `useCandidates.ts` | `useReorderCandidates(threadId)` | WIRED | Line 7 imports, line 26 calls `useReorderCandidates(threadId)` |
| `useCandidates.ts` | `/api/threads/:id/candidates/reorder` | `apiPatch` | WIRED | Lines 70-73: `apiPatch<{ success: boolean }>(\`/api/threads/${threadId}/candidates/reorder\`, data)` |
| `threads/$threadId.tsx` | `framer-motion` | `Reorder.Group + Reorder.Item` | WIRED | Line 2 imports `{ Reorder }`; line 194 uses `<Reorder.Group>` |
| `CandidateListItem.tsx` | `framer-motion` | `Reorder.Item + useDragControls` | WIRED | Line 1 imports `{ Reorder, useDragControls }`; line 55 calls `useDragControls()` |
| `uiStore.ts` | `threads/$threadId.tsx` | `candidateViewMode state` | WIRED | Lines 23-24 consume `candidateViewMode`/`setCandidateViewMode`; lines 148-170 use them in toggle buttons |
| `Reorder.Group` | `reorderMutation` | `handleDragEnd via onPointerUp` | WIRED | `onPointerUp={handleDragEnd}` is on the active-thread `<Reorder.Group>` at line 198. `handleDragEnd` at lines 78-84 calls `reorderMutation.mutate`. Fix confirmed. |
---
## Requirements Coverage
| Requirement | Source Plan | Description | Status | Evidence |
|-------------|-------------|-------------|--------|----------|
| RANK-01 | 11-01, 11-02 | User can drag candidates to reorder priority ranking | SATISFIED | Drag via framer-motion `Reorder.Group`; `handleDragEnd` now wired at `onPointerUp` on active `Reorder.Group` (line 198); mutation fires `PATCH /api/threads/:id/candidates/reorder` |
| RANK-02 | 11-02 | Top 3 ranked candidates display rank badges (gold, silver, bronze) | SATISFIED | `RankBadge` renders medal icon with `RANK_COLORS`; used in both `CandidateListItem` (line 85) and `CandidateCard` (line 165) |
| RANK-04 | 11-01, 11-02 | Candidate rank order persists across sessions | SATISFIED | `sort_order` column in DB; `reorderCandidates` service updates it in a transaction; React Query invalidates on `onSettled` so next load fetches fresh sorted order |
| RANK-05 | 11-01, 11-02 | Drag handles and ranking disabled on resolved threads | SATISFIED | `CandidateListItem.tsx:73` renders drag handle only if `isActive`; resolved threads use plain `<div>` without `Reorder.Group`; service returns 400 if thread not active |
Note: RANK-03 (pros/cons fields) was handled in Phase 10 and is not part of Phase 11.
---
## Anti-Patterns Found
No blockers or warnings detected in the fixed code.
| File | Line | Pattern | Severity | Impact |
|------|------|---------|----------|--------|
| — | — | — | — | No anti-patterns found |
Previously identified blockers have been resolved: `onPointerUp={handleDragEnd}` is now correctly placed on the active `<Reorder.Group>` and absent from the resolved-thread `<div>`.
---
## Human Verification Required
### 1. Drag persistence after refresh
**Test:** Open an active thread with 3+ candidates, drag a candidate to a different position (e.g. drag position 3 to position 1), then refresh the page.
**Expected:** The new order is preserved after refresh. The `PATCH /api/threads/:id/candidates/reorder` call fires on pointer-up, and the invalidated React Query refetch loads the persisted sort order.
**Why human:** Real-time drag animation quality, gap animation between items, pointer-event timing, and the full round-trip to the server cannot be confirmed by static code analysis.
### 2. Gold/silver/bronze badge colors
**Test:** Open an active thread with 3+ candidates and view in list mode.
**Expected:** Position 1 shows a gold medal icon (`#D4AF37`), position 2 shows silver (`#C0C0C0`), position 3 shows bronze (`#CD7F32`). Positions 4 and above show no badge. Toggle to grid view and verify the same badges appear on the first 3 cards.
**Why human:** Hex color rendering accuracy and icon (medal) correctness need visual confirmation.
### 3. Drag handle visibility on resolved threads
**Test:** Navigate to a resolved thread in list view.
**Expected:** No GripVertical drag handle icons are visible. Gold/silver/bronze rank badges are still present on the top 3 candidates in their sorted order. Candidates cannot be dragged.
**Why human:** Conditional rendering of drag handles and static-only resolved state need visual verification.
---
## Gap Closure Confirmation
The single gap from the previous verification has been closed:
**Gap:** `onPointerUp={handleDragEnd}` was on the resolved-thread `<div>` (isActive=false path) only; the active `<Reorder.Group>` had no handler to trigger the mutation.
**Fix:** `src/client/routes/threads/$threadId.tsx` line 198 — `onPointerUp={handleDragEnd}` is now on `<Reorder.Group axis="y" values={displayItems} onReorder={setTempItems} onPointerUp={handleDragEnd}>`. The resolved-thread `<div>` at lines 217-233 has no `onPointerUp`. The wiring is correct.
**Regression check:** 135/135 tests pass. All previously-verified artifacts and key links remain intact.
---
_Verified: 2026-03-16T23:30:00Z_
_Verifier: Claude (gsd-verifier)_
_Re-verification: Yes — gap closure after previous gaps_found verdict_

File diff suppressed because it is too large Load Diff

View File

@@ -1,244 +1,262 @@
# Feature Research: v1.2 Collection Power-Ups # Feature Research
**Domain:** Gear management -- search/filter, weight classification, weight visualization, candidate status tracking, weight unit selection **Domain:** Gear management — candidate comparison, setup impact preview, and candidate ranking
**Researched:** 2026-03-16 **Researched:** 2026-03-16
**Confidence:** HIGH **Confidence:** HIGH (existing codebase fully understood; UX patterns verified via multiple sources)
**Scope:** New features only. v1.0/v1.1 features (item CRUD, categories, threads, setups, dashboard, onboarding, images, icons) are already shipped.
## Table Stakes ---
Features that gear management users expect. Missing these makes the app feel incomplete for collections beyond ~20 items. ## Context
| Feature | Why Expected | Complexity | Dependencies on Existing | This is a subsequent milestone research file for **v1.3 Research & Decision Tools**.
|---------|--------------|------------|--------------------------| The features below are **additive** to v1.2. All three features operate within the existing
| Search items by name | Every competitor with an inventory concept has search. Hikt highlights "searchable digital closet." PackLight Supporter Edition has inventory search. Once a collection exceeds 30 items, scrolling to find something is painful. LighterPack notably lacks this and users complain. | LOW | Items query (`useItems`), collection view. Client-side only -- no API changes needed for <500 items. | `threads/$threadId` page and its data model.
| Filter items by category | Already partially exists in Planning view (category dropdown for threads). Collection view groups by category visually but has no filter. Users need to quickly narrow to "show me just my shelter items." | LOW | Categories query (`useCategories`), collection view. Client-side filtering of already-fetched items. |
| Weight unit selection (g, oz, lb, kg) | Universal across all competitors. LighterPack supports toggling between g/oz/lb/kg. Packrat offers per-item input in any unit with display conversion. Backpacking Light forum users specifically praise apps that let you "enter item weights in grams and switch the entire display to lbs & oz." Gear specs come in mixed units -- a sleeping bag in lbs/oz, a fuel canister in grams. | LOW | `formatWeight()` in `lib/formatters.ts`, `settings` table (already exists with key/value store), TotalsBar, ItemCard, CandidateCard, SetupCard -- every weight display. |
| Weight classification (base/worn/consumable) | LighterPack pioneered this three-way split and it is now universal. Hikt, PackLight, Packstack, HikeLite, 99Boulders spreadsheet -- all support it. "Base weight" is the core metric of the ultralight community. Without classification, weight totals are a single number with no actionable insight. | MEDIUM | `setup_items` join table (needs new column), setup detail view, setup service, totals computation. Schema migration required. |
## Differentiators **Existing data model relevant to this milestone:**
- `threadCandidates`: id, threadId, name, weightGrams, priceCents, categoryId, notes, productUrl, imageFilename, status — no rank, pros, or cons columns yet
- `setups` + `setupItems`: stores weight/cost per setup item with classification (base/worn/consumable)
- `getSetupWithItems` already returns `classification` per item — available for impact preview
Features that set GearBox apart or add meaningful value beyond what competitors offer. ---
| Feature | Value Proposition | Complexity | Dependencies on Existing | ## Feature Landscape
|---------|-------------------|------------|--------------------------|
| Weight distribution visualization (donut/pie chart) | LighterPack's pie chart is iconic and widely cited as its best feature. "The pie chart at the top is a great way to visualize how your pack weight breaks down by category." PackLight uses bar graphs. GearBox can do this per-setup with a modern donut chart that also shows base/worn/consumable breakdown -- a combination no competitor offers cleanly. | MEDIUM | Totals data (already computed server-side per category), weight classification (new), a chart library (react-minimal-pie-chart at 2kB or Recharts). |
| Candidate status tracking (researching/ordered/arrived) | No competitor has this. Research confirmed: the specific workflow of tracking purchase status through stages does not exist in any gear management app. This is unique to GearBox's planning thread concept. It makes threads a living document of the purchase lifecycle, not just a comparison tool. | LOW | `thread_candidates` table (needs new `status` column), CandidateCard, CandidateForm. Simple text field migration. |
| Planning category filter with icon-aware dropdown | Already partially built as a plain `<select>` in PlanningView. Upgrading to show Lucide icons alongside category names makes filtering feel polished and consistent with the icon picker UX. | LOW | Existing CategoryPicker component pattern, existing category filter state in PlanningView. |
| Weight classification shown per-setup (not global) | In LighterPack, worn/consumable flags are per-item within a list. In GearBox, items exist in a global collection and appear in multiple setups. The same jacket might be "worn" in a summer bikepacking setup but "base weight" (packed in panniers) in a winter setup. Classification belongs on the setup_items join, not on the item itself. This is architecturally superior to competitors. | MEDIUM | `setup_items` table schema, setup sync endpoint, setup detail UI. |
## Anti-Features ### Table Stakes (Users Expect These)
Features to explicitly NOT build in this milestone. Features users assume exist in any comparison or decision tool. Missing these makes the thread
detail page feel incomplete as a decision workspace.
| Anti-Feature | Why Avoid | What to Do Instead | | Feature | Why Expected | Complexity | Notes |
|--------------|-----------|-------------------| |---------|--------------|------------|-------|
| Per-item weight input in multiple units | Packrat lets you enter "2 lb 3 oz" per item. This adds parsing complexity, ambiguous storage, and conversion bugs. | Store grams internally (already done). Convert for display only. Users enter grams; if they want oz input, they convert mentally or we add a unit toggle on the input field later. | | Side-by-side comparison view | Any comparison tool in any domain shows attributes aligned per-column. Card grid (current) forces mental juggling between candidates. E-commerce, spec sheets, gear apps — all use tabular layout for comparison. | MEDIUM | Rows = attributes (image, name, weight, price, status, notes, link), columns = candidates. Sticky attribute-label column during horizontal scroll. Max 34 candidates usable on desktop; 2 on mobile. Toggle between grid view (current) and table view. |
| Interactive chart drill-down (click to zoom) | LighterPack lets you click pie slices to zoom into category breakdowns. Adds significant interaction complexity. | Static donut chart with hover tooltips. Drill-down is a future enhancement. | | Weight delta per candidate | Gear apps (LighterPack, GearGrams) display weight totals prominently. Users replacing an item need the delta, not just the raw weight of the candidate. | LOW | Pure client-side computation: `candidate.weightGrams - existingItemWeight`. No API call needed if setup data already loaded via `useSetup`. |
| Weight goals / targets ("your target base weight is X") | Some apps show ultralight thresholds. Adds opinionated norms that conflict with hobby-agnostic design. | Show the numbers. Let users interpret them. | | Cost delta per candidate | Same reasoning as weight delta. A purchase decision is always the weight vs. cost tradeoff. | LOW | Same pattern as weight delta. Color-coded: green for savings/lighter, red for more expensive/heavier. |
| Custom weight classification labels | Beyond base/worn/consumable. Some users want "luxury" or "shared" categories. | Three classifications cover 95% of use cases. The notes field handles edge cases. | | Setup selector for impact preview | User needs to pick which setup to compute deltas against — not all setups contain the same category of item being replaced. | MEDIUM | Dropdown of setup names populated from `useSetups()`. When selected, loads setup via `useSetup(id)`. "No setup selected" state shows raw candidate values only, no delta. |
| Server-side search / full-text search | SQLite FTS5 or similar. Premature for a single-user app with <1000 items. | Client-side filtering of the already-fetched items array. Simpler, faster for the expected data scale. |
| Worn/consumable at the global item level | Tempting to add a classification column to the `items` table. | Classification varies by setup context. A rain shell is "worn" on a day hike but "base weight" (packed) on a bike tour. The join table `setup_items` is the correct location. |
## Feature Details ### Differentiators (Competitive Advantage)
### 1. Search and Filter Features not found in LighterPack, GearGrams, or any other gear app. Directly serve the
"decide between candidates" workflow that is unique to GearBox.
**What users expect:** A text input that filters visible items by name as you type. A category dropdown or pill selector to filter by category. Both should work together (search within a category). | Feature | Value Proposition | Complexity | Notes |
|---------|-------------------|------------|-------|
| Drag-to-rank ordering | Makes priority explicit without a numeric input. Ranking communicates "this is my current top pick." Maps to how users mentally stack-rank options during research. No competitor has this in the gear domain. | MEDIUM | `@dnd-kit/sortable` is the current standard (actively maintained; `react-beautiful-dnd` is abandoned as of 2025). Requires new `rank` integer column on `threadCandidates`. Persist order via PATCH endpoint. |
| Per-candidate pros/cons fields | Freeform text capturing the reasoning behind ranking. LighterPack and GearGrams have notes per item but no structured decision rationale. Differentiates GearBox as a decision tool, not just a list tracker. | LOW | Two textarea fields per candidate. New `pros` and `cons` text columns on `threadCandidates`. Visible in comparison view rows and candidate edit panel. |
| Impact preview with category-matched delta | Setup items have a category. The most meaningful delta is weight saved within the same category (e.g., comparing sleeping pads, subtract current sleeping pad weight from setup total). More actionable than comparing against the entire setup total. | MEDIUM | Use `candidate.categoryId` to find matching setup items and compute delta. Edge case: no item of that category in the setup → show "not in setup." Data already available from `getSetupWithItems`. |
**Domain patterns observed:** ### Anti-Features (Commonly Requested, Often Problematic)
- Hikt: Searchable gear closet with category and specification filters
- PackLight: Inventory search (premium feature) with category organization
- Backpacking Light Calculator: Search filter in gear locker and within packs
- LighterPack: No text search -- widely considered a gap
**Recommended implementation:** | Feature | Why Requested | Why Problematic | Alternative |
- Sticky search bar above the collection grid with a text input and category filter dropdown |---------|---------------|-----------------|-------------|
- Client-side filtering using `Array.filter()` on the items array from `useItems()` | Custom comparison attributes | "I want to compare battery life, durability, color..." | PROJECT.md explicitly rejects this as a complexity trap. Custom attributes require schema generalization, dynamic rendering, and data entry friction for every candidate. | Notes field and pros/cons fields cover the remaining use cases. |
- Case-insensitive substring match on item name | Score/rating calculation | Automatically rank candidates by computed score | Score algorithms require encoding the user's weight-vs-price preference — personalization complexity. Users distrust opaque scores. | Manual drag-to-rank expresses the user's own weighting without encoding it in an algorithm. |
- Category filter as pills or dropdown (reuse the pattern from PlanningView) | Side-by-side comparison across threads | Compare candidates from different research threads | Candidates belong to different purchase decisions — mixing them is conceptually incoherent. Different categories are never apples-to-apples. | Thread remains the scope boundary. Cross-thread planning is what setups are for. |
- URL search params for filter state (shareable filtered views, consistent with existing `?tab=` pattern) | Comparison permalink/share | Share a comparison view URL | GearBox is single-user, no auth for v1. Sharing requires auth, user management, public/private visibility. | Out of scope for v1 per PROJECT.md. Future feature. |
- Clear filters button when any filter is active | Classification-aware impact preview as MVP requirement | Show delta broken down by base/worn/consumable | While data is available, the classification breakdown adds significant UI complexity. The flat delta answers "will this make my setup lighter?" which is 90% of the use case. | Flat delta for MVP. Classification-aware breakdown as a follow-up enhancement (P2). |
- Result count displayed ("showing 12 of 47 items")
**Complexity:** LOW. Pure client-side. No API changes. ~100 lines of new component code plus minor state management. ---
### 2. Weight Classification (Base/Worn/Consumable)
**What users expect:** Every item in a setup can be marked as one of three types:
- **Base weight**: Items carried in the pack. The fixed weight of your loadout. This is the primary metric ultralight hikers optimize.
- **Worn weight**: Items on your body while hiking (shoes, primary clothing, watch, sunglasses). Not counted toward pack weight but tracked as part of "skin-out" weight.
- **Consumable weight**: Items that deplete during a trip (food, water, fuel, sunscreen). Variable weight not counted toward base weight.
**Domain patterns observed:**
- LighterPack: Per-item icons (shirt icon = worn, flame icon = consumable). Default = base weight. Totals show base/worn/consumable/total separately.
- Packstack: "Separates base weight, worn weight, and consumables so you always know exactly what your pack weighs."
- HikeLite: "Mark heavy clothing as worn to see your true base weight."
- 99Boulders spreadsheet: Column with dropdown: WORN / CONSUMABLE / - (dash = base).
**Critical design decision -- classification scope:**
In LighterPack, items only exist within lists, so the flag is per-item-per-list inherently. In GearBox, items live in a global collection and are referenced by setups. The classification MUST live on the `setup_items` join table, not on the `items` table. Reason: the same item can have different classifications in different setups (a puffy jacket is "worn" on a cold-weather hike but "base weight" in a three-season setup where it stays packed).
**Recommended implementation:**
- Add `classification TEXT NOT NULL DEFAULT 'base'` column to `setup_items` table
- Valid values: `"base"`, `"worn"`, `"consumable"`
- Default to `"base"` (most items are base weight; this matches user expectation)
- UI: Small segmented control or icon toggle on each item within the setup detail view
- LighterPack-style icons: backpack icon (base), shirt icon (worn), flame/droplet icon (consumable)
- Setup totals recalculated: show base weight, worn weight, consumable weight, and total (skin-out) as four separate numbers
- SQL aggregation update: `SUM(CASE WHEN classification = 'base' THEN weight_grams ELSE 0 END)` etc.
**Complexity:** MEDIUM. Requires schema migration, API changes (sync endpoint must accept classification), service layer updates, and UI for per-item classification within setup views.
### 3. Weight Distribution Visualization
**What users expect:** A chart showing where the weight is. By category is standard. By classification (base/worn/consumable) is a bonus.
**Domain patterns observed:**
- LighterPack: Color-coded pie chart by category, click to drill down. "As you enter each piece of equipment, a pie chart immediately displays a breakdown of where your weight is appropriated." Colors are customizable per category.
- PackLight: Bar graph comparing category weights
- OutPack: Category breakdown graph
**Two chart contexts:**
1. **Collection-level**: Weight by category across the whole collection. Uses existing `useTotals()` data.
2. **Setup-level**: Weight by category AND by classification within a specific setup. More useful because setups represent actual loadouts.
**Recommended implementation:**
- Donut chart (modern feel, consistent with GearBox's minimalist aesthetic)
- Library: `react-minimal-pie-chart` (2kB gzipped, zero dependencies, SVG-based) over Recharts (40kB+). GearBox only needs pie/donut -- no line charts, bar charts, etc.
- Setup detail view: Donut chart showing weight by category, with center text showing total base weight
- Optional toggle: switch between "by category" and "by classification" views
- Color assignment: Derive from category or classification type (base = neutral gray, worn = blue, consumable = amber)
- Hover tooltips showing category name, weight, and percentage
- Responsive: Chart should work on mobile viewports
**Complexity:** MEDIUM. New dependency, new component, integration with totals data. The chart itself is straightforward; the data aggregation for per-setup-per-category-per-classification is the main work.
### 4. Candidate Status Tracking
**What users expect:** This is novel -- no competitor has it. The workflow mirrors real purchase behavior:
1. **Researching** (default): You found this product, added it to a thread, and are evaluating it
2. **Ordered**: You decided to buy it and placed an order
3. **Arrived**: The product has been delivered. Ready for thread resolution.
**Why this matters:** Without status tracking, threads are a flat list of candidates. With it, threads become a living purchase tracker. A user can see at a glance "I ordered the Nemo Tensor, still researching two other pads."
**Recommended implementation:**
- Add `status TEXT NOT NULL DEFAULT 'researching'` column to `thread_candidates` table
- Valid values: `"researching"`, `"ordered"`, `"arrived"`
- UI: Status badge on CandidateCard (small colored pill, similar to existing weight/price badges)
- Color scheme: researching = gray/neutral, ordered = amber/yellow, arrived = green
- Status change: Dropdown or simple click-to-cycle on the candidate card
- Thread-level summary: Show count by status ("2 researching, 1 ordered")
- When resolving a thread, only candidates with status "arrived" should be selectable as winners (soft constraint -- show a warning, not a hard block, since users may resolve with a "researching" candidate they just bought in-store)
**Complexity:** LOW. Simple column addition, enum-like text field, badge rendering, optional status transition UI.
### 5. Weight Unit Selection
**What users expect:** Choose a preferred unit (grams, ounces, pounds, kilograms) and have ALL weight displays in the app use that unit. LighterPack toggles between g/oz/lb/kg at the top level. The BPL Calculator app lets you "enter item weights in grams and switch the entire display to lbs & oz."
**Domain patterns observed:**
- LighterPack: Toggle at list level between lb/oz/g/kg. Only changes summary display, not per-item display.
- Packrat: "Input items in different units, choose how they're displayed, and freely convert between them."
- BPL Calculator: Global settings change, applied to all displays
- WeighMyGear: Input locked to grams, less intuitive
**Recommended implementation:**
- Store preference in existing `settings` table as `{ key: "weightUnit", value: "g" }` (default: grams)
- Supported units: `g` (grams), `oz` (ounces), `lb` (pounds + ounces), `kg` (kilograms)
- Conversion constants: 1 oz = 28.3495g, 1 lb = 453.592g, 1 kg = 1000g
- Display format per unit:
- `g`: "450g" (round to integer)
- `oz`: "15.9 oz" (one decimal)
- `lb`: "2 lb 3 oz" (pounds + remainder ounces, traditional format)
- `kg`: "1.45 kg" (two decimals)
- Update `formatWeight()` to accept unit parameter or read from a React context/hook
- Settings UI: Simple dropdown or segmented control, accessible from a settings page or inline in the TotalsBar
- Internal storage stays as grams (already the case with `weight_grams` column)
- Affects: TotalsBar, ItemCard, CandidateCard, SetupCard, CategoryHeader, setup detail view, chart tooltips
**Complexity:** LOW. No schema changes. Update the `formatWeight()` function, add a settings hook, propagate the unit to all display points. The main effort is touching every component that displays weight (there are ~6-8 call sites).
### 6. Planning Category Filter with Icon-Aware Dropdown
**What users expect:** The existing category filter in PlanningView is a plain `<select>` without icons. Since categories now have Lucide icons (v1.1), the filter should show them.
**Recommended implementation:**
- Replace the native `<select>` with a custom dropdown component that renders `<LucideIcon>` alongside category names
- Match the visual style of the CategoryPicker used in thread creation
- Same functionality, better visual consistency
**Complexity:** LOW. UI-only change. Replace ~20 lines of `<select>` with a custom dropdown component.
## Feature Dependencies ## Feature Dependencies
``` ```
[Weight Unit Selection] --independent-- (affects all displays, no schema changes) [Side-by-side comparison view]
| └──requires──> [All candidate fields visible in UI]
+-- should ship first (all other features benefit from correct unit display) (weightGrams, priceCents, notes, productUrl already in schema)
└──enhances──> [Pros/cons fields] (displayed as comparison rows)
└──enhances──> [Drag-to-rank] (rank number shown as position in comparison columns)
└──enhances──> [Impact preview] (delta displayed per-column inline)
[Search & Filter] --independent-- (pure client-side, no schema changes) [Impact preview (weight + cost delta)]
| └──requires──> [Setup selector] (user picks which setup to compute delta against)
+-- no dependencies on other v1.2 features └──requires──> [Setup data client-side] (useSetup hook already exists, no new API)
└──requires──> [Candidate weight/price data] (already in threadCandidates schema)
[Candidate Status Tracking] --independent-- (schema change on thread_candidates only) [Setup selector]
| └──requires──> [useSetups() hook] (already exists in src/client/hooks/useSetups.ts)
+-- no dependencies on other v1.2 features └──requires──> [useSetup(id) hook] (already exists, loads items with classification)
[Weight Classification] --depends-on--> [existing setup_items table] [Drag-to-rank]
| └──requires──> [rank INTEGER column on threadCandidates] (new — schema migration)
+-- schema migration on setup_items └──requires──> [PATCH /api/threads/:id/candidates/rank endpoint] (new API endpoint)
+-- enables [Weight Distribution Visualization] └──enhances──> [Side-by-side comparison] (rank visible as position indicator)
└──enhances──> [Card grid view] (rank badge on each CandidateCard)
[Weight Distribution Visualization] --depends-on--> [Weight Classification] [Pros/cons fields]
| └──requires──> [pros TEXT column on threadCandidates] (new — schema migration)
+-- needs classification data to show base/worn/consumable breakdown └──requires──> [cons TEXT column on threadCandidates] (new — schema migration)
+-- can show by-category chart without classification (partial value) └──requires──> [updateCandidateSchema extended] (add pros/cons to Zod schema)
+-- new dependency: react-minimal-pie-chart └──enhances──> [CandidateForm edit panel] (new textarea fields)
└──enhances──> [Side-by-side comparison] (pros/cons rows in comparison table)
[Planning Category Filter Icons] --depends-on--> [existing CategoryPicker pattern]
|
+-- pure UI enhancement
``` ```
### Implementation Order Rationale ### Dependency Notes
1. **Weight Unit Selection** first -- touches formatting everywhere, foundational for all subsequent weight displays - **Side-by-side comparison is independent of schema changes.** It can be built using
2. **Search & Filter** second -- standalone, immediately useful, low risk existing candidate data. No migrations required. Delivers value immediately.
3. **Candidate Status Tracking** third -- standalone schema change, simple - **Impact preview is independent of schema changes.** Uses existing `useSetups` and
4. **Planning Category Filter** fourth -- quick UI polish `useSetup` hooks client-side. Delta computation is pure math in the component.
5. **Weight Classification** fifth -- most complex schema change, affects setup data model No new API endpoint needed for MVP.
6. **Weight Distribution Visualization** last -- depends on classification, needs chart library, highest UI complexity - **Drag-to-rank requires schema migration.** `rank` column must be added to
`threadCandidates`. Default ordering on migration = `createdAt` ascending.
- **Pros/cons requires schema migration.** Two nullable `text` columns on
`threadCandidates`. Low risk — nullable, backwards compatible.
- **Comparison view enhances everything.** Best delivered after rank and pros/cons
schema work is done so the full table is useful from day one.
## Complexity Summary ---
| Feature | Schema Change | API Change | New Dependency | UI Scope | Overall | ## MVP Definition
|---------|---------------|------------|----------------|----------|---------|
| Search & Filter | None | None | None | Collection view only | LOW | ### Launch With (v1.3 milestone)
| Weight Unit Selection | None (uses settings) | None (settings API exists) | None | All weight displays (~8 components) | LOW |
| Candidate Status Tracking | `thread_candidates.status` column | Update candidate CRUD | None | CandidateCard, CandidateForm | LOW | - [ ] **Side-by-side comparison view** — Core deliverable. Replace mental juggling of the card
| Planning Category Filter | None | None | None | PlanningView dropdown | LOW | grid with a scannable table. No schema changes. Highest ROI, lowest risk.
| Weight Classification | `setup_items.classification` column | Update setup sync + detail endpoints | None | Setup detail view | MEDIUM | - [ ] **Impact preview: flat weight + cost delta per candidate** — Shows `+/- X g` and
| Weight Distribution Chart | None | Possibly new totals endpoint | react-minimal-pie-chart (~2kB) | New chart component | MEDIUM | `+/- $Y` vs. the selected setup. Pure client-side math. No schema changes.
- [ ] **Setup selector** — Dropdown of user's setups. Required for impact preview. One
interaction: pick a setup, see deltas update.
- [ ] **Drag-to-rank** — Requires `rank` column migration. `@dnd-kit/sortable` handles
the drag UX. Persist via new PATCH endpoint.
- [ ] **Pros/cons text fields** — Requires `pros` + `cons` column migration. Trivially low
implementation complexity once schema is in place.
### Add After Validation (v1.x)
- [ ] **Classification-aware impact preview** — Delta broken down by base/worn/consumable.
Higher complexity UI. Add once flat delta is validated as useful.
Trigger: user feedback requests "which classification does this affect?"
- [ ] **Rank indicator on card grid** — Small "1st", "2nd" badge on CandidateCard.
Trigger: users express confusion about which candidate is ranked first without entering
comparison view.
- [ ] **Comparison view on mobile** — Horizontal scroll works but is not ideal. Consider
attribute-focus swipe view. Trigger: usage data shows mobile traffic on thread pages.
### Future Consideration (v2+)
- [ ] **Comparison permalink** — Requires auth/multi-user work first.
- [ ] **Auto-fill from product URL** — Fragile scraping, rejected in PROJECT.md.
- [ ] **Custom comparison attributes** — Explicitly rejected in PROJECT.md.
---
## Feature Prioritization Matrix
| Feature | User Value | Implementation Cost | Priority |
|---------|------------|---------------------|----------|
| Side-by-side comparison view | HIGH | MEDIUM | P1 |
| Setup impact preview (flat delta) | HIGH | LOW | P1 |
| Setup selector for impact preview | HIGH | LOW | P1 |
| Drag-to-rank ordering | MEDIUM | MEDIUM | P1 |
| Pros/cons text fields | MEDIUM | LOW | P1 |
| Classification-aware impact preview | MEDIUM | HIGH | P2 |
| Rank indicator on card grid | LOW | LOW | P2 |
| Mobile-optimized comparison view | LOW | MEDIUM | P3 |
**Priority key:**
- P1: Must have for this milestone launch
- P2: Should have, add when possible
- P3: Nice to have, future consideration
---
## Competitor Feature Analysis
| Feature | LighterPack | GearGrams | OutPack | Our Approach |
|---------|-------------|-----------|---------|--------------|
| Side-by-side candidate comparison | None (list only) | None (library + trip list) | None | Inline comparison table on thread detail page, toggle from grid view |
| Impact preview / weight delta | None (duplicate lists manually to compare) | None (no delta concept) | None | Per-candidate delta vs. selected setup, computed client-side |
| Candidate ranking | None | None | None | Drag-to-rank with persisted `rank` column |
| Pros/cons annotation | None (notes field only) | None (notes field only) | None | Dedicated `pros` and `cons` fields separate from general notes |
| Status tracking | None | "wish list" item flag only | None | Already built in v1.2 (researching/ordered/arrived) |
**Key insight:** No existing gear management tool has a comparison view, delta preview, or
ranking system for candidates within a research thread. This is an unmet-need gap.
The features are adapted from general product comparison UX (e-commerce) to the gear domain.
---
## Implementation Notes by Feature
### Side-by-side Comparison View
- Rendered as a transposed table: rows = attribute labels, columns = candidates.
- Rows: Image (thumbnail), Name, Weight, Price, Status, Notes, Link, Pros, Cons, Rank, Impact Delta (weight), Impact Delta (cost).
- Sticky first column (attribute label) while candidate columns scroll horizontally for 3+.
- Candidate images at reduced aspect ratio (square thumbnail ~80px).
- Weight/price cells use existing `formatWeight` / `formatPrice` formatters with the user's preferred unit.
- Status cell reuses existing `StatusBadge` component.
- "Pick as winner" action available per column (reuses existing `openResolveDialog`).
- Toggle between grid view (current) and table view. Preserve both modes. Default to grid;
user activates comparison mode explicitly.
- Comparison mode is a UI state only (Zustand or local component state) — no URL change needed.
### Impact Preview
- Setup selector: `<select>` or custom dropdown populated from `useSetups()`.
- On selection: load setup via `useSetup(id)`. Compute delta per candidate:
`candidate.weightGrams - matchingCategoryWeight` where `matchingCategoryWeight` is the
sum of setup item weights in the same category as the thread.
- Delta display: colored pill on each candidate column in comparison view:
- Negative delta (lighter) = green, prefixed with ""
- Positive delta (heavier) = red, prefixed with "+"
- Zero = neutral gray
- Same pattern for cost delta.
- "No setup selected" state = no delta row shown.
- "Category not in setup" state = "not in setup" label instead of delta.
- No new API endpoints required. All data is client-side once setups are loaded.
### Drag-to-Rank
- `@dnd-kit/sortable` with `SortableContext` wrapping the candidate list.
- `useSortable` hook per candidate with a drag handle (Lucide `grip-vertical` icon).
- Drag handle visible always (not hover-only) so the affordance is clear.
- On `onDragEnd`: recompute ranks using `arrayMove()`, call
`PATCH /api/threads/:threadId/candidates/rank` with `{ orderedIds: number[] }`.
- Server endpoint: bulk update `rank` for each candidate ID in the thread atomically.
- `rank` column: `INTEGER` nullable. Null = unranked (treated as lowest rank). Default to
`createdAt` order on first explicit rank save.
- Rank number badge: displayed on each CandidateCard corner (small gray circle, "1", "2", "3").
- Works in both grid view and comparison view.
### Pros/Cons Fields
- Two `textarea` inputs added to the existing `CandidateForm` (slide-out panel).
- Labels: "Pros" and "Cons" — plain text, no icons.
- Displayed below the existing Notes field in the form.
- Extend `updateCandidateSchema` with `pros: z.string().optional()` and `cons: z.string().optional()`.
- In comparison table: pros and cons rows display as plain text, line-wrapped.
- In card grid: pros/cons not shown on card surface (too much density). Visible only in edit
panel and comparison view.
### Schema Changes Required
Two schema migrations needed for this milestone:
```sql
-- Migration 1: Candidate rank
ALTER TABLE thread_candidates ADD COLUMN rank INTEGER;
-- Migration 2: Candidate pros/cons
ALTER TABLE thread_candidates ADD COLUMN pros TEXT;
ALTER TABLE thread_candidates ADD COLUMN cons TEXT;
```
Both columns are nullable and backwards compatible. Existing candidates get `NULL` values.
UI treats `NULL` rank as unranked, `NULL` pros/cons as empty string.
---
## Sources ## Sources
- [LighterPack](https://lighterpack.com/) -- weight classification and pie chart visualization patterns - [Designing The Perfect Feature Comparison Table — Smashing Magazine](https://www.smashingmagazine.com/2017/08/designing-perfect-feature-comparison-table/) — table layout patterns, sticky headers, progressive disclosure (HIGH confidence)
- [LighterPack Tutorial (99Boulders)](https://www.99boulders.com/lighterpack-tutorial) -- detailed feature walkthrough - [Comparison Tables for Products, Services, and Features — Nielsen Norman Group](https://www.nngroup.com/articles/comparison-tables/) — information architecture for comparison, anti-patterns (HIGH confidence)
- [LighterPack Tutorial (Backpackers.com)](https://backpackers.com/blog/how-to-calculate-backpack-weight-with-lighterpack/) -- base/worn/consumable definitions - [The Ultimate Drag-and-Drop Toolkit for React: @dnd-kit — BrightCoding (2025)](https://www.blog.brightcoding.dev/2025/08/21/the-ultimate-drag-and-drop-toolkit-for-react-a-deep-dive-into-dnd-kit/) — confirmed dnd-kit as current standard, react-beautiful-dnd abandoned (HIGH confidence)
- [Hikt](https://hikt.app/) -- searchable gear closet, base vs worn weight display - [dnd-kit Sortable Docs](https://docs.dndkit.com/presets/sortable) — SortableContext, useSortable, arrayMove patterns (HIGH confidence)
- [PackLight (iOS)](https://apps.apple.com/us/app/packlight-for-backpacking/id1054845207) -- search, custom categories, bar graph visualization - [Ultralight: The Gear Tracking App I'm Leaving LighterPack For — TrailsMag](https://trailsmag.net/blogs/hiker-box/ultralight-the-gear-tracking-app-i-m-leaving-lighterpack-for) — LighterPack feature gap analysis (MEDIUM confidence)
- [Packstack](https://www.packstack.io/) -- base/worn/consumable weight separation - [Comparing products: UX design best practices — Contentsquare](https://contentsquare.com/blog/comparing-products-design-practices-to-help-your-users-avoid-fragmented-comparison-7/) — fragmented comparison UX pitfalls (HIGH confidence)
- [HikeLite](https://hikeliteapp.com/) -- worn weight marking, CSV import format - [Drag and drop UI examples and UX tips — Eleken](https://www.eleken.co/blog-posts/drag-and-drop-ui) — drag affordance and visual feedback patterns (MEDIUM confidence)
- [Packrat](https://www.packrat.app/) -- flexible weight unit input and display conversion - GearBox codebase analysis (src/db/schema.ts, src/server/services/, src/client/hooks/) — confirmed existing data model, no rank/pros/cons columns present (HIGH confidence)
- [BPL Calculator Forum Discussion](https://backpackinglight.com/forums/topic/new-backpacking-hiking-weight-calculator-app/) -- unit conversion UX, search filter patterns
- [react-minimal-pie-chart (GitHub)](https://github.com/toomuchdesign/react-minimal-pie-chart) -- 2kB lightweight chart library
- [Best React Chart Libraries 2025 (LogRocket)](https://blog.logrocket.com/best-react-chart-libraries-2025/) -- chart library comparison
- [LighterPack GitHub Issues](https://github.com/galenmaly/lighterpack/issues) -- user feature requests
- [OutPack](https://outpack.app/) -- modern LighterPack alternative with category breakdown graphs
- [Pack Weight Calculator Guide (BackpackPeek)](https://backpackpeek.com/blog/pack-weight-calculator-base-weight-guide) -- base weight calculation methodology
--- ---
*Feature research for: v1.2 Collection Power-Ups (search/filter, weight classification, visualization, candidate status, weight units)* *Feature research for: GearBox v1.3 — candidate comparison, setup impact preview, candidate ranking*
*Researched: 2026-03-16* *Researched: 2026-03-16*

View File

@@ -1,202 +1,230 @@
# Pitfalls Research # Pitfalls Research
**Domain:** Adding search/filter, weight classification, weight distribution charts, candidate status tracking, and weight unit selection to an existing gear management app (GearBox v1.2) **Domain:** Adding side-by-side candidate comparison, setup impact preview, and drag-to-reorder ranking to an existing gear management app (GearBox v1.3)
**Researched:** 2026-03-16 **Researched:** 2026-03-16
**Confidence:** HIGH (pitfalls derived from direct codebase analysis + domain-specific patterns from gear tracking community + React/SQLite ecosystem knowledge) **Confidence:** HIGH (derived from direct codebase analysis of v1.2 + verified with dnd-kit GitHub issues, TanStack Query docs, and Baymard comparison UX research)
---
## Critical Pitfalls ## Critical Pitfalls
### Pitfall 1: Weight Unit Conversion Rounding Accumulation ### Pitfall 1: dnd-kit + React Query Cache Produces Visible Flicker on Drop
**What goes wrong:** **What goes wrong:**
GearBox stores weight as `real("weight_grams")` (a floating-point column in SQLite). When adding unit selection (g, oz, lb, kg), the naive approach is to convert on display and let users input in their preferred unit, converting back to grams on save. The problem: repeated round-trip conversions accumulate rounding errors. A user enters `5.3 oz`, which converts to `150.253...g`, gets stored as `150.253`, then displayed back as `5.30 oz` (fine so far). But if the user opens the edit form (which shows `5.30 oz`), makes no changes, and saves, the value reconverts from the displayed `5.30` to `150.2535g` -- a different value from what was stored. Over multiple edit cycles, weights drift. More critically, the existing `SUM(items.weight_grams)` aggregates in `setup.service.ts` and `totals.service.ts` will accumulate these micro-errors across dozens of items, producing totals that visibly disagree with manual addition of displayed values. A setup showing items of "5.3 oz + 2.1 oz" but a total of "7.41 oz" (instead of 7.40 oz) erodes trust in the app's core value proposition. When ranking candidates via drag-to-reorder, the naive approach is to call `mutate()` in `onDragEnd` and apply an optimistic update with `setQueryData` in the `onMutate` callback. Despite this, the item visibly snaps back to its original position for a split second before settling in the new position. The user sees a "jump" on every successful drop, which makes the ranking feature feel broken even though the data is correct.
**Why it happens:** **Why it happens:**
The conversion factor between grams and ounces (28.3495) is irrational enough that floating-point representation always involves truncation. Combined with SQLite's `REAL` type (8-byte IEEE 754 float, ~15 digits of precision), individual items are accurate enough, but the accumulation across conversions and summation surfaces visible errors. dnd-kit's `SortableContext` derives its order from React state. When the order is stored in React Query's cache rather than local React state, there is a timing mismatch: dnd-kit reads the list order from the cache after the drop animation, but the cache update triggers a React re-render cycle that arrives one or two frames late. The drop animation briefly shows the item at its original position before the re-render reflects the new order. This is a known, documented issue in dnd-kit (GitHub Discussion #1522, Issue #921) that specifically affects React Query integrations.
**How to avoid:** **How to avoid:**
1. Store weights in grams as the canonical unit -- this is already done. Good. Use a `tempItems` local state (`useState<Candidate[] | null>(null)`) alongside React Query. On `onDragEnd`, immediately set `tempItems` to the reordered array before calling `mutate()`. Render the candidate list from `tempItems ?? queryData.candidates`. In mutation `onSettled`, set `tempItems` to `null` to hand back control to React Query. This approach:
2. Convert only at the display boundary (the `formatWeight` function in `lib/formatters.ts`). Never convert grams to another unit, let the user edit, and convert back. - Prevents the flicker because the component re-renders from synchronous local state immediately
3. When the user inputs in oz/lb/kg, convert to grams once on save and store. The edit form should always load the stored grams value and re-convert for display, never re-convert from a previously displayed value. - Avoids `useEffect` syncing (which adds extra renders and is error-prone)
4. Round only at the final display step, not during storage. Use `Number(value.toFixed(1))` for display, never for the stored value. - Stays consistent with the existing React Query + Zustand pattern in the codebase
5. For totals, compute `SUM(weight_grams)` in SQL (already done), then convert the total to display units once. Do not sum converted per-item display values. - Handles drag cancellation cleanly (reset `tempItems` on `onDragCancel`)
6. Consider changing `weight_grams` from `real` to `integer` to store milligrams (or tenths of grams) for sub-gram precision without floating-point issues. This is a larger migration but eliminates the class of errors entirely.
Do not store the rank column data in the React Query `["threads", threadId]` cache key in a way that requires invalidation and refetch after reorder — this causes a round-trip delay that amplifies the flicker.
**Warning signs:** **Warning signs:**
- Edit form pre-fills with a converted value and saves by reconverting that value - Item visibly snaps back to original position for ~1 frame on drop
- `formatWeight` is called before summation rather than after - `onDragEnd` calls `mutate()` but uses no local state bridge
- Unit conversion is done in multiple places (client and server) with different rounding - `setQueryData` is the only state update on drag end
- Tests compare floating-point totals with `===` instead of tolerance-based comparison
**Phase to address:** **Phase to address:**
Phase 1 (Weight unit selection) -- the conversion layer must be designed correctly from the start. Getting this wrong poisons every downstream feature (charts, setup totals, classification breakdowns). Candidate ranking phase — the `tempItems` pattern must be designed before building the drag UI, not retrofitted after noticing the flicker.
--- ---
### Pitfall 2: Weight Classification Stored at Wrong Level ### Pitfall 2: Rank Storage Using Integer Offsets Requires Bulk Writes
**What goes wrong:** **What goes wrong:**
Weight classification (base weight / worn / consumable) seems like a property of the item itself -- "my rain jacket is always worn weight." So the developer adds a `classification` column to the `items` table. But this is wrong: the same item can be classified differently in different setups. A rain jacket is "worn" in a summer bikepacking setup but "base weight" (packed in the bag) in a winter setup where you wear a heavier outer shell. By putting classification on the item, users cannot accurately model multiple setups with the same gear, which is the entire point of the setup feature. The most obvious approach for storing candidate rank order is adding a `sortOrder INTEGER` column to `thread_candidates` and storing 1, 2, 3... When the user drags candidate #2 to position #1, the naive fix is to update all subsequent candidates' `sortOrder` values to maintain contiguous integers. With 5 candidates, this is 5 UPDATE statements per drop. With rapid dragging, this creates a burst of writes where each intermediate position during the drag fires updates. If the app ever has threads with 10+ candidates (not uncommon for a serious gear decision), this becomes visible latency on every drag.
**Why it happens:** **Why it happens:**
LighterPack and similar tools model classification at the list level (each list has its own classification per item), but when you look at the GearBox schema, the `setup_items` join table only has `(id, setup_id, item_id)`. It feels more natural to add a column to the item itself rather than to a join table, especially since the current `setup_items` table is minimal. The single-user context also makes it feel like "my items have fixed classifications." Integer rank storage feels natural and maps directly to how arrays work. The developer adds `ORDER BY sort_order ASC` to the candidate query and calls it done. The performance problem is only discovered when testing with a realistic number of candidates and a fast drag gesture.
**How to avoid:** **How to avoid:**
Add `classification TEXT DEFAULT 'base'` to the `setup_items` table, not to `items`. This means: Use a `sortOrder REAL` column (floating-point) with fractional indexing — when inserting between positions A and B, assign `(A + B) / 2`. This means a drag requires only a single UPDATE for the moved item. Only trigger a full renumber (resetting all candidates to integers 1000, 2000, 3000... or similar spaced values) when the float precision degrades (approximately after 50+ nested insertions, unlikely in practice for this app). Start values at 1000, 5000 increments to give ample room.
- The same item can have different classifications in different setups
- Classification is optional and defaults to "base" (the most common case)
- The `items` table stays generic -- classification is a setup-level concern
- Existing `setup_items` rows get a sensible default via the migration
- SQL aggregates for setup totals can easily group by classification: `SUM(CASE WHEN setup_items.classification = 'base' THEN items.weight_grams ELSE 0 END)`
If classification is also useful outside of setups (e.g., in the collection view for a general breakdown), add it as an optional `defaultClassification` on `items` that serves as a hint when adding items to setups, but the authoritative classification is always on `setup_items`. For GearBox's use case (typically 2-8 candidates per thread), integer storage is workable, but the fractional approach is cleaner and avoids the bulk-write problem entirely. The added complexity is minimal: one line of math in the service layer.
Regardless of storage strategy, add an index: `CREATE INDEX ON thread_candidates (thread_id, sort_order)`.
**Warning signs:** **Warning signs:**
- `classification` column added to `items` table - `sortOrder` column uses `integer()` type in Drizzle schema
- Setup detail view shows classification but cannot be different per setup - Reorder service function issues multiple UPDATE statements in a loop
- Weight breakdown chart shows the same classification for an item across all setups - No transaction wrapping the bulk update
- No way to classify an item as "worn" in one setup and "base" in another - Each drag event (not just the final drop) triggers a service call
**Phase to address:** **Phase to address:**
Phase 2 (Weight classification) -- this is the single most important schema decision in v1.2. Getting it wrong requires migrating data out of the `items` table into `setup_items` later, which means reconciling possibly-different classifications that users already set. Schema and service design phase for candidate ranking — the storage strategy must be chosen before building the sort UI, as changing from integer to fractional later requires a migration.
--- ---
### Pitfall 3: Search/Filter Implemented Server-Side for a Client-Side Dataset ### Pitfall 3: Impact Preview Reads Stale Candidate Data
**What goes wrong:** **What goes wrong:**
The developer adds a `GET /api/items?search=tent&category=3` endpoint, sending filtered results from the server. This means: The impact preview shows "+450g / +$89" next to each candidate — what this candidate would add to the selected setup. The calculation is: `(candidate.weightGrams - null) + setup.totalWeight`. But the candidate card data comes from the `["threads", threadId]` query cache, while the setup totals come from a separate `["setups", setupId]` query cache. These caches can be out of sync: the user edits a candidate's weight in one tab, invalidating the threads cache, but if the setup was fetched earlier and has not been refetched, the "current setup weight" baseline in the delta is stale. The preview shows a delta calculated against the wrong baseline.
- Every keystroke fires an API request (or requires debouncing, adding latency)
- The client's React Query cache for `["items"]` now contains different data depending on filter params, causing stale/inconsistent state The second failure mode: if `candidate.weightGrams` is `null` (not yet entered), displaying `+-- / +$89` is confusing. Users see "null delta" and assume the comparison is broken rather than understanding that the candidate has no weight data.
- Category grouping in `CollectionView` breaks because the full list is no longer available
- The existing `useTotals()` hook returns totals for all items, but the list shows filtered items -- a confusing mismatch
**Why it happens:** **Why it happens:**
Server-side filtering is the "correct" pattern at scale, and most tutorials teach it that way. But GearBox is a single-user app where the entire collection fits comfortably in memory. The existing `useItems()` hook already fetches all items in one call and the collection view groups them client-side. Impact preview feels like pure computation — "just subtract two numbers." The developer writes it as a derived value from two props and does not think about cache coherence. The null case is often overlooked because the developer tests with complete candidate data.
**How to avoid:** **How to avoid:**
Implement search and filter entirely on the client side: 1. Derive the delta from data already co-located in one cache entry where possible. The thread detail query (`["threads", threadId]`) returns all candidates; the setup query (`["setups", setupId]`) returns items with weight. Compute the delta in the component using both: `delta = candidate.weightGrams - replacedItemWeight` where `replacedItemWeight` is taken from the currently loaded setup data.
1. Keep `useItems()` fetching the full list (it already does) 2. Use `useQuery` for setup data with the setup selector in the same component that renders the comparison, so both data sources are reactive.
2. Add filter state (search query, category ID) as URL search params or React state in the collection page 3. Handle null weight explicitly: show "-- (no weight data)" not "--g" for candidates without weights. Make the null state visually distinct from a zero delta.
3. Filter the `items` array in the component using `Array.filter()` before grouping and rendering 4. Do NOT make a server-side `/api/threads/:id/impact?setupId=:sid` endpoint that computes delta server-side — this creates a third cache entry to invalidate and adds network latency to what should be a purely client-side calculation.
4. The totals bar should continue to show collection totals (unfiltered), not filtered totals -- or show both ("showing 12 of 47 items")
5. Only move to server-side filtering if the collection exceeds ~500 items, which is far beyond typical for a single-user gear app
This preserves the existing caching behavior, requires zero API changes, and gives instant feedback on every keystroke.
**Warning signs:** **Warning signs:**
- New query parameters added to `GET /api/items` endpoint - Impact delta shows stale values after editing a candidate's weight
- `useItems` hook accepts filter params, creating multiple cache entries - Null weight candidates show a numerical delta (treating null as 0)
- Search input has a debounce delay - Delta calculation is in a server route rather than a client-side derived value
- Filtered view totals disagree with dashboard totals - Setup data is fetched via a different hook than the one used for candidate data, with no shared staleness boundary
**Phase to address:** **Phase to address:**
Phase 1 (Search/filter) -- the decision to filter client-side vs server-side affects where state lives and must be decided before building the UI. Impact preview phase — establish the data flow (client-side derived from two existing queries) before building the UI so the stale-cache problem cannot arise.
--- ---
### Pitfall 4: Candidate Status Transition Without Validation ### Pitfall 4: Side-by-Side Comparison Breaks at Narrow Widths
**What goes wrong:** **What goes wrong:**
The existing thread system has a simple `status: "active" | "resolved"` on threads and no status on candidates. Adding candidate status tracking (researching -> ordered -> arrived) as a simple text column without transition validation allows impossible states: a candidate marked "arrived" in a thread that was already "resolved," or a candidate going from "arrived" back to "researching." Worse, the existing `resolveThread` function in `thread.service.ts` copies candidate data to create a collection item -- but does not check or update candidate status, so a "researching" candidate can be resolved as the winner (logically wrong, though the data flow works). The comparison view is built with a fixed two-or-three-column grid for the candidate cards. On a laptop at 1280px it looks great. On a narrower viewport or when the browser window is partially shrunk, the columns collapse to ~200px each, making the candidate name truncated, the weight/price badges unreadable, and the notes text invisible. The user cannot actually compare the candidates — the view that was supposed to help them decide becomes unusable.
GearBox's existing design philosophy is mobile-responsive, but comparison tables are inherently wide. The tension is real: side-by-side requires horizontal space that mobile cannot provide.
**Why it happens:** **Why it happens:**
The current codebase uses plain strings for thread status with no validation layer. The developer follows the same pattern for candidate status: just a text column with no constraints. SQLite does not enforce enum values, so any string is accepted. Comparison views are usually mocked at full desktop width. Responsiveness is added as an afterthought, and the "fix" is often to stack columns vertically on mobile — which defeats the entire purpose of side-by-side comparison.
**How to avoid:** **How to avoid:**
1. Define valid candidate statuses as a union type: `"researching" | "ordered" | "arrived"` in `schemas.ts` 1. Build the comparison view as a horizontally scrollable container on mobile (`overflow-x: auto`). Do not collapse to vertical stack — comparing stacked items is cognitively equivalent to switching between detail pages.
2. Add Zod validation for the status field with `.refine()` or `z.enum()` to reject invalid values at the API level 2. Limit the number of simultaneously compared candidates to 3 (or at most 4). Comparing 8 candidates side-by-side is unusable regardless of screen size.
3. Define valid transitions: `researching -> ordered -> arrived` (and optionally `* -> dropped`) 3. Use a minimum column width (e.g., `min-width: 200px`) so the container scrolls horizontally before the column content becomes illegible.
4. In the service layer, validate that the requested status transition is valid before applying it (e.g., cannot go from "arrived" to "researching") 4. Sticky first column for candidate names when scrolling horizontally, so the user always knows which column they are reading.
5. When resolving a thread, do NOT require a specific candidate status -- the user may resolve with a "researching" candidate if they decide to buy it outright. But DO update all non-winner candidates to a terminal state like "dropped" in the same transaction. 5. Test at 768px viewport width before considering the feature done.
6. Add a check in `resolveThread`: if the thread is already resolved, reject the operation (this check already exists in the current code -- good)
**Warning signs:** **Warning signs:**
- Candidate status is a plain `text()` column with no Zod enum validation - Comparison grid uses percentage widths that collapse below 150px
- No transition validation in the update candidate service - No horizontal scroll on the comparison container
- `resolveThread` does not update non-winner candidate statuses - Mobile viewport shows columns stacked vertically
- UI allows arbitrary status changes via a dropdown with no constraints - Candidate name or weight badges are truncated without tooltip
**Phase to address:** **Phase to address:**
Phase 3 (Candidate status tracking) -- must be designed with awareness of the existing thread resolution flow in `thread.service.ts`. The status field and transition logic should be added together, not incrementally. Side-by-side comparison UI phase — responsive behavior must be designed in, not retrofitted. The minimum column width and scroll container decision shapes the entire component structure.
--- ---
### Pitfall 5: Weight Distribution Chart Diverges from Displayed Totals ### Pitfall 5: Pros/Cons Fields Stored as Free Text in Column, Not Structured
**What goes wrong:** **What goes wrong:**
The weight distribution chart (e.g., a donut chart showing weight by category or by classification) computes its data from one source, while the totals bar and setup detail page compute from another. The chart might use client-side summation of displayed (rounded) values while the totals use SQL `SUM()`. Or the chart uses the `useTotals()` hook data while the setup page computes totals inline (as `$setupId.tsx` currently does on lines 53-61). These different computation paths produce different numbers for the same data, and when a chart slice says "Shelter: 2,450g" but the category header says "Shelter: 2,451g," users lose trust. Pros and cons per candidate are stored as two free-text columns: `pros TEXT` and `cons TEXT` on `thread_candidates`. The user types a multi-line blob of text into each field. The comparison view renders them as raw text blocks next to each other. Two problems emerge:
- Formatting: the comparison view cannot render individual pro/con bullet points because the data is unstructured blobs
- Length: one candidate has a 500-word "pros" essay; another has two words. The comparison columns have wildly unequal heights, making the side-by-side comparison visually chaotic and hard to scan
The deeper problem: free text in a comparison context produces noise, not signal. Users write "it's really lightweight and packable and the color options are nice" when what the comparison view needs is scannable bullet points.
**Why it happens:** **Why it happens:**
The codebase already has two computation paths for totals: `totals.service.ts` computes via SQL aggregates, and the setup detail page computes via JavaScript reduce on the client. These happen to agree now because there is no unit conversion, but adding unit display and classification filtering creates more opportunities for divergence. Adding two text columns to `thread_candidates` is the simplest possible implementation. The developer tests it with neat, short text and it looks fine. The UX failure is only visible when a real user writes the way real users write.
**How to avoid:** **How to avoid:**
1. Establish a single source of truth for all weight computations: the SQL aggregate in the service layer. 1. Store pros/cons as newline-delimited strings, not markdown or JSON. The UI splits on newlines and renders each line as a bullet. Simple, no parsing, no migration complexity.
2. For chart data, create a dedicated endpoint or extend `GET /api/totals` to return breakdowns by category AND by classification (for setups). Do not recompute in the chart component. 2. In the form, use a `<textarea>` with a placeholder of "one item per line." Show a character count.
3. For setup-specific charts, extend `getSetupWithItems` to return pre-computed breakdowns, or compute them from the setup's item list using a shared utility function that is used by both the totals display and the chart. 3. In the comparison view, render each newline-delimited entry as its own row, so columns stay scannable. Use a max of 5 bullet points per field; truncate with "show more" if longer.
4. Unit conversion happens once, at the display layer, using the same `formatWeight` function everywhere. 4. Cap `pros` and `cons` field length at 500 characters in the Zod schema to prevent essay-length blobs.
5. Write a test that compares the chart data source against the totals data source and asserts they agree. 5. The comparison view should truncate to the first 3 bullets when in compact comparison mode, with expand option.
**Warning signs:** **Warning signs:**
- Chart component does its own `reduce()` on item data instead of using the same data as the totals display - `pros TEXT` and `cons TEXT` added to schema with no length constraint
- Two different API endpoints return weight totals for the same scope and the values differ by small amounts - Comparison view renders `{candidate.pros}` as a raw string in a `<p>` tag
- Chart labels show different precision than text displays (chart: "2.4 kg", header: "2,451 g") - One candidate's pros column is 3x taller than another's, making row alignment impossible
- No shared utility function for weight summation - Form shows a full-height textarea with no guidance on format
**Phase to address:** **Phase to address:**
Phase 3 (Weight distribution visualization) -- but the single-source-of-truth pattern should be established in Phase 1 when refactoring formatters for unit selection. Both the ranking schema phase (when pros/cons columns are added) and the comparison UI phase (when the rendering decision is made). The newline-delimited format must be decided at schema design time.
--- ---
### Pitfall 6: Schema Migration Breaks Test Helper ### Pitfall 6: Impact Preview Compares Against Wrong Setup Total When Item Would Be Replaced
**What goes wrong:** **What goes wrong:**
GearBox's test infrastructure uses a manual `createTestDb()` function in `tests/helpers/db.ts` that creates tables with raw SQL `CREATE TABLE` statements instead of using Drizzle's migration system. When adding new columns (e.g., `classification` to `setup_items`, `status` to `thread_candidates`, `weight_unit` to `settings`), the developer updates `src/db/schema.ts` and runs `bun run db:generate` + `bun run db:push`, but forgets to update the test helper's CREATE TABLE statements. All tests pass in the test database (which has the old schema) while the real database has the new schema -- or worse, tests fail with cryptic column-not-found errors and the developer wastes time debugging the wrong thing. The impact preview shows the delta for each candidate as if the candidate would be *added* to the setup. But the real use case is: "I want to replace my current tent with one of these candidates — which one saves the most weight?" The user expects the delta to reflect `candidateWeight - currentItemWeight`, not just `+candidateWeight`.
When the delta is calculated as a pure addition (no replacement), a 500g candidate looks like "+500g" even though the item it replaces weighs 800g, meaning it would actually save 300g. The user sees a positive delta and dismisses the candidate when they should pick it.
**Why it happens:** **Why it happens:**
The test helper duplicates the schema definition in raw SQL rather than deriving it from the Drizzle schema. This is a known pattern in the codebase (documented in CLAUDE.md: "When adding schema columns, update both `src/db/schema.ts` and the test helper's CREATE TABLE statements"). But under the pressure of adding multiple schema changes across several features, it is easy to miss one table or one column. "Impact" is ambiguous. The developer defaults to "how much weight does this add?" because that calculation is simpler (no need to identify which existing item is being replaced). The replacement case requires the user to specify which item in the setup would be swapped out, which feels like additional UX complexity.
**How to avoid:** **How to avoid:**
1. **Every schema change PR must include the corresponding test helper update.** Add this as a checklist item in the development workflow. 1. Support both modes: "add to setup" (+delta) and "replace item" (delta = candidate - replaced item). Make the mode selection explicit in the UI.
2. Consider writing a simple validation test that compares the columns in `createTestDb()` tables against the Drizzle schema definition, failing if they diverge. This catches the problem automatically. 2. Default to "add" mode if no item in the setup shares the same category as the thread. Default to "replace" mode if an item with the same category exists — offer it as a pre-populated suggestion ("Replaces: Big Agnes Copper Spur 2? Change").
3. For v1.2, since multiple schema changes are landing (classification on setup_items, status on candidates, possibly weight_unit in settings), batch the test helper update and verify all changes in one pass. 3. The replacement item selector should be a dropdown filtered to setup items in the same category, defaulting to the most likely match.
4. Long-term: investigate using Drizzle's `migrate()` with in-memory SQLite to eliminate the duplication entirely. 4. If no setup is selected, show raw candidate weight rather than a delta — do not calculate a delta against zero.
**Warning signs:** **Warning signs:**
- Schema column added to `schema.ts` but not to `tests/helpers/db.ts` - Delta is always positive (never shows weight savings)
- Tests pass locally but queries fail at runtime - No replacement item selector in the impact preview UI
- New service function works in the app but throws in tests - Thread category is not used to suggest a candidate's likely replacement item
- Test database has fewer columns than production database - Delta is calculated as `candidate.weightGrams` with no baseline
**Phase to address:** **Phase to address:**
Every phase that touches the schema. Must be addressed in Phase 1 (unit settings), Phase 2 (classification on setup_items), and Phase 3 (candidate status). Each phase should verify test helper parity as a completion criterion. Impact preview design phase — the "add vs replace" distinction must be designed before building the service layer, because "add" and "replace" produce fundamentally different calculations and different UI affordances.
--- ---
### Pitfall 7: Weight Unit Preference Stored Wrong, Applied Wrong ### Pitfall 7: Schema Change Adds Columns Without Updating Test Helper
**What goes wrong:** **What goes wrong:**
The developer stores the user's preferred weight unit as a setting (using the existing `settings` table with key-value pairs). But then applies it inconsistently: the collection page shows grams, the setup page shows ounces, the chart shows kilograms. Or the setting is read once on page load and cached in Zustand, so changing the preference requires a page refresh. Or the setting is read on every render, causing a flash of "g" before the "oz" preference loads. v1.3 requires adding `sortOrder`, `pros`, and `cons` to `thread_candidates`. The developer updates `src/db/schema.ts`, runs `bun run db:push`, and builds the feature. Tests fail with cryptic "no such column" errors — or worse, tests pass silently because they do not exercise the new columns, while the real database has them.
This pitfall already existed in v1.2 (documented in the previous PITFALLS.md) and the test helper (`tests/helpers/db.ts`) uses raw CREATE TABLE SQL that must be manually kept in sync.
**Why it happens:** **Why it happens:**
The `settings` table is a key-value store with no type safety. The preference is a string like `"oz"` that must be parsed and applied in many places: `formatWeight` in formatters, chart labels, totals bar, setup detail, item cards, category headers. Missing any one of these locations creates an inconsistency. Under time pressure, the developer focuses on the feature and forgets the test helper update. The error only surfaces when the new service function is called in a test. The CLAUDE.md documents this requirement, but it is easy to miss in the flow of development.
**How to avoid:** **How to avoid:**
1. Store the preference in the `settings` table as `{ key: "weightUnit", value: "g" | "oz" | "lb" | "kg" }`. For every schema change in v1.3, update `tests/helpers/db.ts` in the same commit:
2. Create a `useWeightUnit()` hook that wraps `useSettings()` and returns the parsed unit with a fallback to `"g"`. - `thread_candidates`: add `sort_order REAL DEFAULT 0`, `pros TEXT`, `cons TEXT`
3. Modify `formatWeight` to accept a unit parameter: `formatWeight(grams, unit)`. This is a single function used everywhere, so changing it propagates automatically. - Run `bun test` immediately after schema + helper update, before writing any other code
4. Do NOT store converted values anywhere -- always store grams, convert at display time.
5. Use React Query for the settings fetch so the preference is cached and shared across components. When the user changes their preference, invalidate `["settings"]` and all displays update simultaneously via React Query's reactivity. Consider writing a schema-parity test: compare the columns returned by `PRAGMA table_info(thread_candidates)` against a known expected list, failing if they differ. This catches the test-helper-out-of-sync problem automatically.
6. Handle the loading state: show raw grams (or a loading skeleton) until the preference is loaded. Do not flash a different unit.
**Warning signs:** **Warning signs:**
- `formatWeight` does not accept a unit parameter -- it is hardcoded to `"g"` - Tests failing with `SqliteError: no such column`
- Weight unit preference is stored in Zustand instead of React Query (settings endpoint) - New service function works in the running app but throws in `bun test`
- Some components use `formatWeight` and some inline their own formatting - `bun run db:push` was run but `bun test` was not run afterward
- Changing the unit preference does not update all visible weights without a page refresh - `tests/helpers/db.ts` has fewer columns than `src/db/schema.ts`
**Phase to address:** **Phase to address:**
Phase 1 (Weight unit selection) -- this is foundational infrastructure. The `formatWeight` refactor and `useWeightUnit` hook must exist before building any other feature that displays weight. Every schema-touching phase of v1.3. The candidate ranking schema phase (sortOrder, pros, cons) is the primary risk. Check test helper parity as an explicit completion criterion.
---
### Pitfall 8: Comparison View Includes Resolved Candidates
**What goes wrong:**
After a thread is resolved (winner picked), the thread's candidates still exist in the database. The comparison view, if it loads candidates from the existing `getThreadWithCandidates` response without filtering, will display the resolved winner alongside all losers — including the now-irrelevant candidates. A user revisiting a resolved thread to check why they picked Option A sees all candidates re-listed in the comparison view with no indication of which was selected, creating confusion.
The secondary problem: if the app allows drag-to-reorder ranking on a resolved thread, a user could accidentally fire rank-update mutations on a thread that should be read-only.
**Why it happens:**
The comparison view and ranking components are built for active threads and tested only with active threads. Resolved thread behavior is not considered during design.
**How to avoid:**
1. Check `thread.status === "resolved"` before rendering the comparison/ranking UI. For resolved threads, render a read-only summary: "You chose [winner name]" with the winning candidate highlighted and others shown as non-interactive.
2. Disable drag-to-reorder on resolved threads entirely — don't render the drag handles.
3. In the impact preview, disable the "Impact on Setup" panel for resolved threads and instead show "Added to collection on [date]" for the winning candidate.
4. The API route for rank updates should reject requests for resolved threads (return 400 with "Thread is resolved").
**Warning signs:**
- Comparison/ranking UI renders identically for active and resolved threads
- Drag handles are visible on resolved thread candidates
- No `thread.status` check in the comparison view component
- Resolved threads accept rank update mutations
**Phase to address:**
Comparison UI phase and ranking phase — both must include a resolved-thread guard. This is a correctness issue, not just a UX issue, because drag mutations on resolved threads corrupt state.
--- ---
@@ -206,24 +234,29 @@ Shortcuts that seem reasonable but create long-term problems.
| Shortcut | Immediate Benefit | Long-term Cost | When Acceptable | | Shortcut | Immediate Benefit | Long-term Cost | When Acceptable |
|----------|-------------------|----------------|-----------------| |----------|-------------------|----------------|-----------------|
| Adding classification to `items` instead of `setup_items` | Simpler schema, no join table changes | Cannot have different classifications per setup; future migration required | Never -- the per-setup model is the correct one | | Integer `sortOrder` instead of fractional | Simple schema | Bulk UPDATE on every reorder; bulk write latency with 10+ candidates | Acceptable only if max candidates per thread is enforced at 5 or fewer |
| Client-side unit conversion on both read and write paths | Simple bidirectional conversion | Rounding drift over edit cycles, inconsistent totals | Never -- convert once on write, display-only on read | | Server-side delta calculation endpoint | Simpler client code | Third cache entry to invalidate; network round-trip on every setup selection change | Never — the calculation is two subtractions using data already in client cache |
| Separate chart data computation from totals computation | Faster chart development, no API changes | Numbers disagree between chart and text displays | Only if a shared utility function ensures identical computation | | Pros/cons as unstructured free-text blobs | Zero schema complexity | Comparison view cannot render bullets; columns misalign | Never for comparison display — use newline-delimited format from day one |
| Hardcoding chart library colors per category | Quick to implement | Colors collide when user adds categories; no dark mode support | MVP only if using a predictable color generation function is planned | | Comparison grid with `overflow: hidden` on narrow viewports | Avoids horizontal scroll complexity | Comparison becomes unreadable on laptop with panels open; critical feature breaks | Never — horizontal scroll is the correct behavior for comparison tables |
| Adding candidate status without transition validation | Faster to implement | Invalid states accumulate, resolve logic has edge cases | Only if validation is added before the feature ships to production | | Rendering comparison for resolved threads without guard | Simpler component logic | Users can drag-reorder resolved threads, corrupting state | Never — the resolved-thread guard is a correctness requirement |
| Debouncing search instead of client-side filter | Familiar pattern from server-filtered apps | Unnecessary latency, complex cache management | Never for this app's scale (sub-500 items) | | `DragOverlay` using same component as `useSortable` | Less component code | ID collision in dnd-kit causes undefined behavior during drag | Never — dnd-kit explicitly requires a separate presentational component for DragOverlay |
---
## Integration Gotchas ## Integration Gotchas
Since v1.2 is adding features to an existing system rather than integrating external services, these are internal integration points where new features interact with existing ones. Common mistakes when connecting new v1.3 features to existing v1.2 systems.
| Integration Point | Common Mistake | Correct Approach | | Integration Point | Common Mistake | Correct Approach |
|-------------------|----------------|------------------| |-------------------|----------------|------------------|
| Search/filter + category grouping | Filtering items breaks the existing category-grouped layout because the group headers disappear when no items match | Filter within groups: show category headers only for groups with matching items. Empty groups should hide, not show "no items." | | Ranking + React Query | Using `setQueryData` alone for optimistic reorder, causing flicker | Maintain `tempItems` local state in the drag component; render from `tempItems ?? queryData.candidates`; clear on `onSettled` |
| Weight classification + existing setup totals | Adding classification changes how totals are computed (base weight vs total weight), but existing setup list cards show `totalWeight` which was previously "everything" | Keep `totalWeight` as the sum of all items. Add `baseWeight` as a new computed field (sum of items where classification = 'base'). Show both in the setup detail view. | | Impact preview + weight unit | Computing delta in grams but displaying with `formatWeight` that expects the stored unit | Delta is always computed in grams (raw stored values); apply `formatWeight(delta, unit)` once at display time, same pattern as all other weight displays |
| Candidate status + thread resolution | Adding status to candidates but not updating `resolveThread` to handle it | The `resolveThread` transaction must set winner status to a terminal state and non-winners to "dropped." New candidates added to an already-resolved thread should be rejected. | | Impact preview + null weights | Treating `null` weightGrams as 0 in delta calculation | Show "-- (no weight data)" explicitly; never pass null to arithmetic; guard with `candidate.weightGrams != null && setup.totalWeight != null` |
| Unit selection + React Query cache | Changing the weight unit preference does not invalidate the items cache because items are stored in grams regardless | The unit preference is a display concern, not a data concern. Do NOT invalidate items/totals on unit change. Just re-render with the new unit. Ensure `formatWeight` is called reactively, not cached. | | Pros/cons + thread resolution | Pros/cons text copied to collection item on resolve | Do NOT copy pros/cons to the items table — these are planning notes, not collection metadata. `resolveThread` in `thread.service.ts` should remain unchanged |
| Weight chart + empty/null weights | Chart component crashes or shows misleading data when items have `null` weight | Filter out items with null weight from chart data. Show a note like "3 items excluded (no weight recorded)." Never treat null as 0 in a chart -- that makes the chart lie. | | Rank order + existing `getThreadWithCandidates` | Adding `ORDER BY sort_order` to `getThreadWithCandidates` changes the order of an existing query used by other components | Add `sort_order` to the SELECT and ORDER BY in `getThreadWithCandidates`. Audit all consumers of this query to verify they are unaffected by ordering change (the candidate cards already render in whatever order the query returns) |
| Comparison view + `isActive` prop | `CandidateCard.tsx` uses `isActive` to show/hide the "Winner" button. Comparison view must not show "Winner" button inline if comparison has its own resolve affordance | Pass `isActive={false}` to `CandidateCard` when rendering inside comparison view, or create a separate `CandidateComparisonCard` presentational component that omits action buttons |
---
## Performance Traps ## Performance Traps
@@ -231,11 +264,12 @@ Patterns that work at small scale but fail as usage grows.
| Trap | Symptoms | Prevention | When It Breaks | | Trap | Symptoms | Prevention | When It Breaks |
|------|----------|------------|----------------| |------|----------|------------|----------------|
| Re-rendering entire collection on search keystroke | UI jank on every character typed in search box | Use `useMemo` to memoize the filtered list; ensure `ItemCard` is memoized with `React.memo` | 100+ items with images | | Bulk integer rank updates on every drag | Visible latency after each drop; multiple UPDATE statements per drag; SQLite write lock held | Use fractional `sortOrder REAL` so only the moved item requires an UPDATE | 8+ candidates per thread with rapid dragging |
| Chart re-renders on every parent state change | Chart animation restarts on unrelated state updates (e.g., opening a panel) | Memoize chart data computation with `useMemo`; wrap chart component in `React.memo`; use `isAnimationActive={false}` after initial render | Any chart library with entrance animations | | Comparison view fetching all candidates for all threads | Slow initial load; excessive memory for large thread lists | Comparison view uses the already-loaded `["threads", threadId]` query; never fetches candidates outside the active thread's query | 20+ threads with 5+ candidates each |
| Recharts SVG rendering with many category slices | Donut chart becomes sluggish with 20+ categories, each with a tooltip and label | Limit chart to top N categories by weight, group the rest into "Other." Recharts is SVG-based, so keep segments under ~15. | 20+ categories (unlikely for single user, but possible) | | Sync rank updates on every `dragOver` event (not just `dragEnd`) | Thousands of UPDATE mutations during a single drag; server overwhelmed; UI lags | Persist rank only on `onDragEnd` (drop), never on `onDragOver` (in-flight hover) | Any usage — `onDragOver` fires on every cursor pixel moved |
| Fetching settings on every component that displays weight | Waterfall of settings requests, or flash of unconverted weights | Use React Query with `staleTime: Infinity` for settings (they change rarely). Prefetch settings at app root. | First load of any page with weights | | `useQuery` for setups list inside impact preview component | N+1 query pattern: each candidate card fetches its own setup list | Lift setup list query to the thread detail page level; pass selected setup as prop or context | 3+ candidates in comparison view |
| Computing classification breakdown per-render | Expensive reduce operations on every render cycle | Compute once in `useMemo` keyed on the items array and classification data | Setups with 50+ items (common for full bikepacking lists) |
---
## Security Mistakes ## Security Mistakes
@@ -243,9 +277,11 @@ Domain-specific security issues beyond general web security.
| Mistake | Risk | Prevention | | Mistake | Risk | Prevention |
|---------|------|------------| |---------|------|------------|
| Candidate status field accepts arbitrary strings | SQLite text column accepts anything; UI may display unexpected values or XSS payloads in status badges | Validate status against enum in Zod schema. Reject unknown values at API level. Use `z.enum(["researching", "ordered", "arrived"])`. | | `sortOrder` accepts any float value | Malformed values like `NaN`, `Infinity`, or extremely large floats stored in `sort_order` column, corrupting order | Validate `sortOrder` as a finite number in Zod schema: `z.number().finite()`. Reject `NaN` and `Infinity` at API boundary |
| Search query used in raw SQL LIKE | SQL injection if search string is interpolated into query (unlikely with Drizzle ORM but possible in raw SQL aggregates) | Use Drizzle's `like()` or `ilike()` operators which parameterize automatically. Never use template literals in `sql\`\`` with unsanitized user input. | | Pros/cons fields with no length limit | Users or automated input can store multi-kilobyte text blobs, inflating the database and slowing candidate queries | Cap at 500 characters per field in Zod: `z.string().max(500).optional()` |
| Unit preference allows arbitrary values | Settings table stores any string; a crafted value could break formatWeight or cause display issues | Validate unit against `z.enum(["g", "oz", "lb", "kg"])` both on read and write. Use a typed constant for the allowed values. | | Rank update endpoint accepts any candidateId | A crafted request can reorder candidates from a different thread by passing a candidateId that belongs to another thread | In the rank update service, verify `candidate.threadId === threadId` before applying the update — same pattern as existing `resolveThread` validation |
---
## UX Pitfalls ## UX Pitfalls
@@ -253,28 +289,33 @@ Common user experience mistakes in this domain.
| Pitfall | User Impact | Better Approach | | Pitfall | User Impact | Better Approach |
|---------|-------------|-----------------| |---------|-------------|-----------------|
| Search clears when switching tabs (gear/planning/setups) | User searches for "tent," switches to planning to check threads, switches back and search is gone | Persist search query as a URL search parameter (`?tab=gear&q=tent`). TanStack Router already handles tab via search params. | | Comparison table loses column headers on scroll | User scrolls down to see notes/pros/cons and forgets which column is which candidate | Sticky column headers with candidate name, image thumbnail, and weight. Use `position: sticky; top: 0` on the header row |
| Unit selection buried in settings page | User cannot quickly toggle between g and oz when comparing products listed in different units | Add a unit toggle/selector directly in the weight display area (e.g., in the TotalsBar or a small dropdown next to weight values). Keep global preference in settings, but allow quick access. | | Delta shows raw gram values when user prefers oz | Impact preview shows "+450g" to a user who has set their unit to oz | Apply `formatWeight(delta, unit)` using the `useWeightUnit()` hook, same as all other weight displays in the app |
| Classification picker adds friction to setup composition | User must classify every item when adding it to a setup, turning a quick "add to loadout" into a tedious process | Default all items to "base" classification. Allow bulk reclassification. Show classification as an optional second step after composing the setup. | | Drag-to-reorder with no visual rank indicator | After ranking, it is unclear that the order matters or that #1 is the "top pick" | Show rank numbers (1, 2, 3...) as badges on each candidate card when in ranking mode. Update numbers live during drag |
| Chart with no actionable insight | A pie chart showing "Shelter: 40%, Sleep: 25%, Cooking: 20%" is pretty but does not help the user make decisions | Pair the chart with a list sorted by weight. Highlight the heaviest category. If possible, show how the breakdown compares to "typical" or to other setups. At minimum, make chart segments clickable to filter to that category. | | Pros/cons fields empty by default in comparison view | Comparison table shows empty cells next to populated ones, making the comparison feel sparse and incomplete | Show a subtle "Add pros/cons" prompt in empty cells when the thread is active. In read-only resolved view, hide the pros/cons section entirely if no candidate has data |
| Status badges with no timestamps | User sees "ordered" but cannot remember when they ordered, or whether it has been suspiciously long | Store status change timestamps. Show relative time ("ordered 3 days ago"). Highlight statuses that have been stale too long ("ordered 30+ days ago -- still waiting?"). | | Impact preview setup selector defaults to no setup | User arrives at comparison view and sees no impact numbers because no setup is pre-selected | Default the setup selector to the most recently viewed/modified setup. Persist the last-selected setup in `sessionStorage` or a URL param |
| Filter resets feel destructive | User applies multiple filters (category + search), then accidentally clears one and loses the other | Show active filters as dismissible chips/pills above the list. Each filter is independently clearable. A "clear all" button resets everything. | | Removing a candidate clears comparison selection | User has candidates A, B, C in comparison; deletes C; comparison resets entirely | Comparison state (which candidates are selected) should be stored in local component state keyed by candidate ID. On delete, simply remove that ID from the selection |
---
## "Looks Done But Isn't" Checklist ## "Looks Done But Isn't" Checklist
Things that appear complete but are missing critical pieces. Things that appear complete but are missing critical pieces.
- [ ] **Search/filter:** Often missing keyboard shortcut (Cmd/Ctrl+K to focus search) -- verify search is easily accessible without mouse - [ ] **Drag-to-reorder:** Often missing drag handles — verify the drag affordance is visually distinct (grip icon), not just "drag anywhere on the card" which conflicts with the existing click-to-edit behavior
- [ ] **Search/filter:** Often missing empty state for "no results" -- verify a helpful message appears when search matches nothing, distinct from "collection is empty" - [ ] **Drag-to-reorder:** Often missing keyboard reorder fallback — verify candidates can be moved with arrow keys for accessibility (dnd-kit's `KeyboardSensor` must be added to `DndContext`)
- [ ] **Weight classification:** Often missing the per-setup model -- verify the same item can have different classifications in different setups - [ ] **Drag-to-reorder:** Often missing flicker fix — verify dropping a candidate does not briefly snap back to original position (requires `tempItems` local state, not just `setQueryData`)
- [ ] **Weight classification:** Often missing "unclassified" handling -- verify items with no classification default to "base" in all computations - [ ] **Drag-to-reorder:** Often missing resolved-thread guard — verify drag handles are hidden and mutations are blocked on resolved threads
- [ ] **Weight chart:** Often missing null-weight items -- verify items without weight data are excluded from chart with a visible note, not silently treated as 0g - [ ] **Impact preview:** Often missing the null weight case — verify candidates with no weight show "-- (no weight data)" not "NaNg" or "+0g"
- [ ] **Weight chart:** Often missing responsiveness -- verify chart renders correctly on mobile widths (Recharts needs `ResponsiveContainer` wrapper) - [ ] **Impact preview:** Often missing the replace-vs-add distinction — verify the user can specify which existing item would be replaced, not just see a pure addition delta
- [ ] **Candidate status:** Often missing transition validation -- verify a candidate cannot go from "arrived" back to "researching" - [ ] **Impact preview:** Often missing unit conversion verify the delta respects `useWeightUnit()` and `useCurrency()`, not hardcoded to grams/USD
- [ ] **Candidate status:** Often missing integration with thread resolution -- verify resolving a thread updates all candidate statuses appropriately - [ ] **Side-by-side comparison:** Often missing horizontal scroll on narrow viewports — verify the view is usable at 768px without column collapsing
- [ ] **Unit selection:** Often missing consistent application -- verify every weight display in the app (cards, headers, totals, charts, setup detail, item picker) uses the selected unit - [ ] **Side-by-side comparison:** Often missing sticky headers — verify candidate names remain visible when scrolling the comparison rows
- [ ] **Unit selection:** Often missing the edit form -- verify the item/candidate edit form shows weight in the selected unit and converts correctly on save - [ ] **Pros/cons fields:** Often missing length validation — verify Zod schema caps the field and the textarea shows a character counter
- [ ] **Unit selection:** Often missing chart axis labels -- verify the chart shows the correct unit in labels and tooltips - [ ] **Pros/cons display:** Often missing newline-to-bullet rendering — verify newlines in the stored text render as bullet points in the comparison view, not as `\n` characters
- [ ] **Schema changes:** Often missing test helper update — verify `tests/helpers/db.ts` includes `sort_order`, `pros`, and `cons` columns after the schema migration
---
## Recovery Strategies ## Recovery Strategies
@@ -282,13 +323,15 @@ When pitfalls occur despite prevention, how to recover.
| Pitfall | Recovery Cost | Recovery Steps | | Pitfall | Recovery Cost | Recovery Steps |
|---------|---------------|----------------| |---------|---------------|----------------|
| Classification on items instead of setup_items | HIGH | Add classification column to setup_items. Write migration to copy item classification to all setup_item rows referencing it. Remove classification from items. Review all service queries. | | Drag flicker due to no `tempItems` local state | LOW | Add `tempItems` state to the ranking component. Render from `tempItems ?? queryData.candidates`. No data migration needed. |
| Rounding drift from bidirectional conversion | MEDIUM | Audit all items for drift (compare stored grams to expected values). Fix formatWeight to convert only at display. One-time data cleanup for items with suspicious fractional grams. | | Integer `sortOrder` causing bulk updates | MEDIUM | Add Drizzle migration to change `sort_order` column type from INTEGER to REAL. Update existing rows to spaced values (1000, 2000, 3000...). Update service layer to use fractional logic. |
| Chart data disagrees with totals | LOW | Refactor chart to use the same data source as totals. Create shared utility. No data migration needed. | | Delta treats null weight as 0 | LOW | Add null guards in the delta calculation component. No data changes needed. |
| Test helper out of sync with schema | LOW | Update CREATE TABLE statements in test helper. Run all tests. Fix any that relied on the old schema. | | Pros/cons stored as unformatted blobs | LOW | No migration needed — the data is still correct. Update the rendering component to split on newlines. Add length validation to the Zod schema for new input. |
| Server-side search causing cache issues | MEDIUM | Revert to client-side filtering. Remove query params from useItems. May need to clear stale React Query cache entries with different keys. | | Comparison view visible on resolved threads | LOW | Add `if (thread.status === 'resolved') return <ResolvedView />` before rendering the comparison/ranking UI. Add 400 check in the rank update API route. |
| Candidate status without transitions | MEDIUM | Add transition validation to update endpoint. Audit existing candidates for invalid states. Write cleanup migration if needed. | | Test helper out of sync with schema | LOW | Update CREATE TABLE statements in `tests/helpers/db.ts`. Run `bun test`. Fix any test that relied on the old column count. |
| Unit preference inconsistently applied | LOW | Audit all weight display points. Ensure all use formatWeight with unit parameter. No data changes needed. | | Rank update accepts cross-thread candidateId | LOW | Add `candidate.threadId !== threadId` guard in rank update service (same pattern as existing `resolveThread` guard). |
---
## Pitfall-to-Phase Mapping ## Pitfall-to-Phase Mapping
@@ -296,27 +339,30 @@ How roadmap phases should address these pitfalls.
| Pitfall | Prevention Phase | Verification | | Pitfall | Prevention Phase | Verification |
|---------|------------------|--------------| |---------|------------------|--------------|
| Rounding accumulation | Phase 1: Weight unit selection | `formatWeight` converts grams to display unit. Edit forms load grams from API, not from displayed value. Write test: edit an item 10 times without changes, weight stays identical. | | dnd-kit + React Query flicker | Candidate ranking phase | Drop a candidate, verify no snap-back. Add automated test: mock drag end, verify list order reflects drop position immediately. |
| Classification at wrong level | Phase 2: Weight classification | `classification` column exists on `setup_items`, not `items`. Test: same item in two setups has different classifications. | | Bulk integer rank writes | Schema design for ranking | `sortOrder` column is `REAL` type in Drizzle schema. Service layer issues exactly one UPDATE per reorder. Test: reorder 5 candidates, verify only 1 DB write. |
| Server-side search for client data | Phase 1: Search/filter | No new API parameters on `GET /api/items`. Filter logic lives in `CollectionView` component. Test: search works instantly without network requests. | | Stale data in impact preview | Impact preview phase | Change a candidate's weight, verify delta updates immediately. Select a different setup, verify delta recalculates from new baseline. |
| Status without transition validation | Phase 3: Candidate status | Zod enum validates status values. Service rejects invalid transitions. Test: updating "arrived" to "researching" returns 400 error. | | Comparison broken at narrow width | Comparison UI phase | Test at 768px viewport. Verify horizontal scroll is present and content is readable. No vertical stack of comparison columns. |
| Chart/totals divergence | Phase 3: Weight visualization | Chart data and totals bar use same computation path. Test: sum of chart segment values equals displayed total. | | Pros/cons as unstructured blobs | Ranking schema phase (when columns added) | Verify Zod schema caps at 500 chars. Verify comparison view renders newlines as bullets. Test: enter 3-line pros text, verify 3 bullets rendered. |
| Test helper desync | Every schema-changing phase | Each phase's PR includes updated test helper. CI test suite catches column mismatches. | | Impact preview add vs replace | Impact preview design phase | Thread with same-category item in setup defaults to replace mode. Pure-add mode available as alternative. Test: replace mode shows negative delta when candidate is lighter. |
| Unit preference inconsistency | Phase 1: Weight unit selection | All weight displays use `formatWeight(grams, unit)`. Test: change unit preference, verify all visible weights update without refresh. | | Comparison/rank on resolved threads | Both comparison and ranking phases | Verify drag handles are absent on resolved threads. Verify rank update API returns 400 for resolved thread. |
| Test helper schema drift | Every schema-touching phase of v1.3 | After schema change, run `bun test` immediately. Zero test failures from column-not-found errors. |
---
## Sources ## Sources
- [Weight conversion precision and rounding best practices](https://explore.st-aug.edu/exp/from-ounces-to-pounds-the-precision-behind-weight-conversions-heres-how-many-grams-equal-a-practical-pound) -- authoritative source on conversion factor precision - [dnd-kit Discussion #1522: React Query + DnD flicker](https://github.com/clauderic/dnd-kit/discussions/1522) — `tempItems` solution for React Query cache flicker
- [Base weight classification definitions and community debates](https://thetrek.co/continental-divide-trail/how-to-easily-lower-your-base-weight-calculate-it-differently/) -- real-world examples of classification ambiguity - [dnd-kit Issue #921: Sorting not working with React Query](https://github.com/clauderic/dnd-kit/issues/921) — Root cause of the state lifecycle mismatch
- [LighterPack user classification errors](https://www.99boulders.com/lighterpack-tutorial) -- LighterPack's approach to base/worn/consumable - [dnd-kit Sortable Docs: OptimisticSortingPlugin](https://dndkit.com/concepts/sortable) — New API for handling optimistic reorder
- [Avoiding common mistakes with TanStack Query](https://www.buncolak.com/posts/avoiding-common-mistakes-with-tanstack-query-part-1/) -- anti-patterns with React Query caching - [TanStack Query: Optimistic Updates guide](https://tanstack.com/query/v4/docs/react/guides/optimistic-updates) — `onMutate`/`onSettled` rollback patterns
- [TanStack Query discussions on filtering with cache](https://github.com/TanStack/query/discussions/1113) -- community patterns for client-side vs server-side filtering - [Fractional Indexing: Steveruiz.me](https://www.steveruiz.me/posts/reordering-fractional-indices) — Why fractional keys beat integer reorder for databases
- [Recharts performance and limitations](https://blog.logrocket.com/best-react-chart-libraries-2025/) -- SVG rendering pitfalls, ResponsiveContainer requirement - [Fractional Indexing SQLite library](https://github.com/sqliteai/fractional-indexing) — Implementation reference for base62 lexicographic sort keys
- [Drizzle ORM SQLite migration pitfalls](https://github.com/drizzle-team/drizzle-orm/issues/1313) -- data loss bug with push + add column - [Baymard Institute: Comparison Tool Design](https://baymard.com/blog/user-friendly-comparison-tools) — Sticky headers, horizontal scroll, minimum column width for product comparison UX
- [State machine anti-patterns](https://rclayton.silvrback.com/use-state-machines) -- importance of explicit transition validation - [NN/G: Comparison Tables](https://www.nngroup.com/articles/comparison-tables/) — Avoid prose in comparison cells; use scannable structured values
- [Ultralight gear tracker leaving LighterPack](https://trailsmag.net/blogs/hiker-box/ultralight-the-gear-tracking-app-i-m-leaving-lighterpack-for) -- community frustrations with existing tools - [LogRocket: When comparison charts hurt UX](https://blog.logrocket.com/ux-design/feature-comparison-tips-when-not-to-use/) — Comparison table anti-patterns
- Direct codebase analysis of GearBox v1.1 (schema.ts, services, hooks, routes) -- existing patterns and integration points - Direct codebase analysis of GearBox v1.2 (schema.ts, thread.service.ts, setup.service.ts, CandidateCard.tsx, useSetups.ts, useCandidates.ts, tests/) — existing patterns, integration points, and established conventions
--- ---
*Pitfalls research for: GearBox v1.2 -- Collection Power-Ups (search/filter, weight classification, charts, candidate status, unit selection)* *Pitfalls research for: GearBox v1.3 — Research & Decision Tools (side-by-side comparison, impact preview, candidate ranking)*
*Researched: 2026-03-16* *Researched: 2026-03-16*

View File

@@ -1,179 +1,198 @@
# Technology Stack -- v1.2 Collection Power-Ups # Stack Research -- v1.3 Research & Decision Tools
**Project:** GearBox **Project:** GearBox
**Researched:** 2026-03-16 **Researched:** 2026-03-16
**Scope:** Stack additions for search/filter, weight classification, weight distribution charts, candidate status tracking, weight unit selection **Scope:** Stack additions for side-by-side candidate comparison, setup impact preview, and drag-to-reorder candidate ranking with pros/cons
**Confidence:** HIGH **Confidence:** HIGH
## Key Finding: Minimal New Dependencies ## Key Finding: Zero New Dependencies
Four of five v1.2 features require **zero new libraries**. They are pure application logic built on top of the existing stack (Drizzle ORM filters, Zod schema extensions, Zustand state, React Query invalidation). The only decision point is whether to add a charting library for weight distribution visualization. All three v1.3 features are achievable with the existing stack. The drag-to-reorder feature, which would normally require a dedicated DnD library, is covered by `framer-motion`'s built-in `Reorder` component — already installed at v12.37.0 with React 19 support confirmed.
## New Dependency ## Recommended Stack: Existing Technologies Only
### Charting: react-minimal-pie-chart ### No New Dependencies Required
| Technology | Version | Purpose | Why | | Feature | Library Needed | Status |
|------------|---------|---------|-----| |---------|---------------|--------|
| react-minimal-pie-chart | ^9.1.2 | Weight distribution donut/pie charts | Under 2kB gzipped. Supports pie, donut, loading, and completion chart types. SVG-based with CSS animations, hover/click interactions, custom label rendering. React 19 compatible (peerDeps explicitly include `^19`). Zero external dependencies. TypeScript native. | | Side-by-side comparison view | None — pure layout/UI | Existing Tailwind CSS |
| Setup impact preview | None — SQL delta calculation | Existing Drizzle ORM + TanStack Query |
| Drag-to-reorder candidates | `Reorder` component | Already in `framer-motion@12.37.0` |
| Pros/cons text fields | None — schema + form | Existing Drizzle + Zod + React |
**Why this over alternatives:** ### How Each Feature Uses the Existing Stack
| Criterion | react-minimal-pie-chart | Recharts | Custom SVG | Chart.js | #### 1. Side-by-Side Candidate Comparison
|-----------|------------------------|----------|------------|----------|
| Bundle size | ~2kB gzipped | ~97kB gzipped | 0kB | ~60kB gzipped |
| Chart types needed | Pie + donut (exactly what we need) | Overkill (line, bar, area, scatter, etc.) | Manual math | Overkill |
| React 19 support | Explicit in peerDeps | Isolated rendering issues reported with 19.2.x | N/A | Wrapper has open React 19 issues |
| Interactivity | Click, hover, focus, keyboard events per segment | Full but heavy | Must implement from scratch | Canvas-based (harder to style) |
| Labels | Render prop for custom labels (percentage, value, SVG) | Built-in | Must implement | Built-in |
| Animation | CSS-based, configurable duration/easing, reveal effect | D3-based, heavier | Must implement | Canvas animation |
| Learning curve | Minimal -- one component, straightforward props | Moderate -- many components | High -- SVG arc math | Moderate |
| Maintenance risk | Low -- tiny surface area, stable API | Low -- large community | Zero | Medium -- Canvas abstraction |
**Why not custom SVG:** The SVG `<circle>` + `stroke-dasharray` approach works for static charts but breaks interactivity (stacked circles mean only the last segment is clickable). The `<path>` arc approach gives full interactivity but requires implementing arc math, animation, labels, hover states, and accessibility from scratch. At ~2kB, react-minimal-pie-chart costs less than the custom code would and handles all edge cases. **No schema changes. No new dependencies.**
**Why not Recharts:** GearBox needs exactly one chart type (donut/pie). Recharts adds ~97kB of unused capability. It also had isolated rendering issues reported with React 19.2.x, and pulls in D3 submodules. Significant overkill for this use case.
## Existing Stack Usage for Each Feature
### 1. Search/Filter Items
**No new dependencies.** Uses existing Drizzle ORM operators and React state.
| Existing Tech | How It Is Used | | Existing Tech | How It Is Used |
|---------------|----------------| |---------------|----------------|
| Drizzle ORM `like()` | Server-side text search on `items.name` column. SQLite LIKE is case-insensitive by default, so no need for `ilike()`. | | Tailwind CSS v4 | Responsive comparison table layout. Horizontal scroll on mobile with `overflow-x-auto`. Fixed first column (row labels) using `sticky left-0`. |
| Drizzle ORM `eq()`, `and()` | Category filter: `eq(items.categoryId, selectedId)`. Combine with search: `and(like(...), eq(...))`. | | TanStack Query (`useThread`) | Thread detail already fetches all candidates in one query. Comparison view reads from the same cached data — no new API endpoint. |
| TanStack Query | New query key pattern: `["items", { search, categoryId }]` for filtered results. Server-side filtering preferred over client-side to establish the pattern early (collections grow). | | Lucide React | Comparison row icons (weight, price, status, link). Already in the curated icon set. |
| Zustand or URL search params | Store active filter state. URL search params preferred (already used for tab state) so filter state is shareable/bookmarkable. | | `formatWeight` / `formatPrice` | Existing formatters handle display with selected unit/currency. No changes needed. |
| Zod | Validate query params on the Hono route: `z.object({ search: z.string().optional(), categoryId: z.number().optional() })`. | | `useWeightUnit` / `useCurrency` | Existing hooks provide formatting context. Comparison view uses them identically to `CandidateCard`. |
**Implementation approach:** Add query parameters to `GET /api/items` rather than client-side filtering. Drizzle's conditional filter pattern handles optional params cleanly: **Implementation approach:** Add a view toggle (grid vs. comparison table) to the thread detail page. The comparison view is a `<table>` or CSS grid with candidates as columns and attributes as rows. Data already lives in `useThread` response — no API changes.
#### 2. Setup Impact Preview
**No new dependencies. Requires one new API endpoint.**
| Existing Tech | How It Is Used |
|---------------|----------------|
| Drizzle ORM | New query: for a given setup, sum `weight_grams` and `price_cents` of its items. Then compute delta against each candidate's `weight_grams` and `price_cents`. Pure arithmetic in the service layer. |
| TanStack Query | New `useSetupImpact(threadId, setupId)` hook fetching `GET /api/threads/:threadId/impact?setupId=X`. Returns array of `{ candidateId, weightDelta, costDelta }`. |
| Hono + Zod validator | New route validates `setupId` query param. Delegates to service function. |
| `formatWeight` / `formatPrice` | Format deltas with `+` prefix for positive values (candidate adds weight/cost) and `-` for negative (candidate is lighter/cheaper than what's already in setup). |
| `useSetups` hook | Existing `useSetups()` provides the setup list for the picker dropdown. |
**Delta calculation logic (server-side service):**
```typescript ```typescript
import { like, eq, and } from "drizzle-orm"; // For each candidate in thread:
// weightDelta = candidate.weightGrams - (matching item in setup).weightGrams
// If no matching item in setup (it would be added, not replaced): delta = candidate.weightGrams
const conditions = []; // A "matching item" means: item in setup with same categoryId as the thread.
if (search) conditions.push(like(items.name, `%${search}%`)); // This is the intended semantic: "how does picking this candidate affect my setup?"
if (categoryId) conditions.push(eq(items.categoryId, categoryId));
db.select().from(items).where(and(...conditions));
``` ```
### 2. Weight Classification (Base/Worn/Consumable) **Key decision:** Impact preview is read-only and derived. It does not mutate any data. It computes what *would* happen if the candidate were picked, without modifying the setup. The delta is displayed inline on each candidate card or in the comparison view.
**No new dependencies.** Schema change + UI state. #### 3. Drag-to-Reorder Candidate Ranking with Pros/Cons
**No new DnD library. Requires schema changes.**
| Existing Tech | How It Is Used | | Existing Tech | How It Is Used |
|---------------|----------------| |---------------|----------------|
| Drizzle ORM | Add `weightClass` column to `setup_items` table: `text("weight_class").notNull().default("base")`. Classification is per-setup-item, not per-item globally (a sleeping bag is "base" in a bikepacking setup but might be categorized differently elsewhere). | | `framer-motion@12.37.0` `Reorder` | `Reorder.Group` wraps the candidate list. `Reorder.Item` wraps each candidate card. `onReorder` updates local order state. `onDragEnd` fires the persist mutation. |
| Zod | Extend `syncSetupItemsSchema` to include classification: `z.enum(["base", "worn", "consumable"])`. | | Drizzle ORM | Two new columns on `thread_candidates`: `sortOrder integer` (default 0, lower = higher rank) and `pros text` / `cons text` (nullable). |
| drizzle-kit | Generate migration for the new column: `bun run db:generate`. | | TanStack Query mutation | `usePatchCandidate` for pros/cons text updates. `useReorderCandidates` for bulk sort order update after drag-end. |
| SQL aggregates | Compute base/worn/consumable weight subtotals server-side, same pattern as existing category totals in `useTotals`. | | Hono + Zod validator | `PATCH /api/threads/:threadId/candidates/reorder` accepts `{ candidates: Array<{ id, sortOrder }> }`. `PATCH /api/candidates/:id` accepts `{ pros?, cons? }`. |
| Zod | Extend `updateCandidateSchema` with `pros: z.string().nullable().optional()`, `cons: z.string().nullable().optional()`, `sortOrder: z.number().int().optional()`. |
**Key design decision:** Weight classification belongs on `setup_items` (the join table), not on `items` directly. An item's classification depends on context -- hiking poles are "worn" if you always use them, "base" if they pitch your tent. LighterPack follows this same model. This means the `syncSetupItemsSchema` changes from `{ itemIds: number[] }` to `{ items: Array<{ itemId: number, weightClass: "base" | "worn" | "consumable" }> }`. **Framer Motion `Reorder` API pattern:**
### 3. Weight Distribution Charts ```typescript
import { Reorder } from "framer-motion";
**One new dependency:** `react-minimal-pie-chart` (documented above). // State holds candidates sorted by sortOrder
const [orderedCandidates, setOrderedCandidates] = useState(
[...candidates].sort((a, b) => a.sortOrder - b.sortOrder)
);
| Existing Tech | How It Is Used | // onReorder fires continuously during drag — update local state only
|---------------|----------------| // onDragEnd fires once on drop — persist to DB
| TanStack Query (`useTotals`) | Already returns per-category weight totals. Extend to also return per-weight-class totals for a given setup. | <Reorder.Group
| Tailwind CSS | Style chart container, legend, responsive layout. Chart labels use Tailwind color tokens for consistency. | axis="y"
| Lucide React | Category icons in the chart legend, consistent with existing CategoryHeader component. | values={orderedCandidates}
onReorder={setOrderedCandidates}
>
{orderedCandidates.map((candidate) => (
<Reorder.Item
key={candidate.id}
value={candidate}
onDragEnd={() => persistOrder(orderedCandidates)}
>
<CandidateCard ... />
</Reorder.Item>
))}
</Reorder.Group>
```
**Chart data sources:** **Schema changes required:**
- **By category:** Already available from `GET /api/totals` response (`categories` array with `totalWeight` per category). No new endpoint needed.
- **By weight classification:** New endpoint `GET /api/setups/:id/breakdown` returning `{ base: number, worn: number, consumable: number }` computed from the `weight_class` column on `setup_items`.
### 4. Candidate Status Tracking | Table | Column | Type | Default | Purpose |
|-------|--------|------|---------|---------|
| `thread_candidates` | `sort_order` | `integer NOT NULL` | `0` | Rank position (lower = higher rank) |
| `thread_candidates` | `pros` | `text` | `NULL` | Free-text pros annotation |
| `thread_candidates` | `cons` | `text` | `NULL` | Free-text cons annotation |
**No new dependencies.** Schema change + UI update. **Sort order persistence pattern:** On drag-end, send the full reordered array with new `sortOrder` values (0-based index positions). Backend replaces existing `sort_order` values atomically. This is the same delete-all + re-insert pattern used for `setupItems` but as an UPDATE instead.
| Existing Tech | How It Is Used |
|---------------|----------------|
| Drizzle ORM | Add `status` column to `thread_candidates` table: `text("status").notNull().default("researching")`. Values: `"researching"`, `"ordered"`, `"arrived"`. |
| Zod | Add to `createCandidateSchema` and `updateCandidateSchema`: `status: z.enum(["researching", "ordered", "arrived"]).default("researching")`. |
| Tailwind CSS | Status badge colors on CandidateCard (gray for researching, amber for ordered, green for arrived). Same badge pattern used for thread status already. |
| Lucide React | Status icons: `search` for researching, `truck` for ordered, `check-circle` for arrived. Already in the curated icon set. |
### 5. Weight Unit Selection
**No new dependencies.** Settings storage + formatter change.
| Existing Tech | How It Is Used |
|---------------|----------------|
| SQLite `settings` table | Store preferred unit: `{ key: "weightUnit", value: "g" }`. Same pattern as existing onboarding settings. |
| React Query (`useSettings`) | Already exists. Fetch and cache the weight unit preference. |
| `formatWeight()` in `lib/formatters.ts` | Extend to accept a unit parameter and convert from grams (the canonical storage format). |
| Zustand (optional) | Could cache the unit preference in UI store for synchronous access in formatters. Alternatively, pass it through React context or as a parameter. |
**Conversion constants (stored weights are always grams):**
| Unit | From Grams | Display Format |
|------|-----------|----------------|
| g (grams) | `x` | `${Math.round(x)}g` |
| oz (ounces) | `x / 28.3495` | `${(x / 28.3495).toFixed(1)}oz` |
| lb (pounds) | `x / 453.592` | `${(x / 453.592).toFixed(2)}lb` |
| kg (kilograms) | `x / 1000` | `${(x / 1000).toFixed(2)}kg` |
**Key decision:** Store weights in grams always. Convert on display only. This avoids precision loss from repeated conversions and keeps the database canonical. The `formatWeight` function becomes the single conversion point.
## Installation ## Installation
```bash ```bash
# Only new dependency for v1.2 # No new packages. Zero.
bun add react-minimal-pie-chart
``` ```
That is it. One package, under 2kB gzipped. All required capabilities are already installed.
## Schema Changes Summary ## Alternatives Considered
These are the Drizzle schema modifications needed (no new tables, just column additions): ### Drag and Drop: Why Not Add a Dedicated Library?
| Table | Change | Migration | | Option | Version | React 19 Status | Verdict |
|-------|--------|-----------| |--------|---------|-----------------|---------|
| `setup_items` | Add `weightClass: text("weight_class").notNull().default("base")` | `bun run db:generate && bun run db:push` | | `framer-motion` Reorder (already installed) | 12.37.0 | React 19 explicit peerDep (`^18.0.0 || ^19.0.0`) | USE THIS |
| `thread_candidates` | Add `status: text("status").notNull().default("researching")` | `bun run db:generate && bun run db:push` | | `@dnd-kit/core` + `@dnd-kit/sortable` | 6.3.1 | No React 19 support (stale ~1yr, open GitHub issue #1511) | AVOID |
| `settings` | No schema change (already key-value). Insert `weightUnit` row. | Seed via service or onboarding. | | `@dnd-kit/react` (new rewrite) | 0.3.2 | React 19 compatible | Pre-1.0, no maintainer ETA on stable |
| `@hello-pangea/dnd` | 18.0.1 | No React 19 (stale ~1yr, peerDep `^18.0.0` only) | AVOID |
| `pragmatic-drag-and-drop` | latest | Core is React-agnostic but some sub-packages missing React 19 | Overkill for a single sortable list |
| Custom HTML5 DnD | N/A | N/A | 200+ lines of boilerplate, worse accessibility |
**Why framer-motion `Reorder` wins:** Already in the bundle. React 19 peer dep confirmed in lockfile. Handles the single use case (vertical sortable list) with 10 lines of code. Provides smooth layout animations at zero additional cost. The limitation (no cross-container drag, no multi-row grid) does not apply — candidate ranking is a single vertical list.
**Why not `@dnd-kit`:** The legacy `@dnd-kit/core@6.3.1` has no official React 19 support and has been unmaintained for ~1 year. The new `@dnd-kit/react@0.3.2` does support React 19 but is pre-1.0 with zero maintainer response on stability/roadmap questions (GitHub Discussion #1842 has 0 replies). Adding a pre-1.0 library when the project already has a working solution is unjustifiable.
### Setup Impact: Why Not Client-Side Calculation?
Client-side delta calculation (using cached React Query data) is simpler to implement but:
- Requires loading both the full setup items list AND all candidates into the client
- Introduces staleness bugs if setup items change in another tab
- Is harder to test (service test vs. component test)
Server-side calculation in a service function is testable, authoritative, and consistent with the existing architecture (services compute aggregates, not components).
## What NOT to Add ## What NOT to Add
| Avoid | Why | Use Instead | | Avoid | Why | Use Instead |
|-------|-----|-------------| |-------|-----|-------------|
| Recharts | 97kB for one chart type. React 19 edge-case issues. D3 dependency chain. | react-minimal-pie-chart (2kB) | | `@dnd-kit/core` + `@dnd-kit/sortable` | No React 19 support, stale for ~1 year (latest 6.3.1 from 2024) | `framer-motion` Reorder (already installed) |
| Chart.js / react-chartjs-2 | Canvas-based (harder to style with Tailwind). Open React 19 peer dep issues. Overkill. | react-minimal-pie-chart | | `@hello-pangea/dnd` | No React 19 support, peerDep `react: "^18.0.0"` only, stale | `framer-motion` Reorder |
| visx | Low-level D3 primitives. Steep learning curve. Have to build chart from scratch. Great for custom viz, overkill for a donut chart. | react-minimal-pie-chart | | `react-comparison-table` or similar component packages | Fragile third-party layouts for a simple table. Custom Tailwind table is trivial and design-consistent. | Custom Tailwind CSS table layout |
| Fuse.js or similar search library | Client-side fuzzy search adds bundle weight and complexity. SQLite LIKE is sufficient for name search on a single-user collection (hundreds of items, not millions). | Drizzle `like()` operator | | Modal/dialog library (Radix, Headless UI) | The project already has a hand-rolled modal pattern (`SlideOutPanel`, `ConfirmDialog`). Adding a library for one more dialog adds inconsistency. | Extend existing modal patterns |
| Full-text search (FTS5) | SQLite FTS5 is powerful but requires virtual tables and different query syntax. Overkill for simple name matching on small collections. | Drizzle `like()` operator | | Rich text editor for pros/cons | Markdown editors are overkill for a single-line annotation field. Users want a quick note, not a document. | Plain `<textarea>` with Tailwind styling |
| i18n library for unit conversion | This is not internationalization. It is four conversion constants and a formatter function. A library would be absurd. | Custom `formatWeight()` function |
| State machine library (XState) | Candidate status is a simple enum, not a complex state machine. Three values with no guards or side effects. | Zod enum + Drizzle text column |
| New Zustand store for filters | Filter state should live in URL search params for shareability/bookmarkability. The collection page already uses this pattern for tabs. | TanStack Router search params |
## Existing Stack Version Compatibility ## Stack Patterns by Variant
All existing dependencies remain unchanged. The only version consideration: **If the comparison view needs mobile scroll:**
- Wrap comparison table in `overflow-x-auto`
- Freeze the first column (attribute labels) with `sticky left-0 bg-white z-10`
- This is pure CSS, no JavaScript or library needed
| New Package | Compatible With | Verified | **If the setup impact preview needs a setup picker:**
|-------------|-----------------|----------| - Use `useSetups()` (already exists) to populate a `<select>` dropdown
| react-minimal-pie-chart ^9.1.2 | React 19 (`peerDeps: "^16.8.0 \|\| ^17 \|\| ^18 \|\| ^19"`) | YES -- package.json on GitHub confirms. Dev deps test against React 19.0.0. | - Store selected setup ID in local component state (not URL params — this is transient UI)
| react-minimal-pie-chart ^9.1.2 | TypeScript 5.x | YES -- library is TypeScript native (built with TS 3.8+). | - No new state management needed
| react-minimal-pie-chart ^9.1.2 | Bun bundler / Vite | YES -- pure ESM, no native dependencies, standard npm package. |
**If pros/cons fields need to auto-save:**
- Use a debounced mutation (300-500ms) that fires on `onChange`
- Or save on `onBlur` (simpler, adequate for this use case)
- Existing `useUpdateCandidate` hook already handles candidate mutations — extend schema only
## Version Compatibility
| Package | Version in Project | React 19 Compatible | Notes |
|---------|-------------------|---------------------|-------|
| `framer-motion` | 12.37.0 | YES — peerDeps `"^18.0.0 || ^19.0.0"` confirmed in lockfile | `Reorder` component available since v5 |
| `drizzle-orm` | 0.45.1 | N/A (server-side) | ALTER TABLE or migration for new columns |
| `zod` | 4.3.6 | N/A | Extend existing schemas |
| `@tanstack/react-query` | 5.90.21 | YES | New hooks follow existing patterns |
## Sources ## Sources
- [Drizzle ORM Filter Operators](https://orm.drizzle.team/docs/operators) -- `like`, `eq`, `and`, `or` operators for search/filter (HIGH confidence) - [framer-motion package lockfile entry] — peerDeps `react: "^18.0.0 || ^19.0.0"` confirmed (HIGH confidence, from project's `bun.lock`)
- [Drizzle ORM Conditional Filters Guide](https://orm.drizzle.team/docs/guides/conditional-filters-in-query) -- dynamic filter composition pattern (HIGH confidence) - [Motion Reorder docs](https://motion.dev/docs/react-reorder) — `Reorder.Group`, `Reorder.Item`, `useDragControls` API, `onDragEnd` pattern for persisting order (HIGH confidence)
- [react-minimal-pie-chart GitHub](https://github.com/toomuchdesign/react-minimal-pie-chart) -- version 9.1.2, React 19 peerDeps confirmed (HIGH confidence) - [Motion Changelog](https://motion.dev/changelog) — v12.37.0 actively maintained through Feb 2026 (HIGH confidence)
- [react-minimal-pie-chart package.json](https://github.com/toomuchdesign/react-minimal-pie-chart/blob/master/package.json) -- React 19 in peerDependencies and devDependencies (HIGH confidence) - [@dnd-kit/core npm](https://www.npmjs.com/package/@dnd-kit/core) — v6.3.1, last published ~1 year ago, no React 19 support (HIGH confidence)
- [Recharts npm](https://www.npmjs.com/package/recharts) -- v3.8.0, ~97kB bundle (HIGH confidence) - [dnd-kit React 19 issue #1511](https://github.com/clauderic/dnd-kit/issues/1511) — CLOSED but React 19 TypeScript issues confirmed (MEDIUM confidence)
- [Recharts React 19 issue #6857](https://github.com/recharts/recharts/issues/6857) -- rendering issues reported with React 19.2.3 (MEDIUM confidence -- may be project-specific) - [@dnd-kit/react roadmap discussion #1842](https://github.com/clauderic/dnd-kit/discussions/1842) — 0 maintainer replies on stability question (HIGH confidence — signals pre-1.0 risk)
- [LighterPack weight classification model](https://lighterpack.com) -- base/worn/consumable terminology is industry standard for gear management (HIGH confidence) - [hello-pangea/dnd React 19 issue #864](https://github.com/hello-pangea/dnd/issues/864) — React 19 support still open as of Jan 2026 (HIGH confidence)
- [Pack Weight Calculator Guide](https://backpackpeek.com/blog/pack-weight-calculator-base-weight-guide) -- weight classification definitions (HIGH confidence) - [Top 5 Drag-and-Drop Libraries for React 2026](https://puckeditor.com/blog/top-5-drag-and-drop-libraries-for-react) — ecosystem overview confirming dnd-kit and hello-pangea/dnd limitations (MEDIUM confidence)
- [SQLite LIKE case sensitivity note](https://github.com/drizzle-team/drizzle-orm-docs/issues/239) -- LIKE is case-insensitive in SQLite, no need for ilike (MEDIUM confidence)
--- ---
*Stack research for: GearBox v1.2 -- Collection Power-Ups* *Stack research for: GearBox v1.3 -- Research & Decision Tools*
*Researched: 2026-03-16* *Researched: 2026-03-16*

View File

@@ -1,207 +1,181 @@
# Project Research Summary # Project Research Summary
**Project:** GearBox v1.2 -- Collection Power-Ups **Project:** GearBox v1.3 — Research & Decision Tools
**Domain:** Gear management (bikepacking, sim racing, etc.) -- feature enhancement milestone **Domain:** Gear management — candidate comparison, setup impact preview, drag-to-reorder ranking with pros/cons
**Researched:** 2026-03-16 **Researched:** 2026-03-16
**Confidence:** HIGH **Confidence:** HIGH
## Executive Summary ## Executive Summary
GearBox v1.2 adds six features to the existing gear management app: item search/filter, weight classification (base/worn/consumable), weight distribution charts, candidate status tracking, weight unit selection, and a planning category filter upgrade. Research confirms that four of six features require zero new dependencies -- they are pure application logic built on the existing stack (Drizzle ORM, React Query, Zod, Tailwind). The sole new dependency is `react-minimal-pie-chart` (~2kB gzipped) for donut chart visualization. The codebase is well-positioned for these additions: the settings table already supports key-value preferences, the `setup_items` join table is the correct place for weight classification, and the client-side data model is small enough for in-memory filtering. GearBox v1.3 adds three decision-support features to the existing thread detail page: side-by-side candidate comparison, setup impact preview (weight/cost delta), and drag-to-reorder candidate ranking with pros/cons annotation. All four research areas converge on the same conclusion the existing stack is sufficient and no new dependencies are required. `framer-motion@12.37.0` (already installed) provides the `Reorder` component for drag-to-reorder, eliminating the need for `@dnd-kit` (which lacks React 19 support) or any other library. Two of the three features (comparison view and impact preview) require zero schema changes and can be built as pure client-side derived views using data already cached by `useThread()` and `useSetup()`.
The recommended approach is to build weight unit selection first because it refactors the `formatWeight` function that every subsequent feature depends on for display. Search/filter and candidate status tracking are independent and low-risk. Weight classification is the most architecturally significant change -- it adds a column to the `setup_items` join table and changes the sync API shape from `{ itemIds: number[] }` to `{ items: Array<{ itemId, weightClass }> }`. Weight distribution charts come last because they depend on both the unit formatter and the classification data. The two schema changes (columns on `setup_items` and `thread_candidates`) should be batched into a single Drizzle migration. The recommended build sequence is dependency-driven: schema migration first (adds `sort_order`, `pros`, `cons` to `thread_candidates`), then ranking UI (uses the new columns), then comparison view and impact preview in parallel (both are schema-independent client additions). This order eliminates the risk of mid-feature migrations and ensures the comparison table can display rank, pros, and cons from day one rather than being retrofitted. The entire milestone touches 3 new files and 10 modified files — a contained, low-blast-radius changeset.
The primary risks are: (1) weight unit conversion rounding drift from bidirectional conversion in edit forms, (2) accidentally placing weight classification on the `items` table instead of the `setup_items` join table, and (3) chart data diverging from displayed totals due to separate computation paths. All three are preventable with clear architectural rules established in the first phase: store grams canonically, convert only at the display boundary, and use a single source of truth for weight computations. The primary risks are implementation-level rather than architectural. Three patterns require deliberate design before coding: (1) use `tempItems` local state alongside React Query for drag reorder to prevent the well-documented flicker bug, (2) use `sortOrder REAL` (fractional) instead of `INTEGER` to avoid bulk UPDATE writes on every drag, and (3) treat impact preview as an "add vs replace" decision — not just a pure addition — since users comparing gear are almost always replacing an existing item, not stacking one on top. All three are avoidable with upfront design; recovery cost is low but retrofitting is disruptive.
## Key Findings ## Key Findings
### Recommended Stack ### Recommended Stack
The existing stack (React 19, Hono, Drizzle ORM, SQLite, Bun) handles all v1.2 features without modification. One small library addition is needed. Zero new dependencies are needed for this milestone. The existing stack handles all three features: Tailwind CSS for the comparison table layout, `framer-motion`'s `Reorder` component for drag ordering, Drizzle ORM + Hono + Zod for the one new write endpoint (`PATCH /api/threads/:id/candidates/reorder`), and TanStack Query for the new `useReorderCandidates` mutation. All other React Query hooks (`useThread`, `useSetup`, `useSetups`) already exist and return the data needed for comparison and impact preview without modification.
**Core technologies (all existing, no changes):** **Core technologies:**
- **Drizzle ORM `like()`, `eq()`, `and()`**: Available for server-side filtering if needed in the future, but client-side filtering is preferred at this scale - `framer-motion@12.37.0` (Reorder component): drag-to-reorder — already installed, React 19 peerDeps confirmed in `bun.lock`, replaces any need for `@dnd-kit`
- **Zod `z.enum()`**: Validates weight classification (`"base" | "worn" | "consumable"`) and candidate status (`"researching" | "ordered" | "arrived"`) with compile-time type safety - `drizzle-orm@0.45.1`: three new columns on `thread_candidates` (`sort_order REAL`, `pros TEXT`, `cons TEXT`) plus one new service function (`reorderCandidates`)
- **React Query `useSetting()`**: Reactive settings caching ensures unit preference changes propagate to all weight displays without page refresh - Tailwind CSS v4: comparison table layout with `overflow-x-auto`, `sticky left-0` for frozen label column, `min-w-[200px]` per candidate column
- **Existing `settings` table**: Key-value store supports weight unit preference with no schema change - TanStack Query v5 + existing hooks: impact preview and comparison view derived entirely from cached `useThread` + `useSetup` data — no new API endpoints on read paths
- Zod v4: extend `updateCandidateSchema` with `sortOrder: z.number().finite()`, `pros: z.string().max(500).optional()`, `cons: z.string().max(500).optional()`
**New dependency:** **What NOT to use:**
- **react-minimal-pie-chart ^9.1.2**: Donut/pie charts at ~2kB gzipped. React 19 compatible (explicit in peerDeps). Zero external dependencies. TypeScript native. Chosen over Recharts (~97kB, React 19 rendering issues reported) and Chart.js (~60kB, canvas-based, harder to style with Tailwind). - `@dnd-kit/core@6.3.1` — no React 19 support, unmaintained for ~1 year
- `@dnd-kit/react@0.3.2` — pre-1.0, no maintainer response on stability
**What NOT to add:** - `@hello-pangea/dnd@18.0.1``peerDep react: "^18.0.0"` only, stale
- Recharts, Chart.js, or visx (massive overkill for one chart type) - Any third-party comparison table component — custom Tailwind table is trivial and design-consistent
- Fuse.js or FTS5 (overkill for name search on sub-1000 item collections)
- XState (candidate status is a simple enum, not a complex state machine)
- i18n library for unit conversion (four constants and a formatter function)
### Expected Features ### Expected Features
All five v1.3 features are confirmed as P1 (must-have for this milestone). No existing gear management tool (LighterPack, GearGrams, OutPack) has comparison view, delta preview, or ranking — these are unmet-need differentiators adapted from e-commerce comparison UX to the gear domain.
**Must have (table stakes):** **Must have (table stakes):**
- **Search items by name** -- every competitor with an inventory has search; LighterPack notably lacks it and users complain - Side-by-side comparison view — users juggling 3+ candidates mentally across cards expect tabular layout; NNGroup and Smashing Magazine confirm this is the standard for comparison contexts
- **Filter items by category** -- partially exists in planning view, missing from collection view - Weight and cost delta per candidate — gear apps always display weight prominently; delta is more actionable than raw weight
- **Weight unit selection (g/oz/lb/kg)** -- universal across all competitors; gear specs come in mixed units - Setup selector for impact preview — required to contextualize the delta; `useSetups()` already exists
- **Weight classification (base/worn/consumable)** -- pioneered by LighterPack, now industry standard; "base weight" is the core metric of the ultralight community
**Should have (differentiators):** **Should have (differentiators):**
- **Weight distribution donut chart** -- LighterPack's pie chart is cited as its best feature; GearBox can uniquely combine category and classification breakdown - Drag-to-rank ordering — makes priority explicit without numeric input; no competitor has this in the gear domain; requires `sort_order` schema migration
- **Candidate status tracking (researching/ordered/arrived)** -- entirely unique to GearBox's planning thread concept; no competitor has purchase lifecycle tracking - Per-candidate pros/cons fields — structured decision rationale; stored as newline-delimited text (renders as bullets in comparison view); requires `pros`/`cons` schema migration
- **Per-setup classification** -- architecturally superior to competitors; the same item can be classified differently across setups
**Defer (v2+):** **Defer (v2+):**
- Per-item weight input in multiple units (parsing complexity) - Classification-aware impact breakdown (base/worn/consumable) — data available but UI complexity high; flat delta covers 90% of use case
- Interactive chart drill-down (click to zoom into categories) - Rank badge on card grid — useful but low urgency; add when users express confusion
- Weight goals/targets (opinionated norms conflict with hobby-agnostic design) - Mobile-optimized comparison view (swipe between candidates) — horizontal scroll works for now
- Custom weight classification labels beyond base/worn/consumable - Comparison permalink — requires auth/multi-user work not in scope for v1
- Server-side full-text search (premature for single-user scale)
- Status change timestamps on candidates (useful but not essential now) **Anti-features (explicitly rejected):**
- Custom comparison attributes — complexity trap, rejected in PROJECT.md
- Score/rating calculation — opaque algorithms distrust; manual ranking expresses user preference better
- Cross-thread comparison — candidates are decision-scoped; different categories are not apples-to-apples
### Architecture Approach ### Architecture Approach
All v1.2 features integrate into the existing three-layer architecture (client/server/database) with minimal structural changes. The client layer gains 5 new files (SearchBar, WeightChart, UnitSelector components; useFormatWeight hook; migration SQL) and modifies 15 existing files. The server layer changes are limited to the setup service (weight classification PATCH endpoint, updated sync function) and thread service (candidate status field passthrough). No new route registrations are needed in `src/server/index.ts`. The API layer (`lib/api.ts`) and UI state store (`uiStore.ts`) require no changes. All three features integrate on the `/threads/$threadId` route with no impact on other routes. The comparison view and impact preview are pure client-side derived views using data already in the React Query cache — no new API endpoints on read paths. The only new server-side endpoint is `PATCH /:id/candidates/reorder` which accepts `{ orderedIds: number[] }` and applies a transactional bulk-update in `thread.service.ts`. The `uiStore` (Zustand) gains two new fields: `compareMode: boolean` and `impactSetupId: number | null`, consistent with existing UI-state-only patterns.
**Major components:** **Major components:**
1. **`useFormatWeight` hook** -- single source of truth for unit-aware weight formatting; wraps `useSetting("weightUnit")` and `formatWeight(grams, unit)` so all weight displays stay consistent 1. `CandidateCompare.tsx` (new) — side-by-side table; columns = candidates, rows = attributes; pure presentational, derives deltas from `thread.candidates[]`; `overflow-x-auto` for narrow viewports; sticky label column
2. **`WeightChart` component** -- reusable donut chart wrapper; used in collection page (weight by category) and setup detail page (weight by classification) 2. `SetupImpactRow.tsx` (new) — delta display (`+Xg / +$Y`); reads from `useSetup(impactSetupId)` data passed as props; handles null weight case explicitly
3. **`SearchBar` component** -- reusable search input with clear button; collection page filters via `useMemo` over the cached `useItems()` data 3. `Reorder.Group` / `Reorder.Item` (framer-motion, no new file) — wraps `CandidateCard` list in `$threadId.tsx`; `onReorder` updates local `orderedCandidates` state; `onDragEnd` fires `useReorderCandidates` mutation
4. **Updated `syncSetupItems`** -- breaking API change from `{ itemIds: number[] }` to `{ items: Array<{ itemId, weightClass }> }`; single call site (ItemPicker.tsx) makes this safe 4. `CandidateCard.tsx` (modified) — gains `rank` prop (gold/silver/bronze badge for top 3), pros/cons indicator icons; `isActive={false}` when rendered inside comparison view
5. **`PATCH /api/setups/:id/items/:itemId`** -- new endpoint for updating weight classification without triggering full sync (which would destroy classification data) 5. `CandidateForm.tsx` (modified) — gains `pros`/`cons` textarea fields below existing Notes field
**Key patterns to follow:**
- `tempItems` local state alongside React Query for drag reorder — prevents the documented flicker bug; do not use `setQueryData` alone
- Client-computed derived data from cached queries — no new read endpoints (anti-pattern: building `GET /api/threads/:id/compare` or `GET /api/threads/:id/impact`)
- `uiStore` for cross-panel persistent UI flags only — no server data in Zustand
- Resolved-thread guard — `thread.status === "resolved"` must disable drag handles and block the reorder endpoint (data integrity requirement, not just UX)
### Critical Pitfalls ### Critical Pitfalls
1. **Weight unit conversion rounding drift** -- bidirectional conversion in edit forms causes grams to drift over multiple edit cycles. Always load stored grams from the API, convert for display, and convert user input back to grams once on save. Never re-convert from a previously displayed value. 1. **Drag flicker from `setQueryData`-only optimistic update** — use `tempItems` local state (`useState<Candidate[] | null>(null)`); render from `tempItems ?? queryData.candidates`; clear on mutation `onSettled`. Must be designed before building the drag UI, not retrofitted. (PITFALLS.md Pitfall 1)
2. **Weight classification at the wrong level** -- placing `classification` on the `items` table instead of `setup_items` prevents per-setup classification. A rain jacket is "worn" in summer but "base weight" in winter. This is the single most important schema decision in v1.2 and is costly to reverse. 2. **Integer `sortOrder` causes bulk writes** — use `REAL` (float) type for `sort_order` column with fractional indexing so only the moved item requires a single UPDATE. With 8+ candidates and rapid dragging, integer bulk updates produce visible latency and hold a SQLite write lock. Start values at 1000 with 1000-unit gaps. (PITFALLS.md Pitfall 2)
3. **Chart data diverging from displayed totals** -- the codebase already has two computation paths (SQL aggregates in `totals.service.ts` vs. JavaScript reduce in `$setupId.tsx`). Adding charts creates a third. Use a shared utility for weight summation and convert units only at the final display step. 3. **Impact preview shows wrong delta (add vs replace)** — default to "replace" mode when a setup item exists in the same category as the thread; default to "add" mode when no category match. Pure-addition delta misleads users: a 500g candidate replacing an 800g item shows "+500g" instead of "-300g". The distinction must be designed into the service layer, not retrofitted. (PITFALLS.md Pitfall 6)
4. **Server-side search for client-side data** -- adding search API parameters creates React Query cache fragmentation and unnecessary latency. Keep filtering client-side with `useMemo` over the cached items array. 4. **Comparison/rank on resolved threads**`thread.status === "resolved"` must hide drag handles, disable rank mutation, and show a read-only summary. The reorder API route must return 400 for resolved threads. This is a data integrity issue, not just UX. (PITFALLS.md Pitfall 8)
5. **Test helper desync with schema** -- the manual `createTestDb()` in `tests/helpers/db.ts` duplicates schema in raw SQL. Every column addition must be mirrored there or tests pass against the wrong schema. 5. **Test helper schema drift** — every schema change must update `tests/helpers/db.ts` in the same commit. Run `bun test` immediately after schema + helper update. Missing this produces `SqliteError: no such column` failures. (PITFALLS.md Pitfall 7)
## Implications for Roadmap ## Implications for Roadmap
Based on combined research, a 5-phase structure is recommended: Based on research, a 4-phase structure is recommended with a clear dependency order: schema foundation first, ranking second (consumes new columns), then comparison view and impact preview as sequential client-only phases.
### Phase 1: Weight Unit Selection ### Phase 1: Schema Foundation + Pros/Cons Fields
**Rationale:** Foundational infrastructure. The `formatWeight` refactor touches every component that displays weight (~8 call sites). All subsequent features depend on this formatter working correctly with unit awareness. Building this first means classification totals, chart labels, and setup breakdowns automatically display in the user's preferred unit. **Rationale:** All ranking and pros/cons work shares a schema migration. Batching `sort_order`, `pros`, and `cons` into a single migration avoids multiple ALTER TABLE runs and ensures the test helper is updated once. Pros/cons field UI is low-complexity (two textareas in `CandidateForm`) and can be delivered immediately after the migration, making candidates richer before ranking is built.
**Delivers:** `sort_order REAL NOT NULL DEFAULT 0`, `pros TEXT`, `cons TEXT` on `thread_candidates`; pros/cons visible in candidate edit panel; `CandidateCard` shows pros/cons indicator icons; `tests/helpers/db.ts` updated; Zod schemas extended with 500-char length caps
**Addresses:** Side-by-side comparison row data (pros/cons), drag-to-rank prerequisite (sort_order)
**Avoids:** Test helper schema drift (Pitfall 7), pros/cons as unstructured blobs (Pitfall 5 — newline-delimited format chosen at schema time)
**Delivers:** Global weight unit preference (g/oz/lb/kg) stored in settings, `useFormatWeight` hook, updated `formatWeight` function, UnitSelector component in TotalsBar, correct unit display across all existing weight surfaces (ItemCard, CandidateCard, CategoryHeader, TotalsBar, setup detail), correct unit handling in ItemForm and CandidateForm weight inputs. ### Phase 2: Drag-to-Reorder Candidate Ranking
**Addresses:** Weight unit selection (table stakes from FEATURES.md) **Rationale:** Depends on Phase 1 (`sort_order` column must exist). Schema work is done; this phase is pure service + client. The `tempItems` pattern must be implemented correctly from the start to prevent the React Query flicker bug.
**Delivers:** `reorderCandidates` service function (transactional loop); `PATCH /api/threads/:id/candidates/reorder` endpoint with thread ownership validation; `useReorderCandidates` mutation hook; `Reorder.Group` / `Reorder.Item` in thread detail route; rank badge (gold/silver/bronze) on `CandidateCard`; resolved-thread guard (no drag handles, API returns 400 for resolved)
**Uses:** `framer-motion@12.37.0` Reorder API (already installed), Drizzle ORM transaction, fractional `sort_order REAL` arithmetic (single UPDATE per drag)
**Avoids:** dnd-kit flicker (Pitfall 1 — `tempItems` pattern), bulk integer writes (Pitfall 2 — REAL type), resolved-thread corruption (Pitfall 8)
**Avoids:** Rounding drift (Pitfall 1), inconsistent unit application (Pitfall 7), flash of unconverted weights on load ### Phase 3: Side-by-Side Comparison View
**Schema changes:** None (uses existing settings table key-value store) **Rationale:** No schema dependency — can technically be built before Phase 2, but is most useful when rank, pros, and cons are already in the data model so the comparison table shows the full picture from day one. Pure client-side presentational component; no API changes.
**Delivers:** `CandidateCompare.tsx` component; "Compare" toggle button in thread header; `compareMode` in `uiStore`; comparison table with sticky label column, horizontal scroll, weight/price relative deltas (lightest/cheapest candidate highlighted); responsive at 768px viewport; read-only summary for resolved threads
**Implements:** Client-computed derived data pattern — data from `useThread()` cache; `Math.min` across candidates for relative delta; `formatWeight`/`formatPrice` for display
**Avoids:** Comparison breaking at narrow widths (Pitfall 4 — `overflow-x-auto` + `min-w-[200px]`), comparison visible on resolved threads (Pitfall 8), server endpoint for comparison deltas (architecture anti-pattern)
### Phase 2: Search, Filter, and Planning Category Filter ### Phase 4: Setup Impact Preview
**Rationale:** Pure client-side addition with no schema changes, no API changes, and no dependencies on other v1.2 features. Immediately useful as collections grow. The planning category filter upgrade fits naturally here since both involve filter UX and the icon-aware dropdown is a shared component. **Rationale:** No schema dependency. Easiest to build last because the comparison view UI (Phase 3) already establishes the thread header area where the setup selector lives. Both add-mode and replace-mode deltas must be designed here to avoid the misleading pure-addition delta.
**Delivers:** Setup selector dropdown in thread header (`useSetups()` data); `SetupImpactRow.tsx` component; `impactSetupId` in `uiStore`; add-mode delta and replace-mode delta (auto-defaults to replace when same-category item exists in setup); null weight guard ("-- (no weight data)" not "+0g"); unit-aware display via `useWeightUnit()` / `useCurrency()`
**Delivers:** Search input in collection view, icon-aware category filter dropdown (reused in gear and planning tabs), filtered item display with count ("showing 12 of 47 items"), URL search param persistence, empty state for no results, result count display. **Uses:** Existing `useSetup(id)` hook (no new API), existing `formatWeight` / `formatPrice` formatters, `categoryId` on thread for replacement item detection
**Avoids:** Stale data in impact preview (Pitfall 3 — reactive `useQuery` for setup data), wrong delta from add-vs-replace confusion (Pitfall 6), null weight treated as 0 (integration gotcha), server endpoint for delta calculation (architecture anti-pattern)
**Addresses:** Search items by name (table stakes), filter by category (table stakes), planning category filter upgrade (differentiator)
**Avoids:** Server-side search anti-pattern (Pitfall 3), search state lost on tab switch (UX pitfall), category groups disappearing incorrectly during filtering
**Schema changes:** None
### Phase 3: Candidate Status Tracking
**Rationale:** Simple schema change on `thread_candidates` with minimal integration surface. Independent of other features. Low complexity but requires awareness of the existing thread resolution flow. Schema change should be batched with Phase 4 into one Drizzle migration.
**Delivers:** Status column on candidates (researching/ordered/arrived), status badge on CandidateCard with click-to-cycle, status field in CandidateForm, Zod enum validation, status transition validation in service layer (researching -> ordered -> arrived, no backward transitions).
**Addresses:** Candidate status tracking (differentiator -- unique to GearBox)
**Avoids:** Status without transition validation (Pitfall 4), test helper desync (Pitfall 6), not handling candidate status during thread resolution
**Schema changes:** Add `status TEXT NOT NULL DEFAULT 'researching'` to `thread_candidates`
### Phase 4: Weight Classification
**Rationale:** Most architecturally significant change in v1.2. Changes the sync API shape (breaking change, single call site). Requires Phase 1 to be complete so classification totals display in the correct unit. Schema migration should be batched with Phase 3.
**Delivers:** `weightClass` column on `setup_items`, updated sync endpoint accepting `{ items: Array<{ itemId, weightClass }> }`, new `PATCH /api/setups/:id/items/:itemId` endpoint, three-segment classification toggle per item in setup detail view, base/worn/consumable weight subtotals.
**Addresses:** Weight classification base/worn/consumable (table stakes), per-setup classification (differentiator)
**Avoids:** Classification on items table (Pitfall 2), test helper desync (Pitfall 6), losing classification data on sync
**Schema changes:** Add `weight_class TEXT NOT NULL DEFAULT 'base'` to `setup_items`
### Phase 5: Weight Distribution Charts
**Rationale:** Depends on Phase 1 (unit-aware labels) and Phase 4 (classification data for setup breakdown). Only phase requiring a new npm dependency. Highest UI complexity but lowest architectural risk -- read-only visualization of existing data.
**Delivers:** `react-minimal-pie-chart` integration, `WeightChart` component, collection-level donut chart (weight by category from `useTotals()`), setup-level donut chart (weight by classification), chart legend with consistent colors, hover tooltips with formatted weights.
**Addresses:** Weight distribution visualization (differentiator)
**Avoids:** Chart/totals divergence (Pitfall 5), chart crashing on null-weight items, unnecessary chart re-renders on unrelated state changes
**Schema changes:** None (npm dependency: `bun add react-minimal-pie-chart`)
### Phase Ordering Rationale ### Phase Ordering Rationale
- **Phase 1 first** because `formatWeight` is called by every weight-displaying component. Refactoring it after other features are built means touching the same files twice. - Phase 1 before all others: SQLite schema changes batched into a single migration; test helper updated once; pros/cons in edit panel adds value immediately without waiting for the comparison view
- **Phase 2 is independent** and could be built in any order, but sequencing it second allows the team to ship a quick win while Phase 3/4 schema changes are designed. - Phase 2 before Phase 3: rank data (sort order, rank badge) is more valuable displayed in the comparison table than in the card grid alone; building the comparison view after ranking ensures the table is complete on first delivery
- **Batch Phase 3 + Phase 4 schema migrations** into one `bun run db:generate` run. Both add columns to existing tables; a single migration simplifies deployment. - Phase 3 before Phase 4: comparison view establishes the thread header chrome (toggle button area) where the setup selector in Phase 4 will live; building header UI in Phase 3 reduces Phase 4 scope
- **Phase 4 after Phase 1** because classification totals need the unit-aware formatter. - Phases 3 and 4 are technically independent and could parallelize, but sequencing them keeps the thread detail header changes contained to one phase at a time
- **Phase 5 last** because it is pure visualization depending on data from Phases 1 and 4, and introduces the only external dependency.
### Research Flags ### Research Flags
Phases likely needing deeper research during planning: Phases that need careful plan review before execution (not full research-phase, but plan must address specific design decisions):
- **Phase 4 (Weight Classification):** The sync API shape change is breaking. The existing delete-all/re-insert pattern destroys classification data. Needs careful design of the PATCH endpoint and how ItemPicker interacts with classification preservation during item add/remove. Worth a `/gsd:research-phase`. - **Phase 2:** The `tempItems` local state pattern and fractional `sort_order` arithmetic are non-obvious. The PLAN.md must spell these out explicitly before coding. PITFALLS.md Pitfall 1 and Pitfall 2 must be addressed in the plan, not discovered during implementation.
- **Phase 5 (Weight Distribution Charts):** react-minimal-pie-chart API specifics (label rendering, responsive sizing, animation control) should be validated with a quick prototype. Consider a short research spike. - **Phase 4:** The add-vs-replace distinction requires deliberate design (which mode is default, how replacement item is detected by category, how null weight is surfaced). PITFALLS.md Pitfall 6 must be resolved in the plan before the component is built.
Phases with standard patterns (skip research-phase): Phases with standard patterns (can skip `/gsd:research-phase`):
- **Phase 1 (Weight Unit Selection):** Well-documented pattern. Extend `formatWeight`, add a `useSetting` wrapper, propagate through components. No unknowns. - **Phase 1:** Standard Drizzle migration + Zod schema extension; established patterns in the codebase; ARCHITECTURE.md provides exact column definitions
- **Phase 2 (Search/Filter):** Textbook client-side filtering with `useMemo`. No API changes. Standard React pattern. - **Phase 3:** Pure presentational component; Tailwind comparison table is well-documented; ARCHITECTURE.md provides complete component structure, props interface, and delta calculation code
- **Phase 3 (Candidate Status):** Simple column addition with Zod enum validation. Existing `useUpdateCandidate` mutation already handles partial updates.
## Confidence Assessment ## Confidence Assessment
| Area | Confidence | Notes | | Area | Confidence | Notes |
|------|------------|-------| |------|------------|-------|
| Stack | HIGH | Only one new dependency (react-minimal-pie-chart). React 19 compatibility verified via package.json peerDeps. All other features use existing stack with no changes. | | Stack | HIGH | Verified from `bun.lock` (framer-motion React 19 peerDeps confirmed); dnd-kit abandonment verified via npm + GitHub; Motion Reorder API verified via motion.dev docs |
| Features | HIGH | Feature set derived from analysis of 8+ competing tools (LighterPack, Hikt, PackLight, Packstack, HikeLite, Packrat, OutPack, BPL Calculator). Clear consensus on table stakes vs. differentiators. | | Features | HIGH | Codebase analysis confirmed no rank/pros/cons columns in existing schema; NNGroup + Smashing Magazine for comparison UX patterns; competitor analysis (LighterPack, GearGrams, OutPack) confirmed feature gap |
| Architecture | HIGH | Based on direct codebase analysis with integration points mapped to specific files. The 5 new / 15 modified file inventory is concrete and verified against the existing codebase. | | Architecture | HIGH | Full integration map derived from direct codebase analysis; build order confirmed by column dependency graph; all changed files enumerated (3 new, 10 modified); complete code patterns provided |
| Pitfalls | HIGH | Derived from codebase-specific patterns (test helper duplication, dual computation paths) combined with domain risks (unit conversion rounding, classification scope). Not generic warnings. | | Pitfalls | HIGH | dnd-kit flicker: verified in GitHub Discussion #1522 and Issue #921; fractional indexing: verified via steveruiz.me and fractional-indexing library; comparison UX: Baymard Institute and NNGroup |
**Overall confidence:** HIGH **Overall confidence:** HIGH
### Gaps to Address ### Gaps to Address
- **`lb` display format:** FEATURES.md suggests "2 lb 3 oz" (pounds + remainder ounces) while STACK.md suggests simpler decimal format. The traditional "lb + oz" format is more useful to American users but adds formatting complexity. Decide during Phase 1 implementation. - **Impact preview add-vs-replace UX:** Research establishes that both modes are needed and when to default to each (same-category item in setup = replace mode). The exact affordance — dropdown to select which item is replaced vs. automatic category matching — is not fully specified. Recommendation: auto-match by category with a "change" link to override. Decide during Phase 4 planning.
- **Status change timestamps:** PITFALLS.md recommends storing `statusChangedAt` alongside `status` for staleness detection ("ordered 30 days ago -- still waiting?"). Low effort to add during the schema migration. Decide during Phase 3 planning. - **Comparison view maximum candidate count:** Research recommends 3-4 max for usability. GearBox has no current limit on candidates per thread. Whether to enforce a hard display limit (hide additional candidates behind "show more") or allow unrestricted horizontal scroll should be decided during Phase 3 planning.
- **Sync API backward compatibility:** The sync endpoint shape changes from `{ itemIds: number[] }` to `{ items: [...] }`. Single call site (ItemPicker.tsx), but verify no external consumers exist before shipping. - **Sort order initialization for existing candidates:** When the migration runs, existing `thread_candidates` rows get `sort_order = 0` (default). Phase 1 plan must specify whether to initialize existing candidates with spaced values (e.g., 1000, 2000, 3000) at migration time or accept that all existing rows start at 0 and rely on first drag to establish order.
- **react-minimal-pie-chart responsive behavior:** SVG-based and should handle responsive sizing, but exact approach (CSS width vs. explicit size prop) should be validated in Phase 5. Not a risk, just a detail to confirm.
## Sources ## Sources
### Primary (HIGH confidence) ### Primary (HIGH confidence)
- [Drizzle ORM Filter Operators](https://orm.drizzle.team/docs/operators) -- like, eq, and operators for search/filter - `bun.lock` (project lockfile) — framer-motion v12.37.0 peerDeps `"react: ^18.0.0 || ^19.0.0"` confirmed
- [Drizzle ORM Conditional Filters Guide](https://orm.drizzle.team/docs/guides/conditional-filters-in-query) -- dynamic filter composition - [Motion Reorder docs](https://motion.dev/docs/react-reorder) `Reorder.Group`, `Reorder.Item`, `onDragEnd` API
- [react-minimal-pie-chart GitHub](https://github.com/toomuchdesign/react-minimal-pie-chart) -- v9.1.2, React 19 peerDeps verified in package.json - [dnd-kit Discussion #1522](https://github.com/clauderic/dnd-kit/discussions/1522) — `tempItems` solution for React Query cache flicker
- [LighterPack](https://lighterpack.com/) -- base/worn/consumable classification standard, pie chart visualization pattern - [dnd-kit Issue #921](https://github.com/clauderic/dnd-kit/issues/921) — root cause of state lifecycle mismatch
- [99Boulders LighterPack Tutorial](https://www.99boulders.com/lighterpack-tutorial) -- classification definitions and feature walkthrough - [Fractional Indexing — steveruiz.me](https://www.steveruiz.me/posts/reordering-fractional-indices) — why float sort keys beat integer reorder for databases
- [BackpackPeek Pack Weight Calculator Guide](https://backpackpeek.com/blog/pack-weight-calculator-base-weight-guide) -- weight classification methodology - [Baymard Institute: Comparison Tool Design](https://baymard.com/blog/user-friendly-comparison-tools) — sticky headers, horizontal scroll, minimum column width
- Direct codebase analysis of GearBox v1.1 -- schema.ts, services, hooks, routes, test helpers - [NNGroup: Comparison Tables](https://www.nngroup.com/articles/comparison-tables/) — information architecture, anti-patterns
- [Smashing Magazine: Feature Comparison Table](https://www.smashingmagazine.com/2017/08/designing-perfect-feature-comparison-table/) — table layout patterns
- GearBox codebase direct analysis (`src/db/schema.ts`, `src/server/services/`, `src/client/hooks/`, `tests/helpers/db.ts`) — confirmed existing patterns, missing columns, integration points
### Secondary (MEDIUM confidence) ### Secondary (MEDIUM confidence)
- [Hikt](https://hikt.app/) -- searchable gear closet, base vs worn weight display - [@dnd-kit/core npm](https://www.npmjs.com/package/@dnd-kit/core) — v6.3.1 last published ~1 year ago, no React 19
- [PackLight (iOS)](https://apps.apple.com/us/app/packlight-for-backpacking/id1054845207) -- search, categories, bar graph visualization - [dnd-kit React 19 issue #1511](https://github.com/clauderic/dnd-kit/issues/1511) — CLOSED but React 19 TypeScript issues confirmed
- [Packstack](https://www.packstack.io/) -- base/worn/consumable weight separation - [@dnd-kit/react roadmap discussion #1842](https://github.com/clauderic/dnd-kit/discussions/1842) — 0 maintainer replies; pre-1.0 risk signal
- [Packrat](https://www.packrat.app/) -- flexible weight unit input and display conversion - [hello-pangea/dnd React 19 issue #864](https://github.com/hello-pangea/dnd/issues/864) — still open as of Jan 2026
- [Recharts React 19 issue #6857](https://github.com/recharts/recharts/issues/6857) -- rendering issues with React 19.2.3 - [BrightCoding dnd-kit deep dive (2025)](https://www.blog.brightcoding.dev/2025/08/21/the-ultimate-drag-and-drop-toolkit-for-react-a-deep-dive-into-dnd-kit/) react-beautiful-dnd abandoned; dnd-kit current standard but React 19 gap confirmed
- [TanStack Query filtering discussions](https://github.com/TanStack/query/discussions/1113) -- client-side vs server-side filtering patterns - [TrailsMag: Leaving LighterPack](https://trailsmag.net/blogs/hiker-box/ultralight-the-gear-tracking-app-i-m-leaving-lighterpack-for) — LighterPack feature gap analysis
- [LogRocket Best React Chart Libraries 2025](https://blog.logrocket.com/best-react-chart-libraries-2025/) -- chart library comparison - [Contentsquare: Comparing products UX](https://contentsquare.com/blog/comparing-products-design-practices-to-help-your-users-avoid-fragmented-comparison-7/) — fragmented comparison pitfalls
### Tertiary (LOW confidence) ### Tertiary (LOW confidence)
- [SQLite LIKE case sensitivity](https://github.com/drizzle-team/drizzle-orm-docs/issues/239) -- LIKE is case-insensitive in SQLite (relevant only if search moves server-side) - [Fractional Indexing SQLite library](https://github.com/sqliteai/fractional-indexing) — implementation reference for lexicographic sort keys (pattern reference only; direct float arithmetic sufficient for this use case)
- [Drizzle ORM SQLite migration pitfalls #1313](https://github.com/drizzle-team/drizzle-orm/issues/1313) -- data loss bug with push + add column (monitor during migration) - [Top 5 Drag-and-Drop Libraries for React 2026](https://puckeditor.com/blog/top-5-drag-and-drop-libraries-for-react) — ecosystem overview confirming dnd-kit and hello-pangea/dnd limitations
--- ---
*Research completed: 2026-03-16* *Research completed: 2026-03-16*

View File

@@ -0,0 +1,2 @@
ALTER TABLE `thread_candidates` ADD `pros` text;--> statement-breakpoint
ALTER TABLE `thread_candidates` ADD `cons` text;

View File

@@ -0,0 +1 @@
ALTER TABLE `thread_candidates` ADD `sort_order` real DEFAULT 0 NOT NULL;

View File

@@ -0,0 +1,497 @@
{
"version": "6",
"dialect": "sqlite",
"id": "529d2e93-7d7f-4a83-bb29-254ce09cdef4",
"prevId": "628b9ef4-c715-4bbe-a118-042d80fde91e",
"tables": {
"categories": {
"name": "categories",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'package'"
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"categories_name_unique": {
"name": "categories_name_unique",
"columns": [
"name"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"items": {
"name": "items",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"weight_grams": {
"name": "weight_grams",
"type": "real",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"price_cents": {
"name": "price_cents",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"category_id": {
"name": "category_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"notes": {
"name": "notes",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"product_url": {
"name": "product_url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"image_filename": {
"name": "image_filename",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"items_category_id_categories_id_fk": {
"name": "items_category_id_categories_id_fk",
"tableFrom": "items",
"tableTo": "categories",
"columnsFrom": [
"category_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"settings": {
"name": "settings",
"columns": {
"key": {
"name": "key",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"value": {
"name": "value",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"setup_items": {
"name": "setup_items",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"setup_id": {
"name": "setup_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"item_id": {
"name": "item_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"classification": {
"name": "classification",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'base'"
}
},
"indexes": {},
"foreignKeys": {
"setup_items_setup_id_setups_id_fk": {
"name": "setup_items_setup_id_setups_id_fk",
"tableFrom": "setup_items",
"tableTo": "setups",
"columnsFrom": [
"setup_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"setup_items_item_id_items_id_fk": {
"name": "setup_items_item_id_items_id_fk",
"tableFrom": "setup_items",
"tableTo": "items",
"columnsFrom": [
"item_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"setups": {
"name": "setups",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"thread_candidates": {
"name": "thread_candidates",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"thread_id": {
"name": "thread_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"weight_grams": {
"name": "weight_grams",
"type": "real",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"price_cents": {
"name": "price_cents",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"category_id": {
"name": "category_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"notes": {
"name": "notes",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"product_url": {
"name": "product_url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"image_filename": {
"name": "image_filename",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"status": {
"name": "status",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'researching'"
},
"pros": {
"name": "pros",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"cons": {
"name": "cons",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"thread_candidates_thread_id_threads_id_fk": {
"name": "thread_candidates_thread_id_threads_id_fk",
"tableFrom": "thread_candidates",
"tableTo": "threads",
"columnsFrom": [
"thread_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"thread_candidates_category_id_categories_id_fk": {
"name": "thread_candidates_category_id_categories_id_fk",
"tableFrom": "thread_candidates",
"tableTo": "categories",
"columnsFrom": [
"category_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"threads": {
"name": "threads",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"status": {
"name": "status",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'active'"
},
"resolved_candidate_id": {
"name": "resolved_candidate_id",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"category_id": {
"name": "category_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"threads_category_id_categories_id_fk": {
"name": "threads_category_id_categories_id_fk",
"tableFrom": "threads",
"tableTo": "categories",
"columnsFrom": [
"category_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}

View File

@@ -0,0 +1,505 @@
{
"version": "6",
"dialect": "sqlite",
"id": "297e86db-c777-4432-950e-b0129dedb2dc",
"prevId": "529d2e93-7d7f-4a83-bb29-254ce09cdef4",
"tables": {
"categories": {
"name": "categories",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"icon": {
"name": "icon",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'package'"
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {
"categories_name_unique": {
"name": "categories_name_unique",
"columns": [
"name"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"items": {
"name": "items",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"weight_grams": {
"name": "weight_grams",
"type": "real",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"price_cents": {
"name": "price_cents",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"category_id": {
"name": "category_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"notes": {
"name": "notes",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"product_url": {
"name": "product_url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"image_filename": {
"name": "image_filename",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"items_category_id_categories_id_fk": {
"name": "items_category_id_categories_id_fk",
"tableFrom": "items",
"tableTo": "categories",
"columnsFrom": [
"category_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"settings": {
"name": "settings",
"columns": {
"key": {
"name": "key",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"value": {
"name": "value",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"setup_items": {
"name": "setup_items",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"setup_id": {
"name": "setup_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"item_id": {
"name": "item_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"classification": {
"name": "classification",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'base'"
}
},
"indexes": {},
"foreignKeys": {
"setup_items_setup_id_setups_id_fk": {
"name": "setup_items_setup_id_setups_id_fk",
"tableFrom": "setup_items",
"tableTo": "setups",
"columnsFrom": [
"setup_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"setup_items_item_id_items_id_fk": {
"name": "setup_items_item_id_items_id_fk",
"tableFrom": "setup_items",
"tableTo": "items",
"columnsFrom": [
"item_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"setups": {
"name": "setups",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"thread_candidates": {
"name": "thread_candidates",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"thread_id": {
"name": "thread_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"weight_grams": {
"name": "weight_grams",
"type": "real",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"price_cents": {
"name": "price_cents",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"category_id": {
"name": "category_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"notes": {
"name": "notes",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"product_url": {
"name": "product_url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"image_filename": {
"name": "image_filename",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"status": {
"name": "status",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'researching'"
},
"pros": {
"name": "pros",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"cons": {
"name": "cons",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"sort_order": {
"name": "sort_order",
"type": "real",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"thread_candidates_thread_id_threads_id_fk": {
"name": "thread_candidates_thread_id_threads_id_fk",
"tableFrom": "thread_candidates",
"tableTo": "threads",
"columnsFrom": [
"thread_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"thread_candidates_category_id_categories_id_fk": {
"name": "thread_candidates_category_id_categories_id_fk",
"tableFrom": "thread_candidates",
"tableTo": "categories",
"columnsFrom": [
"category_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"threads": {
"name": "threads",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"status": {
"name": "status",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'active'"
},
"resolved_candidate_id": {
"name": "resolved_candidate_id",
"type": "integer",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"category_id": {
"name": "category_id",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"updated_at": {
"name": "updated_at",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"threads_category_id_categories_id_fk": {
"name": "threads_category_id_categories_id_fk",
"tableFrom": "threads",
"tableTo": "categories",
"columnsFrom": [
"category_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}

View File

@@ -29,6 +29,20 @@
"when": 1773670263013, "when": 1773670263013,
"tag": "0003_misty_mongu", "tag": "0003_misty_mongu",
"breakpoints": true "breakpoints": true
},
{
"idx": 4,
"version": "6",
"when": 1773693113029,
"tag": "0004_soft_synch",
"breakpoints": true
},
{
"idx": 5,
"version": "6",
"when": 1773696058992,
"tag": "0005_clear_micromax",
"breakpoints": true
} }
] ]
} }

View File

@@ -1,7 +1,9 @@
import { useCurrency } from "../hooks/useCurrency";
import { useWeightUnit } from "../hooks/useWeightUnit"; import { useWeightUnit } from "../hooks/useWeightUnit";
import { formatPrice, formatWeight } from "../lib/formatters"; import { formatPrice, formatWeight } from "../lib/formatters";
import { LucideIcon } from "../lib/iconData"; import { LucideIcon } from "../lib/iconData";
import { useUIStore } from "../stores/uiStore"; import { useUIStore } from "../stores/uiStore";
import { RankBadge } from "./CandidateListItem";
import { StatusBadge } from "./StatusBadge"; import { StatusBadge } from "./StatusBadge";
interface CandidateCardProps { interface CandidateCardProps {
@@ -17,6 +19,9 @@ interface CandidateCardProps {
isActive: boolean; isActive: boolean;
status: "researching" | "ordered" | "arrived"; status: "researching" | "ordered" | "arrived";
onStatusChange: (status: "researching" | "ordered" | "arrived") => void; onStatusChange: (status: "researching" | "ordered" | "arrived") => void;
pros?: string | null;
cons?: string | null;
rank?: number;
} }
export function CandidateCard({ export function CandidateCard({
@@ -32,8 +37,12 @@ export function CandidateCard({
isActive, isActive,
status, status,
onStatusChange, onStatusChange,
pros,
cons,
rank,
}: CandidateCardProps) { }: CandidateCardProps) {
const unit = useWeightUnit(); const unit = useWeightUnit();
const currency = useCurrency();
const openCandidateEditPanel = useUIStore((s) => s.openCandidateEditPanel); const openCandidateEditPanel = useUIStore((s) => s.openCandidateEditPanel);
const openConfirmDeleteCandidate = useUIStore( const openConfirmDeleteCandidate = useUIStore(
(s) => s.openConfirmDeleteCandidate, (s) => s.openConfirmDeleteCandidate,
@@ -42,14 +51,74 @@ export function CandidateCard({
const openExternalLink = useUIStore((s) => s.openExternalLink); const openExternalLink = useUIStore((s) => s.openExternalLink);
return ( return (
<div className="relative bg-white rounded-xl border border-gray-100 hover:border-gray-200 hover:shadow-sm transition-all overflow-hidden group"> <button
type="button"
onClick={() => openCandidateEditPanel(id)}
className="relative w-full text-left bg-white rounded-xl border border-gray-100 hover:border-gray-200 hover:shadow-sm transition-all overflow-hidden group"
>
{/* Hover-reveal action buttons */}
{isActive && (
<span
role="button"
tabIndex={0}
onClick={(e) => {
e.stopPropagation();
openResolveDialog(threadId, id);
}}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.stopPropagation();
openResolveDialog(threadId, id);
}
}}
className="absolute top-2 left-2 z-10 px-2 py-0.5 flex items-center gap-1 rounded-full text-xs font-medium bg-amber-100/90 text-amber-700 hover:bg-amber-200 opacity-0 group-hover:opacity-100 transition-all cursor-pointer"
title="Pick as winner"
>
<LucideIcon name="trophy" size={12} />
Winner
</span>
)}
<span
role="button"
tabIndex={0}
onClick={(e) => {
e.stopPropagation();
openConfirmDeleteCandidate(id);
}}
onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") {
e.stopPropagation();
openConfirmDeleteCandidate(id);
}
}}
className={`absolute top-2 ${productUrl ? "right-10" : "right-2"} z-10 w-6 h-6 flex items-center justify-center rounded-full bg-gray-100/80 text-gray-400 hover:bg-red-100 hover:text-red-500 opacity-0 group-hover:opacity-100 transition-all cursor-pointer`}
title="Delete candidate"
>
<svg
className="w-3.5 h-3.5"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</span>
{productUrl && ( {productUrl && (
<span <span
role="button" role="button"
tabIndex={0} tabIndex={0}
onClick={() => openExternalLink(productUrl)} onClick={(e) => {
e.stopPropagation();
openExternalLink(productUrl);
}}
onKeyDown={(e) => { onKeyDown={(e) => {
if (e.key === "Enter" || e.key === " ") { if (e.key === "Enter" || e.key === " ") {
e.stopPropagation();
openExternalLink(productUrl); openExternalLink(productUrl);
} }
}} }}
@@ -92,7 +161,8 @@ export function CandidateCard({
<h3 className="text-sm font-semibold text-gray-900 mb-2 truncate"> <h3 className="text-sm font-semibold text-gray-900 mb-2 truncate">
{name} {name}
</h3> </h3>
<div className="flex flex-wrap gap-1.5 mb-3"> <div className="flex flex-wrap gap-1.5">
{rank != null && <RankBadge rank={rank} />}
{weightGrams != null && ( {weightGrams != null && (
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-blue-50 text-blue-400"> <span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-blue-50 text-blue-400">
{formatWeight(weightGrams, unit)} {formatWeight(weightGrams, unit)}
@@ -100,7 +170,7 @@ export function CandidateCard({
)} )}
{priceCents != null && ( {priceCents != null && (
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-50 text-green-500"> <span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-50 text-green-500">
{formatPrice(priceCents)} {formatPrice(priceCents, currency)}
</span> </span>
)} )}
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-gray-50 text-gray-600"> <span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-gray-50 text-gray-600">
@@ -112,33 +182,13 @@ export function CandidateCard({
{categoryName} {categoryName}
</span> </span>
<StatusBadge status={status} onStatusChange={onStatusChange} /> <StatusBadge status={status} onStatusChange={onStatusChange} />
</div> {(pros || cons) && (
<div className="flex gap-2"> <span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-purple-50 text-purple-700">
<button +/- Notes
type="button" </span>
onClick={() => openCandidateEditPanel(id)}
className="text-xs text-gray-500 hover:text-gray-700 transition-colors"
>
Edit
</button>
<button
type="button"
onClick={() => openConfirmDeleteCandidate(id)}
className="text-xs text-gray-500 hover:text-red-600 transition-colors"
>
Delete
</button>
{isActive && (
<button
type="button"
onClick={() => openResolveDialog(threadId, id)}
className="ml-auto text-xs font-medium text-amber-600 hover:text-amber-700 transition-colors"
>
Pick Winner
</button>
)} )}
</div> </div>
</div> </div>
</div> </button>
); );
} }

View File

@@ -19,6 +19,8 @@ interface FormData {
notes: string; notes: string;
productUrl: string; productUrl: string;
imageFilename: string | null; imageFilename: string | null;
pros: string;
cons: string;
} }
const INITIAL_FORM: FormData = { const INITIAL_FORM: FormData = {
@@ -29,6 +31,8 @@ const INITIAL_FORM: FormData = {
notes: "", notes: "",
productUrl: "", productUrl: "",
imageFilename: null, imageFilename: null,
pros: "",
cons: "",
}; };
export function CandidateForm({ export function CandidateForm({
@@ -61,6 +65,8 @@ export function CandidateForm({
notes: candidate.notes ?? "", notes: candidate.notes ?? "",
productUrl: candidate.productUrl ?? "", productUrl: candidate.productUrl ?? "",
imageFilename: candidate.imageFilename, imageFilename: candidate.imageFilename,
pros: candidate.pros ?? "",
cons: candidate.cons ?? "",
}); });
} }
} else if (mode === "add") { } else if (mode === "add") {
@@ -110,6 +116,8 @@ export function CandidateForm({
notes: form.notes.trim() || undefined, notes: form.notes.trim() || undefined,
productUrl: form.productUrl.trim() || undefined, productUrl: form.productUrl.trim() || undefined,
imageFilename: form.imageFilename ?? undefined, imageFilename: form.imageFilename ?? undefined,
pros: form.pros.trim() || undefined,
cons: form.cons.trim() || undefined,
}; };
if (mode === "add") { if (mode === "add") {
@@ -239,6 +247,42 @@ export function CandidateForm({
/> />
</div> </div>
{/* Pros */}
<div>
<label
htmlFor="candidate-pros"
className="block text-sm font-medium text-gray-700 mb-1"
>
Pros
</label>
<textarea
id="candidate-pros"
value={form.pros}
onChange={(e) => setForm((f) => ({ ...f, pros: e.target.value }))}
rows={3}
className="w-full px-3 py-2 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-gray-400 focus:border-transparent resize-none"
placeholder="One pro per line..."
/>
</div>
{/* Cons */}
<div>
<label
htmlFor="candidate-cons"
className="block text-sm font-medium text-gray-700 mb-1"
>
Cons
</label>
<textarea
id="candidate-cons"
value={form.cons}
onChange={(e) => setForm((f) => ({ ...f, cons: e.target.value }))}
rows={3}
className="w-full px-3 py-2 border border-gray-200 rounded-lg text-sm focus:outline-none focus:ring-2 focus:ring-gray-400 focus:border-transparent resize-none"
placeholder="One con per line..."
/>
</div>
{/* Product Link */} {/* Product Link */}
<div> <div>
<label <label

View File

@@ -0,0 +1,211 @@
import { Reorder, useDragControls } from "framer-motion";
import { useCurrency } from "../hooks/useCurrency";
import { useWeightUnit } from "../hooks/useWeightUnit";
import { formatPrice, formatWeight } from "../lib/formatters";
import { LucideIcon } from "../lib/iconData";
import { useUIStore } from "../stores/uiStore";
import { StatusBadge } from "./StatusBadge";
interface CandidateWithCategory {
id: number;
threadId: number;
name: string;
weightGrams: number | null;
priceCents: number | null;
categoryId: number;
notes: string | null;
productUrl: string | null;
imageFilename: string | null;
status: "researching" | "ordered" | "arrived";
pros: string | null;
cons: string | null;
createdAt: string;
updatedAt: string;
categoryName: string;
categoryIcon: string;
}
interface CandidateListItemProps {
candidate: CandidateWithCategory;
rank: number;
isActive: boolean;
onStatusChange: (status: "researching" | "ordered" | "arrived") => void;
}
const RANK_COLORS = ["#D4AF37", "#C0C0C0", "#CD7F32"]; // gold, silver, bronze
export function RankBadge({ rank }: { rank: number }) {
if (rank > 3) return null;
return (
<LucideIcon
name="medal"
size={16}
className="shrink-0"
style={{ color: RANK_COLORS[rank - 1] }}
/>
);
}
export function CandidateListItem({
candidate,
rank,
isActive,
onStatusChange,
}: CandidateListItemProps) {
const controls = useDragControls();
const unit = useWeightUnit();
const currency = useCurrency();
const openCandidateEditPanel = useUIStore((s) => s.openCandidateEditPanel);
const openConfirmDeleteCandidate = useUIStore(
(s) => s.openConfirmDeleteCandidate,
);
const openResolveDialog = useUIStore((s) => s.openResolveDialog);
const openExternalLink = useUIStore((s) => s.openExternalLink);
return (
<Reorder.Item
value={candidate}
dragControls={controls}
dragListener={false}
className="flex items-center gap-3 bg-white rounded-xl border border-gray-100 p-3 hover:border-gray-200 hover:shadow-sm transition-all group cursor-default"
>
{/* Drag handle */}
{isActive && (
<button
type="button"
onPointerDown={(e) => controls.start(e)}
className="cursor-grab active:cursor-grabbing text-gray-300 hover:text-gray-500 touch-none shrink-0"
title="Drag to reorder"
>
<LucideIcon name="grip-vertical" size={16} />
</button>
)}
{/* Rank badge */}
<RankBadge rank={rank} />
{/* Image thumbnail */}
<div className="w-12 h-12 rounded-lg overflow-hidden shrink-0 bg-gray-50 flex items-center justify-center">
{candidate.imageFilename ? (
<img
src={`/uploads/${candidate.imageFilename}`}
alt={candidate.name}
className="w-full h-full object-cover"
/>
) : (
<LucideIcon
name={candidate.categoryIcon}
size={20}
className="text-gray-400"
/>
)}
</div>
{/* Name + badges */}
<button
type="button"
onClick={() => openCandidateEditPanel(candidate.id)}
className="flex-1 min-w-0 text-left"
>
<p className="text-sm font-semibold text-gray-900 truncate">
{candidate.name}
</p>
<div className="flex flex-wrap gap-1.5 mt-1">
{candidate.weightGrams != null && (
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-blue-50 text-blue-400">
{formatWeight(candidate.weightGrams, unit)}
</span>
)}
{candidate.priceCents != null && (
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-50 text-green-500">
{formatPrice(candidate.priceCents, currency)}
</span>
)}
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-gray-50 text-gray-600">
<LucideIcon
name={candidate.categoryIcon}
size={14}
className="inline-block mr-1 text-gray-500"
/>
{candidate.categoryName}
</span>
<StatusBadge
status={candidate.status}
onStatusChange={onStatusChange}
/>
{(candidate.pros || candidate.cons) && (
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-purple-50 text-purple-700">
+/- Notes
</span>
)}
</div>
</button>
{/* Action buttons (hover-reveal) */}
<div className="flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity shrink-0">
{isActive && (
<button
type="button"
onClick={(e) => {
e.stopPropagation();
openResolveDialog(candidate.threadId, candidate.id);
}}
className="px-2 py-0.5 flex items-center gap-1 rounded-full text-xs font-medium bg-amber-100/90 text-amber-700 hover:bg-amber-200 cursor-pointer"
title="Pick as winner"
>
<LucideIcon name="trophy" size={12} />
Winner
</button>
)}
{candidate.productUrl && (
<button
type="button"
onClick={(e) => {
e.stopPropagation();
openExternalLink(candidate.productUrl as string);
}}
className="w-6 h-6 flex items-center justify-center rounded-full bg-gray-100/80 text-gray-400 hover:bg-gray-200 hover:text-gray-600 cursor-pointer"
title="Open product link"
>
<svg
className="w-3.5 h-3.5"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6M15 3h6v6M10 14L21 3"
/>
</svg>
</button>
)}
<button
type="button"
onClick={(e) => {
e.stopPropagation();
openConfirmDeleteCandidate(candidate.id);
}}
className="w-6 h-6 flex items-center justify-center rounded-full bg-gray-100/80 text-gray-400 hover:bg-red-100 hover:text-red-500 cursor-pointer"
title="Delete candidate"
>
<svg
className="w-3.5 h-3.5"
fill="none"
stroke="currentColor"
viewBox="0 0 24 24"
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
</div>
</Reorder.Item>
);
}

View File

@@ -1,5 +1,6 @@
import { useState } from "react"; import { useState } from "react";
import { useDeleteCategory, useUpdateCategory } from "../hooks/useCategories"; import { useDeleteCategory, useUpdateCategory } from "../hooks/useCategories";
import { useCurrency } from "../hooks/useCurrency";
import { useWeightUnit } from "../hooks/useWeightUnit"; import { useWeightUnit } from "../hooks/useWeightUnit";
import { formatPrice, formatWeight } from "../lib/formatters"; import { formatPrice, formatWeight } from "../lib/formatters";
import { LucideIcon } from "../lib/iconData"; import { LucideIcon } from "../lib/iconData";
@@ -23,6 +24,7 @@ export function CategoryHeader({
itemCount, itemCount,
}: CategoryHeaderProps) { }: CategoryHeaderProps) {
const unit = useWeightUnit(); const unit = useWeightUnit();
const currency = useCurrency();
const [isEditing, setIsEditing] = useState(false); const [isEditing, setIsEditing] = useState(false);
const [editName, setEditName] = useState(name); const [editName, setEditName] = useState(name);
const [editIcon, setEditIcon] = useState(icon); const [editIcon, setEditIcon] = useState(icon);
@@ -87,7 +89,7 @@ export function CategoryHeader({
<h2 className="text-lg font-semibold text-gray-900">{name}</h2> <h2 className="text-lg font-semibold text-gray-900">{name}</h2>
<span className="text-sm text-gray-400"> <span className="text-sm text-gray-400">
{itemCount} {itemCount === 1 ? "item" : "items"} ·{" "} {itemCount} {itemCount === 1 ? "item" : "items"} ·{" "}
{formatWeight(totalWeight, unit)} · {formatPrice(totalCost)} {formatWeight(totalWeight, unit)} · {formatPrice(totalCost, currency)}
</span> </span>
{!isUncategorized && ( {!isUncategorized && (
<div className="ml-auto flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity"> <div className="ml-auto flex items-center gap-1 opacity-0 group-hover:opacity-100 transition-opacity">

View File

@@ -1,7 +1,9 @@
import { useCurrency } from "../hooks/useCurrency";
import { useWeightUnit } from "../hooks/useWeightUnit"; import { useWeightUnit } from "../hooks/useWeightUnit";
import { formatPrice, formatWeight } from "../lib/formatters"; import { formatPrice, formatWeight } from "../lib/formatters";
import { LucideIcon } from "../lib/iconData"; import { LucideIcon } from "../lib/iconData";
import { useUIStore } from "../stores/uiStore"; import { useUIStore } from "../stores/uiStore";
import { ClassificationBadge } from "./ClassificationBadge";
interface ItemCardProps { interface ItemCardProps {
id: number; id: number;
@@ -13,6 +15,8 @@ interface ItemCardProps {
imageFilename: string | null; imageFilename: string | null;
productUrl?: string | null; productUrl?: string | null;
onRemove?: () => void; onRemove?: () => void;
classification?: string;
onClassificationCycle?: () => void;
} }
export function ItemCard({ export function ItemCard({
@@ -25,8 +29,11 @@ export function ItemCard({
imageFilename, imageFilename,
productUrl, productUrl,
onRemove, onRemove,
classification,
onClassificationCycle,
}: ItemCardProps) { }: ItemCardProps) {
const unit = useWeightUnit(); const unit = useWeightUnit();
const currency = useCurrency();
const openEditPanel = useUIStore((s) => s.openEditPanel); const openEditPanel = useUIStore((s) => s.openEditPanel);
const openExternalLink = useUIStore((s) => s.openExternalLink); const openExternalLink = useUIStore((s) => s.openExternalLink);
@@ -129,7 +136,7 @@ export function ItemCard({
)} )}
{priceCents != null && ( {priceCents != null && (
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-50 text-green-500"> <span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-50 text-green-500">
{formatPrice(priceCents)} {formatPrice(priceCents, currency)}
</span> </span>
)} )}
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-gray-50 text-gray-600"> <span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-gray-50 text-gray-600">
@@ -140,6 +147,12 @@ export function ItemCard({
/>{" "} />{" "}
{categoryName} {categoryName}
</span> </span>
{classification && onClassificationCycle && (
<ClassificationBadge
classification={classification}
onCycle={onClassificationCycle}
/>
)}
</div> </div>
</div> </div>
</button> </button>

View File

@@ -1,4 +1,5 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { useCurrency } from "../hooks/useCurrency";
import { useItems } from "../hooks/useItems"; import { useItems } from "../hooks/useItems";
import { useSyncSetupItems } from "../hooks/useSetups"; import { useSyncSetupItems } from "../hooks/useSetups";
import { useWeightUnit } from "../hooks/useWeightUnit"; import { useWeightUnit } from "../hooks/useWeightUnit";
@@ -22,6 +23,7 @@ export function ItemPicker({
const { data: items } = useItems(); const { data: items } = useItems();
const syncItems = useSyncSetupItems(setupId); const syncItems = useSyncSetupItems(setupId);
const unit = useWeightUnit(); const unit = useWeightUnit();
const currency = useCurrency();
const [selectedIds, setSelectedIds] = useState<Set<number>>(new Set()); const [selectedIds, setSelectedIds] = useState<Set<number>>(new Set());
// Reset selected IDs when panel opens // Reset selected IDs when panel opens
@@ -121,7 +123,7 @@ export function ItemPicker({
item.priceCents != null && item.priceCents != null &&
" · "} " · "}
{item.priceCents != null && {item.priceCents != null &&
formatPrice(item.priceCents)} formatPrice(item.priceCents, currency)}
</span> </span>
</label> </label>
))} ))}

View File

@@ -1,4 +1,5 @@
import { Link } from "@tanstack/react-router"; import { Link } from "@tanstack/react-router";
import { useCurrency } from "../hooks/useCurrency";
import { useWeightUnit } from "../hooks/useWeightUnit"; import { useWeightUnit } from "../hooks/useWeightUnit";
import { formatPrice, formatWeight } from "../lib/formatters"; import { formatPrice, formatWeight } from "../lib/formatters";
@@ -18,6 +19,7 @@ export function SetupCard({
totalCost, totalCost,
}: SetupCardProps) { }: SetupCardProps) {
const unit = useWeightUnit(); const unit = useWeightUnit();
const currency = useCurrency();
return ( return (
<Link <Link
to="/setups/$setupId" to="/setups/$setupId"
@@ -35,7 +37,7 @@ export function SetupCard({
{formatWeight(totalWeight, unit)} {formatWeight(totalWeight, unit)}
</span> </span>
<span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-50 text-green-500"> <span className="inline-flex items-center px-2 py-0.5 rounded-full text-xs font-medium bg-green-50 text-green-500">
{formatPrice(totalCost)} {formatPrice(totalCost, currency)}
</span> </span>
</div> </div>
</Link> </Link>

View File

@@ -1,4 +1,5 @@
import { useNavigate } from "@tanstack/react-router"; import { useNavigate } from "@tanstack/react-router";
import { useCurrency } from "../hooks/useCurrency";
import { formatPrice } from "../lib/formatters"; import { formatPrice } from "../lib/formatters";
import { LucideIcon } from "../lib/iconData"; import { LucideIcon } from "../lib/iconData";
@@ -22,10 +23,11 @@ function formatDate(iso: string): string {
function formatPriceRange( function formatPriceRange(
min: number | null, min: number | null,
max: number | null, max: number | null,
currency: Parameters<typeof formatPrice>[1],
): string | null { ): string | null {
if (min == null && max == null) return null; if (min == null && max == null) return null;
if (min === max) return formatPrice(min); if (min === max) return formatPrice(min, currency);
return `${formatPrice(min)} - ${formatPrice(max)}`; return `${formatPrice(min, currency)} - ${formatPrice(max, currency)}`;
} }
export function ThreadCard({ export function ThreadCard({
@@ -40,9 +42,10 @@ export function ThreadCard({
categoryIcon, categoryIcon,
}: ThreadCardProps) { }: ThreadCardProps) {
const navigate = useNavigate(); const navigate = useNavigate();
const currency = useCurrency();
const isResolved = status === "resolved"; const isResolved = status === "resolved";
const priceRange = formatPriceRange(minPriceCents, maxPriceCents); const priceRange = formatPriceRange(minPriceCents, maxPriceCents, currency);
return ( return (
<button <button

View File

@@ -10,24 +10,25 @@ import {
import type { SetupItemWithCategory } from "../hooks/useSetups"; import type { SetupItemWithCategory } from "../hooks/useSetups";
import { useWeightUnit } from "../hooks/useWeightUnit"; import { useWeightUnit } from "../hooks/useWeightUnit";
import { formatWeight, type WeightUnit } from "../lib/formatters"; import { formatWeight, type WeightUnit } from "../lib/formatters";
import { LucideIcon } from "../lib/iconData";
const CATEGORY_COLORS = [ const CATEGORY_COLORS = [
"#6366f1", "#374151",
"#f59e0b", "#4b5563",
"#10b981", "#6b7280",
"#ef4444", "#7f8a94",
"#8b5cf6", "#9ca3af",
"#06b6d4", "#b0b7bf",
"#f97316", "#c4c9cf",
"#ec4899", "#d1d5db",
"#14b8a6", "#dfe2e6",
"#84cc16", "#e5e7eb",
]; ];
const CLASSIFICATION_COLORS: Record<string, string> = { const CLASSIFICATION_COLORS: Record<string, string> = {
base: "#6366f1", base: "#6b7280",
worn: "#f59e0b", worn: "#9ca3af",
consumable: "#10b981", consumable: "#d1d5db",
}; };
const CLASSIFICATION_LABELS: Record<string, string> = { const CLASSIFICATION_LABELS: Record<string, string> = {
@@ -109,29 +110,34 @@ function CustomTooltip({
); );
} }
function SubtotalColumn({ function LegendRow({
color,
label, label,
weight, weight,
unit, unit,
color, percent,
}: { }: {
color: string;
label: string; label: string;
weight: number; weight: number;
unit: WeightUnit; unit: WeightUnit;
color?: string; percent?: number;
}) { }) {
return ( return (
<div className="flex flex-col items-center gap-1"> <div className="flex items-center gap-3 py-1.5">
{color && (
<span <span
className="w-2.5 h-2.5 rounded-full" className="w-2.5 h-2.5 rounded-full shrink-0"
style={{ backgroundColor: color }} style={{ backgroundColor: color }}
/> />
)} <span className="text-sm text-gray-600 flex-1">{label}</span>
<span className="text-xs text-gray-500">{label}</span> <span className="text-sm font-semibold text-gray-900 tabular-nums">
<span className="text-sm font-semibold text-gray-900">
{formatWeight(weight, unit)} {formatWeight(weight, unit)}
</span> </span>
{percent != null && (
<span className="text-xs text-gray-400 w-10 text-right tabular-nums">
{(percent * 100).toFixed(0)}%
</span>
)}
</div> </div>
); );
} }
@@ -237,27 +243,39 @@ export function WeightSummaryCard({ items }: WeightSummaryCardProps) {
</ResponsiveContainer> </ResponsiveContainer>
</div> </div>
{/* Weight subtotals columns */} {/* Weight legend */}
<div className="flex-1 grid grid-cols-4 gap-4"> <div className="flex-1 flex flex-col justify-center min-w-0">
<SubtotalColumn <LegendRow
label="Base" color="#6b7280"
label="Base Weight"
weight={baseWeight} weight={baseWeight}
unit={unit} unit={unit}
color="#6366f1" percent={totalWeight > 0 ? baseWeight / totalWeight : undefined}
/> />
<SubtotalColumn <LegendRow
color="#9ca3af"
label="Worn" label="Worn"
weight={wornWeight} weight={wornWeight}
unit={unit} unit={unit}
color="#f59e0b" percent={totalWeight > 0 ? wornWeight / totalWeight : undefined}
/> />
<SubtotalColumn <LegendRow
color="#d1d5db"
label="Consumable" label="Consumable"
weight={consumableWeight} weight={consumableWeight}
unit={unit} unit={unit}
color="#10b981" percent={totalWeight > 0 ? consumableWeight / totalWeight : undefined}
/> />
<SubtotalColumn label="Total" weight={totalWeight} unit={unit} /> <div className="border-t border-gray-200 mt-1.5 pt-1.5">
<div className="flex items-center gap-3 py-1.5">
<LucideIcon name="sigma" size={10} className="text-gray-400 shrink-0 ml-0.5" />
<span className="text-sm font-medium text-gray-700 flex-1">Total</span>
<span className="text-sm font-bold text-gray-900 tabular-nums">
{formatWeight(totalWeight, unit)}
</span>
<span className="w-10" />
</div>
</div>
</div> </div>
</div> </div>
</div> </div>

View File

@@ -1,6 +1,6 @@
import { useMutation, useQueryClient } from "@tanstack/react-query"; import { useMutation, useQueryClient } from "@tanstack/react-query";
import type { CreateCandidate, UpdateCandidate } from "../../shared/types"; import type { CreateCandidate, UpdateCandidate } from "../../shared/types";
import { apiDelete, apiPost, apiPut } from "../lib/api"; import { apiDelete, apiPatch, apiPost, apiPut } from "../lib/api";
interface CandidateResponse { interface CandidateResponse {
id: number; id: number;
@@ -13,6 +13,8 @@ interface CandidateResponse {
productUrl: string | null; productUrl: string | null;
imageFilename: string | null; imageFilename: string | null;
status: "researching" | "ordered" | "arrived"; status: "researching" | "ordered" | "arrived";
pros: string | null;
cons: string | null;
createdAt: string; createdAt: string;
updatedAt: string; updatedAt: string;
} }
@@ -60,3 +62,17 @@ export function useDeleteCandidate(threadId: number) {
}, },
}); });
} }
export function useReorderCandidates(threadId: number) {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (data: { orderedIds: number[] }) =>
apiPatch<{ success: boolean }>(
`/api/threads/${threadId}/candidates/reorder`,
data,
),
onSettled: () => {
queryClient.invalidateQueries({ queryKey: ["threads", threadId] });
},
});
}

View File

@@ -0,0 +1,12 @@
import type { Currency } from "../lib/formatters";
import { useSetting } from "./useSettings";
const VALID_CURRENCIES: Currency[] = ["USD", "EUR", "GBP", "JPY", "CAD", "AUD"];
export function useCurrency(): Currency {
const { data } = useSetting("currency");
if (data && VALID_CURRENCIES.includes(data as Currency)) {
return data as Currency;
}
return "USD";
}

View File

@@ -27,6 +27,8 @@ interface CandidateWithCategory {
productUrl: string | null; productUrl: string | null;
imageFilename: string | null; imageFilename: string | null;
status: "researching" | "ordered" | "arrived"; status: "researching" | "ordered" | "arrived";
pros: string | null;
cons: string | null;
createdAt: string; createdAt: string;
updatedAt: string; updatedAt: string;
categoryName: string; categoryName: string;

View File

@@ -21,7 +21,25 @@ export function formatWeight(
} }
} }
export function formatPrice(cents: number | null | undefined): string { export type Currency = "USD" | "EUR" | "GBP" | "JPY" | "CAD" | "AUD";
const CURRENCY_SYMBOLS: Record<Currency, string> = {
USD: "$",
EUR: "€",
GBP: "£",
JPY: "¥",
CAD: "CA$",
AUD: "A$",
};
export function formatPrice(
cents: number | null | undefined,
currency: Currency = "USD",
): string {
if (cents == null) return "--"; if (cents == null) return "--";
return `$${(cents / 100).toFixed(2)}`; const symbol = CURRENCY_SYMBOLS[currency];
if (currency === "JPY") {
return `${symbol}${Math.round(cents / 100)}`;
}
return `${symbol}${(cents / 100).toFixed(2)}`;
} }

View File

@@ -1,4 +1,5 @@
import { icons } from "lucide-react"; import { icons } from "lucide-react";
import type React from "react";
// --- Emoji to Lucide icon mapping (for migration/fallback) --- // --- Emoji to Lucide icon mapping (for migration/fallback) ---
@@ -232,18 +233,20 @@ interface LucideIconProps {
name: string; name: string;
size?: number; size?: number;
className?: string; className?: string;
style?: React.CSSProperties;
} }
export function LucideIcon({ export function LucideIcon({
name, name,
size = 20, size = 20,
className = "", className = "",
style,
}: LucideIconProps) { }: LucideIconProps) {
const pascalName = toPascalCase(name); const pascalName = toPascalCase(name);
const IconComponent = icons[pascalName as keyof typeof icons]; const IconComponent = icons[pascalName as keyof typeof icons];
if (!IconComponent) { if (!IconComponent) {
const FallbackIcon = icons.Package; const FallbackIcon = icons.Package;
return <FallbackIcon size={size} className={className} />; return <FallbackIcon size={size} className={className} style={style} />;
} }
return <IconComponent size={size} className={className} />; return <IconComponent size={size} className={className} style={style} />;
} }

View File

@@ -9,11 +9,17 @@
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. // Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
import { Route as rootRouteImport } from './routes/__root' import { Route as rootRouteImport } from './routes/__root'
import { Route as SettingsRouteImport } from './routes/settings'
import { Route as IndexRouteImport } from './routes/index' import { Route as IndexRouteImport } from './routes/index'
import { Route as CollectionIndexRouteImport } from './routes/collection/index' import { Route as CollectionIndexRouteImport } from './routes/collection/index'
import { Route as ThreadsThreadIdRouteImport } from './routes/threads/$threadId' import { Route as ThreadsThreadIdRouteImport } from './routes/threads/$threadId'
import { Route as SetupsSetupIdRouteImport } from './routes/setups/$setupId' import { Route as SetupsSetupIdRouteImport } from './routes/setups/$setupId'
const SettingsRoute = SettingsRouteImport.update({
id: '/settings',
path: '/settings',
getParentRoute: () => rootRouteImport,
} as any)
const IndexRoute = IndexRouteImport.update({ const IndexRoute = IndexRouteImport.update({
id: '/', id: '/',
path: '/', path: '/',
@@ -37,12 +43,14 @@ const SetupsSetupIdRoute = SetupsSetupIdRouteImport.update({
export interface FileRoutesByFullPath { export interface FileRoutesByFullPath {
'/': typeof IndexRoute '/': typeof IndexRoute
'/settings': typeof SettingsRoute
'/setups/$setupId': typeof SetupsSetupIdRoute '/setups/$setupId': typeof SetupsSetupIdRoute
'/threads/$threadId': typeof ThreadsThreadIdRoute '/threads/$threadId': typeof ThreadsThreadIdRoute
'/collection/': typeof CollectionIndexRoute '/collection/': typeof CollectionIndexRoute
} }
export interface FileRoutesByTo { export interface FileRoutesByTo {
'/': typeof IndexRoute '/': typeof IndexRoute
'/settings': typeof SettingsRoute
'/setups/$setupId': typeof SetupsSetupIdRoute '/setups/$setupId': typeof SetupsSetupIdRoute
'/threads/$threadId': typeof ThreadsThreadIdRoute '/threads/$threadId': typeof ThreadsThreadIdRoute
'/collection': typeof CollectionIndexRoute '/collection': typeof CollectionIndexRoute
@@ -50,18 +58,30 @@ export interface FileRoutesByTo {
export interface FileRoutesById { export interface FileRoutesById {
__root__: typeof rootRouteImport __root__: typeof rootRouteImport
'/': typeof IndexRoute '/': typeof IndexRoute
'/settings': typeof SettingsRoute
'/setups/$setupId': typeof SetupsSetupIdRoute '/setups/$setupId': typeof SetupsSetupIdRoute
'/threads/$threadId': typeof ThreadsThreadIdRoute '/threads/$threadId': typeof ThreadsThreadIdRoute
'/collection/': typeof CollectionIndexRoute '/collection/': typeof CollectionIndexRoute
} }
export interface FileRouteTypes { export interface FileRouteTypes {
fileRoutesByFullPath: FileRoutesByFullPath fileRoutesByFullPath: FileRoutesByFullPath
fullPaths: '/' | '/setups/$setupId' | '/threads/$threadId' | '/collection/' fullPaths:
| '/'
| '/settings'
| '/setups/$setupId'
| '/threads/$threadId'
| '/collection/'
fileRoutesByTo: FileRoutesByTo fileRoutesByTo: FileRoutesByTo
to: '/' | '/setups/$setupId' | '/threads/$threadId' | '/collection' to:
| '/'
| '/settings'
| '/setups/$setupId'
| '/threads/$threadId'
| '/collection'
id: id:
| '__root__' | '__root__'
| '/' | '/'
| '/settings'
| '/setups/$setupId' | '/setups/$setupId'
| '/threads/$threadId' | '/threads/$threadId'
| '/collection/' | '/collection/'
@@ -69,6 +89,7 @@ export interface FileRouteTypes {
} }
export interface RootRouteChildren { export interface RootRouteChildren {
IndexRoute: typeof IndexRoute IndexRoute: typeof IndexRoute
SettingsRoute: typeof SettingsRoute
SetupsSetupIdRoute: typeof SetupsSetupIdRoute SetupsSetupIdRoute: typeof SetupsSetupIdRoute
ThreadsThreadIdRoute: typeof ThreadsThreadIdRoute ThreadsThreadIdRoute: typeof ThreadsThreadIdRoute
CollectionIndexRoute: typeof CollectionIndexRoute CollectionIndexRoute: typeof CollectionIndexRoute
@@ -76,6 +97,13 @@ export interface RootRouteChildren {
declare module '@tanstack/react-router' { declare module '@tanstack/react-router' {
interface FileRoutesByPath { interface FileRoutesByPath {
'/settings': {
id: '/settings'
path: '/settings'
fullPath: '/settings'
preLoaderRoute: typeof SettingsRouteImport
parentRoute: typeof rootRouteImport
}
'/': { '/': {
id: '/' id: '/'
path: '/' path: '/'
@@ -109,6 +137,7 @@ declare module '@tanstack/react-router' {
const rootRouteChildren: RootRouteChildren = { const rootRouteChildren: RootRouteChildren = {
IndexRoute: IndexRoute, IndexRoute: IndexRoute,
SettingsRoute: SettingsRoute,
SetupsSetupIdRoute: SetupsSetupIdRoute, SetupsSetupIdRoute: SetupsSetupIdRoute,
ThreadsThreadIdRoute: ThreadsThreadIdRoute, ThreadsThreadIdRoute: ThreadsThreadIdRoute,
CollectionIndexRoute: CollectionIndexRoute, CollectionIndexRoute: CollectionIndexRoute,

View File

@@ -1,5 +1,6 @@
import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { createFileRoute } from "@tanstack/react-router";
import { useMemo, useState } from "react"; import { AnimatePresence, motion } from "framer-motion";
import { useMemo, useRef, useState } from "react";
import { z } from "zod"; import { z } from "zod";
import { CategoryFilterDropdown } from "../../components/CategoryFilterDropdown"; import { CategoryFilterDropdown } from "../../components/CategoryFilterDropdown";
import { CategoryHeader } from "../../components/CategoryHeader"; import { CategoryHeader } from "../../components/CategoryHeader";
@@ -7,12 +8,14 @@ import { CreateThreadModal } from "../../components/CreateThreadModal";
import { ItemCard } from "../../components/ItemCard"; import { ItemCard } from "../../components/ItemCard";
import { SetupCard } from "../../components/SetupCard"; import { SetupCard } from "../../components/SetupCard";
import { ThreadCard } from "../../components/ThreadCard"; import { ThreadCard } from "../../components/ThreadCard";
import { CollectionTabs } from "../../components/ThreadTabs";
import { useCategories } from "../../hooks/useCategories"; import { useCategories } from "../../hooks/useCategories";
import { useItems } from "../../hooks/useItems"; import { useItems } from "../../hooks/useItems";
import { useCreateSetup, useSetups } from "../../hooks/useSetups"; import { useCreateSetup, useSetups } from "../../hooks/useSetups";
import { useThreads } from "../../hooks/useThreads"; import { useThreads } from "../../hooks/useThreads";
import { useTotals } from "../../hooks/useTotals"; import { useTotals } from "../../hooks/useTotals";
import { useCurrency } from "../../hooks/useCurrency";
import { useWeightUnit } from "../../hooks/useWeightUnit";
import { formatPrice, formatWeight } from "../../lib/formatters";
import { LucideIcon } from "../../lib/iconData"; import { LucideIcon } from "../../lib/iconData";
import { useUIStore } from "../../stores/uiStore"; import { useUIStore } from "../../stores/uiStore";
@@ -25,18 +28,34 @@ export const Route = createFileRoute("/collection/")({
component: CollectionPage, component: CollectionPage,
}); });
const TAB_ORDER = ["gear", "planning", "setups"] as const;
const slideVariants = {
enter: (dir: number) => ({ x: `${dir * 15}%`, opacity: 0 }),
center: { x: 0, opacity: 1 },
exit: (dir: number) => ({ x: `${dir * -15}%`, opacity: 0 }),
};
function CollectionPage() { function CollectionPage() {
const { tab } = Route.useSearch(); const { tab } = Route.useSearch();
const navigate = useNavigate(); const prevTab = useRef(tab);
function handleTabChange(newTab: "gear" | "planning" | "setups") { const direction =
navigate({ to: "/collection", search: { tab: newTab } }); TAB_ORDER.indexOf(tab) >= TAB_ORDER.indexOf(prevTab.current) ? 1 : -1;
} prevTab.current = tab;
return ( return (
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6"> <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6 overflow-x-hidden">
<CollectionTabs active={tab} onChange={handleTabChange} /> <AnimatePresence mode="wait" initial={false} custom={direction}>
<div className="mt-6"> <motion.div
key={tab}
custom={direction}
variants={slideVariants}
initial="enter"
animate="center"
exit="exit"
transition={{ duration: 0.12, ease: "easeInOut" }}
>
{tab === "gear" ? ( {tab === "gear" ? (
<CollectionView /> <CollectionView />
) : tab === "planning" ? ( ) : tab === "planning" ? (
@@ -44,7 +63,8 @@ function CollectionPage() {
) : ( ) : (
<SetupsView /> <SetupsView />
)} )}
</div> </motion.div>
</AnimatePresence>
</div> </div>
); );
} }
@@ -53,6 +73,8 @@ function CollectionView() {
const { data: items, isLoading: itemsLoading } = useItems(); const { data: items, isLoading: itemsLoading } = useItems();
const { data: totals } = useTotals(); const { data: totals } = useTotals();
const { data: categories } = useCategories(); const { data: categories } = useCategories();
const unit = useWeightUnit();
const currency = useCurrency();
const openAddPanel = useUIStore((s) => s.openAddPanel); const openAddPanel = useUIStore((s) => s.openAddPanel);
const [searchText, setSearchText] = useState(""); const [searchText, setSearchText] = useState("");
@@ -169,8 +191,41 @@ function CollectionView() {
return ( return (
<> <>
{/* Collection stats card */}
{totals?.global && (
<div className="bg-white rounded-xl border border-gray-100 p-5 mb-6">
<div className="flex items-center gap-8">
<div className="flex flex-col items-center gap-1">
<LucideIcon name="layers" size={14} className="text-gray-400" />
<span className="text-xs text-gray-500">Items</span>
<span className="text-sm font-semibold text-gray-900">
{totals.global.itemCount}
</span>
</div>
<div className="flex flex-col items-center gap-1">
<LucideIcon name="weight" size={14} className="text-gray-400" />
<span className="text-xs text-gray-500">Total Weight</span>
<span className="text-sm font-semibold text-gray-900">
{formatWeight(totals.global.totalWeight, unit)}
</span>
</div>
<div className="flex flex-col items-center gap-1">
<LucideIcon
name="credit-card"
size={14}
className="text-gray-400"
/>
<span className="text-xs text-gray-500">Total Spent</span>
<span className="text-sm font-semibold text-gray-900">
{formatPrice(totals.global.totalCost, currency)}
</span>
</div>
</div>
</div>
)}
{/* Search/filter toolbar */} {/* Search/filter toolbar */}
<div className="sticky top-0 z-10 bg-white/95 backdrop-blur-sm border-b border-gray-100 -mx-4 px-4 py-3 sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8 mb-6"> <div className="sticky top-0 z-10 bg-gray-50/95 backdrop-blur-sm border-b border-gray-100 -mx-4 px-4 py-3 sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8 mb-6">
<div className="flex gap-3 items-center"> <div className="flex gap-3 items-center">
<div className="relative flex-1"> <div className="relative flex-1">
<input <input
@@ -219,9 +274,7 @@ function CollectionView() {
{hasActiveFilters ? ( {hasActiveFilters ? (
filteredItems.length === 0 ? ( filteredItems.length === 0 ? (
<div className="py-12 text-center"> <div className="py-12 text-center">
<p className="text-sm text-gray-500"> <p className="text-sm text-gray-500">No items match your search</p>
No items match your search
</p>
</div> </div>
) : ( ) : (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"> <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
@@ -516,23 +569,48 @@ function SetupsView() {
{/* Empty state */} {/* Empty state */}
{!isLoading && (!setups || setups.length === 0) && ( {!isLoading && (!setups || setups.length === 0) && (
<div className="py-16 text-center"> <div className="py-16">
<div className="max-w-md mx-auto"> <div className="max-w-lg mx-auto text-center">
<div className="mb-4"> <h2 className="text-xl font-semibold text-gray-900 mb-8">
<LucideIcon Build your perfect loadout
name="tent"
size={48}
className="text-gray-400 mx-auto"
/>
</div>
<h2 className="text-xl font-semibold text-gray-900 mb-2">
No setups yet
</h2> </h2>
<div className="space-y-6 text-left mb-10">
<div className="flex items-start gap-4">
<div className="flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 text-gray-700 font-bold text-sm shrink-0">
1
</div>
<div>
<p className="font-medium text-gray-900">Create a setup</p>
<p className="text-sm text-gray-500"> <p className="text-sm text-gray-500">
Create one to plan your loadout. Name your loadout for a specific trip or activity
</p> </p>
</div> </div>
</div> </div>
<div className="flex items-start gap-4">
<div className="flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 text-gray-700 font-bold text-sm shrink-0">
2
</div>
<div>
<p className="font-medium text-gray-900">Add items</p>
<p className="text-sm text-gray-500">
Pick gear from your collection to include in the setup
</p>
</div>
</div>
<div className="flex items-start gap-4">
<div className="flex items-center justify-center w-8 h-8 rounded-full bg-gray-200 text-gray-700 font-bold text-sm shrink-0">
3
</div>
<div>
<p className="font-medium text-gray-900">Track weight</p>
<p className="text-sm text-gray-500">
See weight breakdown and optimize your pack
</p>
</div>
</div>
</div>
</div>
</div>
)} )}
{/* Setup grid */} {/* Setup grid */}

View File

@@ -4,6 +4,7 @@ import { useSetups } from "../hooks/useSetups";
import { useThreads } from "../hooks/useThreads"; import { useThreads } from "../hooks/useThreads";
import { useTotals } from "../hooks/useTotals"; import { useTotals } from "../hooks/useTotals";
import { useWeightUnit } from "../hooks/useWeightUnit"; import { useWeightUnit } from "../hooks/useWeightUnit";
import { useCurrency } from "../hooks/useCurrency";
import { formatPrice, formatWeight } from "../lib/formatters"; import { formatPrice, formatWeight } from "../lib/formatters";
export const Route = createFileRoute("/")({ export const Route = createFileRoute("/")({
@@ -15,6 +16,7 @@ function DashboardPage() {
const { data: threads } = useThreads(false); const { data: threads } = useThreads(false);
const { data: setups } = useSetups(); const { data: setups } = useSetups();
const unit = useWeightUnit(); const unit = useWeightUnit();
const currency = useCurrency();
const global = totals?.global; const global = totals?.global;
const activeThreadCount = threads?.length ?? 0; const activeThreadCount = threads?.length ?? 0;
@@ -33,7 +35,7 @@ function DashboardPage() {
label: "Weight", label: "Weight",
value: formatWeight(global?.totalWeight ?? null, unit), value: formatWeight(global?.totalWeight ?? null, unit),
}, },
{ label: "Cost", value: formatPrice(global?.totalCost ?? null) }, { label: "Cost", value: formatPrice(global?.totalCost ?? null, currency) },
]} ]}
emptyText="Get started" emptyText="Get started"
/> />

View File

@@ -0,0 +1,104 @@
import { createFileRoute, Link } from "@tanstack/react-router";
import { useCurrency } from "../hooks/useCurrency";
import { useUpdateSetting } from "../hooks/useSettings";
import { useWeightUnit } from "../hooks/useWeightUnit";
import type { Currency, WeightUnit } from "../lib/formatters";
const UNITS: WeightUnit[] = ["g", "oz", "lb", "kg"];
const CURRENCIES: { value: Currency; label: string }[] = [
{ value: "USD", label: "$" },
{ value: "EUR", label: "€" },
{ value: "GBP", label: "£" },
{ value: "JPY", label: "¥" },
{ value: "CAD", label: "CA$" },
{ value: "AUD", label: "A$" },
];
export const Route = createFileRoute("/settings")({
component: SettingsPage,
});
function SettingsPage() {
const unit = useWeightUnit();
const currency = useCurrency();
const updateSetting = useUpdateSetting();
return (
<div className="max-w-2xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
<div className="mb-6">
<Link
to="/"
className="text-sm text-gray-500 hover:text-gray-700 mb-2 inline-block"
>
&larr; Back
</Link>
<h1 className="text-xl font-semibold text-gray-900">Settings</h1>
</div>
<div className="bg-white rounded-xl border border-gray-100 p-5 space-y-6">
<div className="flex items-center justify-between">
<div>
<h3 className="text-sm font-medium text-gray-900">Weight Unit</h3>
<p className="text-xs text-gray-500 mt-0.5">
Choose the unit used to display weights across the app
</p>
</div>
<div className="flex items-center gap-1 bg-gray-100 rounded-full px-1 py-0.5">
{UNITS.map((u) => (
<button
key={u}
type="button"
onClick={() =>
updateSetting.mutate({
key: "weightUnit",
value: u,
})
}
className={`px-2.5 py-1 text-xs rounded-full transition-colors ${
unit === u
? "bg-white text-gray-700 shadow-sm font-medium"
: "text-gray-400 hover:text-gray-600"
}`}
>
{u}
</button>
))}
</div>
</div>
<div className="border-t border-gray-100" />
<div className="flex items-center justify-between">
<div>
<h3 className="text-sm font-medium text-gray-900">Currency</h3>
<p className="text-xs text-gray-500 mt-0.5">
Changes the currency symbol displayed. This does not convert
values.
</p>
</div>
<div className="flex items-center gap-1 bg-gray-100 rounded-full px-1 py-0.5">
{CURRENCIES.map((c) => (
<button
key={c.value}
type="button"
onClick={() =>
updateSetting.mutate({
key: "currency",
value: c.value,
})
}
className={`px-2.5 py-1 text-xs rounded-full transition-colors ${
currency === c.value
? "bg-white text-gray-700 shadow-sm font-medium"
: "text-gray-400 hover:text-gray-600"
}`}
>
{c.label}
</button>
))}
</div>
</div>
</div>
</div>
);
}

View File

@@ -1,7 +1,6 @@
import { createFileRoute, useNavigate } from "@tanstack/react-router"; import { createFileRoute, Link, useNavigate } from "@tanstack/react-router";
import { useState } from "react"; import { useState } from "react";
import { CategoryHeader } from "../../components/CategoryHeader"; import { CategoryHeader } from "../../components/CategoryHeader";
import { ClassificationBadge } from "../../components/ClassificationBadge";
import { ItemCard } from "../../components/ItemCard"; import { ItemCard } from "../../components/ItemCard";
import { ItemPicker } from "../../components/ItemPicker"; import { ItemPicker } from "../../components/ItemPicker";
import { WeightSummaryCard } from "../../components/WeightSummaryCard"; import { WeightSummaryCard } from "../../components/WeightSummaryCard";
@@ -11,6 +10,7 @@ import {
useSetup, useSetup,
useUpdateItemClassification, useUpdateItemClassification,
} from "../../hooks/useSetups"; } from "../../hooks/useSetups";
import { useCurrency } from "../../hooks/useCurrency";
import { useWeightUnit } from "../../hooks/useWeightUnit"; import { useWeightUnit } from "../../hooks/useWeightUnit";
import { formatPrice, formatWeight } from "../../lib/formatters"; import { formatPrice, formatWeight } from "../../lib/formatters";
import { LucideIcon } from "../../lib/iconData"; import { LucideIcon } from "../../lib/iconData";
@@ -22,6 +22,7 @@ export const Route = createFileRoute("/setups/$setupId")({
function SetupDetailPage() { function SetupDetailPage() {
const { setupId } = Route.useParams(); const { setupId } = Route.useParams();
const unit = useWeightUnit(); const unit = useWeightUnit();
const currency = useCurrency();
const navigate = useNavigate(); const navigate = useNavigate();
const numericId = Number(setupId); const numericId = Number(setupId);
const { data: setup, isLoading } = useSetup(numericId); const { data: setup, isLoading } = useSetup(numericId);
@@ -107,9 +108,18 @@ function SetupDetailPage() {
{/* Setup-specific sticky bar */} {/* Setup-specific sticky bar */}
<div className="sticky top-14 z-[9] bg-gray-50 border-b border-gray-100 -mx-4 sm:-mx-6 lg:-mx-8 px-4 sm:px-6 lg:px-8"> <div className="sticky top-14 z-[9] bg-gray-50 border-b border-gray-100 -mx-4 sm:-mx-6 lg:-mx-8 px-4 sm:px-6 lg:px-8">
<div className="flex items-center justify-between h-12"> <div className="flex items-center justify-between h-12">
<div className="flex items-center gap-3 min-w-0">
<Link
to="/collection"
search={{ tab: "setups" }}
className="text-sm text-gray-500 hover:text-gray-700 shrink-0"
>
&larr;
</Link>
<h2 className="text-base font-semibold text-gray-900 truncate"> <h2 className="text-base font-semibold text-gray-900 truncate">
{setup.name} {setup.name}
</h2> </h2>
</div>
<div className="flex items-center gap-4 text-sm text-gray-500"> <div className="flex items-center gap-4 text-sm text-gray-500">
<span> <span>
<span className="font-medium text-gray-700">{itemCount}</span>{" "} <span className="font-medium text-gray-700">{itemCount}</span>{" "}
@@ -123,7 +133,7 @@ function SetupDetailPage() {
</span> </span>
<span> <span>
<span className="font-medium text-gray-700"> <span className="font-medium text-gray-700">
{formatPrice(totalCost)} {formatPrice(totalCost, currency)}
</span>{" "} </span>{" "}
cost cost
</span> </span>
@@ -219,8 +229,8 @@ function SetupDetailPage() {
/> />
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"> <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{categoryItems.map((item) => ( {categoryItems.map((item) => (
<div key={item.id}>
<ItemCard <ItemCard
key={item.id}
id={item.id} id={item.id}
name={item.name} name={item.name}
weightGrams={item.weightGrams} weightGrams={item.weightGrams}
@@ -230,11 +240,8 @@ function SetupDetailPage() {
imageFilename={item.imageFilename} imageFilename={item.imageFilename}
productUrl={item.productUrl} productUrl={item.productUrl}
onRemove={() => removeItem.mutate(item.id)} onRemove={() => removeItem.mutate(item.id)}
/>
<div className="px-4 pb-3 -mt-1">
<ClassificationBadge
classification={item.classification} classification={item.classification}
onCycle={() => onClassificationCycle={() =>
updateClassification.mutate({ updateClassification.mutate({
itemId: item.id, itemId: item.id,
classification: nextClassification( classification: nextClassification(
@@ -243,8 +250,6 @@ function SetupDetailPage() {
}) })
} }
/> />
</div>
</div>
))} ))}
</div> </div>
</div> </div>

View File

@@ -1,6 +1,12 @@
import { createFileRoute, Link } from "@tanstack/react-router"; import { createFileRoute, Link } from "@tanstack/react-router";
import { Reorder } from "framer-motion";
import { useEffect, useState } from "react";
import { CandidateCard } from "../../components/CandidateCard"; import { CandidateCard } from "../../components/CandidateCard";
import { useUpdateCandidate } from "../../hooks/useCandidates"; import { CandidateListItem } from "../../components/CandidateListItem";
import {
useReorderCandidates,
useUpdateCandidate,
} from "../../hooks/useCandidates";
import { useThread } from "../../hooks/useThreads"; import { useThread } from "../../hooks/useThreads";
import { LucideIcon } from "../../lib/iconData"; import { LucideIcon } from "../../lib/iconData";
import { useUIStore } from "../../stores/uiStore"; import { useUIStore } from "../../stores/uiStore";
@@ -14,7 +20,21 @@ function ThreadDetailPage() {
const threadId = Number(threadIdParam); const threadId = Number(threadIdParam);
const { data: thread, isLoading, isError } = useThread(threadId); const { data: thread, isLoading, isError } = useThread(threadId);
const openCandidateAddPanel = useUIStore((s) => s.openCandidateAddPanel); const openCandidateAddPanel = useUIStore((s) => s.openCandidateAddPanel);
const candidateViewMode = useUIStore((s) => s.candidateViewMode);
const setCandidateViewMode = useUIStore((s) => s.setCandidateViewMode);
const updateCandidate = useUpdateCandidate(threadId); const updateCandidate = useUpdateCandidate(threadId);
const reorderMutation = useReorderCandidates(threadId);
const [tempItems, setTempItems] =
useState<typeof thread extends { candidates: infer C } ? C : never | null>(
null,
);
// Clear tempItems when server data changes (biome-ignore: thread?.candidates is intentional dep)
// biome-ignore lint/correctness/useExhaustiveDependencies: thread?.candidates is the intended trigger
useEffect(() => {
setTempItems(null);
}, [thread?.candidates]);
if (isLoading) { if (isLoading) {
return ( return (
@@ -53,6 +73,16 @@ function ThreadDetailPage() {
? thread.candidates.find((c) => c.id === thread.resolvedCandidateId) ? thread.candidates.find((c) => c.id === thread.resolvedCandidateId)
: null; : null;
const displayItems = tempItems ?? thread.candidates;
function handleDragEnd() {
if (!tempItems) return;
reorderMutation.mutate(
{ orderedIds: tempItems.map((c) => c.id) },
{ onSettled: () => setTempItems(null) },
);
}
return ( return (
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6"> <div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
{/* Header */} {/* Header */}
@@ -88,9 +118,9 @@ function ThreadDetailPage() {
</div> </div>
)} )}
{/* Add candidate button */} {/* Toolbar: Add candidate + view toggle */}
<div className="mb-6 flex items-center gap-3">
{isActive && ( {isActive && (
<div className="mb-6">
<button <button
type="button" type="button"
onClick={openCandidateAddPanel} onClick={openCandidateAddPanel}
@@ -111,10 +141,38 @@ function ThreadDetailPage() {
</svg> </svg>
Add Candidate Add Candidate
</button> </button>
)}
{thread.candidates.length > 0 && (
<div className="flex items-center gap-1 bg-gray-100 rounded-lg p-0.5">
<button
type="button"
onClick={() => setCandidateViewMode("list")}
className={`p-1.5 rounded-md transition-colors ${
candidateViewMode === "list"
? "bg-gray-200 text-gray-900"
: "text-gray-400 hover:text-gray-600"
}`}
title="List view"
>
<LucideIcon name="layout-list" size={16} />
</button>
<button
type="button"
onClick={() => setCandidateViewMode("grid")}
className={`p-1.5 rounded-md transition-colors ${
candidateViewMode === "grid"
? "bg-gray-200 text-gray-900"
: "text-gray-400 hover:text-gray-600"
}`}
title="Grid view"
>
<LucideIcon name="layout-grid" size={16} />
</button>
</div> </div>
)} )}
</div>
{/* Candidate grid */} {/* Candidates */}
{thread.candidates.length === 0 ? ( {thread.candidates.length === 0 ? (
<div className="py-12 text-center"> <div className="py-12 text-center">
<div className="mb-3"> <div className="mb-3">
@@ -131,9 +189,51 @@ function ThreadDetailPage() {
Add your first candidate to start comparing. Add your first candidate to start comparing.
</p> </p>
</div> </div>
) : candidateViewMode === "list" ? (
isActive ? (
<Reorder.Group
axis="y"
values={displayItems}
onReorder={setTempItems}
onPointerUp={handleDragEnd}
className="flex flex-col gap-2"
>
{displayItems.map((candidate, index) => (
<CandidateListItem
key={candidate.id}
candidate={candidate}
rank={index + 1}
isActive={isActive}
onStatusChange={(newStatus) =>
updateCandidate.mutate({
candidateId: candidate.id,
status: newStatus,
})
}
/>
))}
</Reorder.Group>
) : (
<div className="flex flex-col gap-2">
{displayItems.map((candidate, index) => (
<CandidateListItem
key={candidate.id}
candidate={candidate}
rank={index + 1}
isActive={isActive}
onStatusChange={(newStatus) =>
updateCandidate.mutate({
candidateId: candidate.id,
status: newStatus,
})
}
/>
))}
</div>
)
) : ( ) : (
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4"> <div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
{thread.candidates.map((candidate) => ( {thread.candidates.map((candidate, index) => (
<CandidateCard <CandidateCard
key={candidate.id} key={candidate.id}
id={candidate.id} id={candidate.id}
@@ -153,6 +253,9 @@ function ThreadDetailPage() {
status: newStatus, status: newStatus,
}) })
} }
pros={candidate.pros}
cons={candidate.cons}
rank={index + 1}
/> />
))} ))}
</div> </div>

View File

@@ -48,6 +48,10 @@ interface UIState {
externalLinkUrl: string | null; externalLinkUrl: string | null;
openExternalLink: (url: string) => void; openExternalLink: (url: string) => void;
closeExternalLink: () => void; closeExternalLink: () => void;
// Candidate view mode
candidateViewMode: "list" | "grid";
setCandidateViewMode: (mode: "list" | "grid") => void;
} }
export const useUIStore = create<UIState>((set) => ({ export const useUIStore = create<UIState>((set) => ({
@@ -103,4 +107,8 @@ export const useUIStore = create<UIState>((set) => ({
externalLinkUrl: null, externalLinkUrl: null,
openExternalLink: (url) => set({ externalLinkUrl: url }), openExternalLink: (url) => set({ externalLinkUrl: url }),
closeExternalLink: () => set({ externalLinkUrl: null }), closeExternalLink: () => set({ externalLinkUrl: null }),
// Candidate view mode
candidateViewMode: "list",
setCandidateViewMode: (mode) => set({ candidateViewMode: mode }),
})); }));

View File

@@ -59,6 +59,9 @@ export const threadCandidates = sqliteTable("thread_candidates", {
productUrl: text("product_url"), productUrl: text("product_url"),
imageFilename: text("image_filename"), imageFilename: text("image_filename"),
status: text("status").notNull().default("researching"), status: text("status").notNull().default("researching"),
pros: text("pros"),
cons: text("cons"),
sortOrder: real("sort_order").notNull().default(0),
createdAt: integer("created_at", { mode: "timestamp" }) createdAt: integer("created_at", { mode: "timestamp" })
.notNull() .notNull()
.$defaultFn(() => new Date()), .$defaultFn(() => new Date()),

View File

@@ -5,6 +5,7 @@ import { Hono } from "hono";
import { import {
createCandidateSchema, createCandidateSchema,
createThreadSchema, createThreadSchema,
reorderCandidatesSchema,
resolveThreadSchema, resolveThreadSchema,
updateCandidateSchema, updateCandidateSchema,
updateThreadSchema, updateThreadSchema,
@@ -16,6 +17,7 @@ import {
deleteThread, deleteThread,
getAllThreads, getAllThreads,
getThreadWithCandidates, getThreadWithCandidates,
reorderCandidates,
resolveThread, resolveThread,
updateCandidate, updateCandidate,
updateThread, updateThread,
@@ -122,6 +124,21 @@ app.delete("/:threadId/candidates/:candidateId", async (c) => {
return c.json({ success: true }); return c.json({ success: true });
}); });
// Candidate reorder
app.patch(
"/:id/candidates/reorder",
zValidator("json", reorderCandidatesSchema),
(c) => {
const db = c.get("db");
const threadId = Number(c.req.param("id"));
const { orderedIds } = c.req.valid("json");
const result = reorderCandidates(db, threadId, orderedIds);
if (!result.success) return c.json({ error: result.error }, 400);
return c.json({ success: true });
},
);
// Resolution // Resolution
app.post("/:id/resolve", zValidator("json", resolveThreadSchema), (c) => { app.post("/:id/resolve", zValidator("json", resolveThreadSchema), (c) => {

View File

@@ -1,4 +1,4 @@
import { desc, eq, sql } from "drizzle-orm"; import { asc, desc, eq, max, sql } from "drizzle-orm";
import { db as prodDb } from "../../db/index.ts"; import { db as prodDb } from "../../db/index.ts";
import { import {
categories, categories,
@@ -6,7 +6,11 @@ import {
threadCandidates, threadCandidates,
threads, threads,
} from "../../db/schema.ts"; } from "../../db/schema.ts";
import type { CreateCandidate, CreateThread } from "../../shared/types.ts"; import type {
CreateCandidate,
CreateThread,
ReorderCandidates,
} from "../../shared/types.ts";
type Db = typeof prodDb; type Db = typeof prodDb;
@@ -73,6 +77,8 @@ export function getThreadWithCandidates(db: Db = prodDb, threadId: number) {
productUrl: threadCandidates.productUrl, productUrl: threadCandidates.productUrl,
imageFilename: threadCandidates.imageFilename, imageFilename: threadCandidates.imageFilename,
status: threadCandidates.status, status: threadCandidates.status,
pros: threadCandidates.pros,
cons: threadCandidates.cons,
createdAt: threadCandidates.createdAt, createdAt: threadCandidates.createdAt,
updatedAt: threadCandidates.updatedAt, updatedAt: threadCandidates.updatedAt,
categoryName: categories.name, categoryName: categories.name,
@@ -81,6 +87,7 @@ export function getThreadWithCandidates(db: Db = prodDb, threadId: number) {
.from(threadCandidates) .from(threadCandidates)
.innerJoin(categories, eq(threadCandidates.categoryId, categories.id)) .innerJoin(categories, eq(threadCandidates.categoryId, categories.id))
.where(eq(threadCandidates.threadId, threadId)) .where(eq(threadCandidates.threadId, threadId))
.orderBy(asc(threadCandidates.sortOrder))
.all(); .all();
return { ...thread, candidates: candidateList }; return { ...thread, candidates: candidateList };
@@ -139,6 +146,14 @@ export function createCandidate(
imageFilename?: string; imageFilename?: string;
}, },
) { ) {
const maxRow = db
.select({ maxOrder: max(threadCandidates.sortOrder) })
.from(threadCandidates)
.where(eq(threadCandidates.threadId, threadId))
.get();
const nextSortOrder = (maxRow?.maxOrder ?? 0) + 1000;
return db return db
.insert(threadCandidates) .insert(threadCandidates)
.values({ .values({
@@ -151,6 +166,9 @@ export function createCandidate(
productUrl: data.productUrl ?? null, productUrl: data.productUrl ?? null,
imageFilename: data.imageFilename ?? null, imageFilename: data.imageFilename ?? null,
status: data.status ?? "researching", status: data.status ?? "researching",
pros: data.pros ?? null,
cons: data.cons ?? null,
sortOrder: nextSortOrder,
}) })
.returning() .returning()
.get(); .get();
@@ -168,6 +186,8 @@ export function updateCandidate(
productUrl: string; productUrl: string;
imageFilename: string; imageFilename: string;
status: "researching" | "ordered" | "arrived"; status: "researching" | "ordered" | "arrived";
pros: string;
cons: string;
}>, }>,
) { ) {
const existing = db const existing = db
@@ -197,6 +217,35 @@ export function deleteCandidate(db: Db = prodDb, candidateId: number) {
return candidate; return candidate;
} }
export function reorderCandidates(
db: Db = prodDb,
threadId: number,
orderedIds: ReorderCandidates["orderedIds"],
): { success: boolean; error?: string } {
return db.transaction((tx) => {
const thread = tx
.select()
.from(threads)
.where(eq(threads.id, threadId))
.get();
if (!thread) {
return { success: false, error: "Thread not found" };
}
if (thread.status !== "active") {
return { success: false, error: "Thread not active" };
}
for (let i = 0; i < orderedIds.length; i++) {
tx.update(threadCandidates)
.set({ sortOrder: (i + 1) * 1000 })
.where(eq(threadCandidates.id, orderedIds[i]))
.run();
}
return { success: true };
});
}
export function resolveThread( export function resolveThread(
db: Db = prodDb, db: Db = prodDb,
threadId: number, threadId: number,

View File

@@ -53,6 +53,8 @@ export const createCandidateSchema = z.object({
productUrl: z.string().url().optional().or(z.literal("")), productUrl: z.string().url().optional().or(z.literal("")),
imageFilename: z.string().optional(), imageFilename: z.string().optional(),
status: candidateStatusSchema.optional(), status: candidateStatusSchema.optional(),
pros: z.string().optional(),
cons: z.string().optional(),
}); });
export const updateCandidateSchema = createCandidateSchema.partial(); export const updateCandidateSchema = createCandidateSchema.partial();
@@ -61,6 +63,10 @@ export const resolveThreadSchema = z.object({
candidateId: z.number().int().positive(), candidateId: z.number().int().positive(),
}); });
export const reorderCandidatesSchema = z.object({
orderedIds: z.array(z.number().int().positive()).min(1),
});
// Setup schemas // Setup schemas
export const createSetupSchema = z.object({ export const createSetupSchema = z.object({
name: z.string().min(1, "Setup name is required"), name: z.string().min(1, "Setup name is required"),

View File

@@ -13,6 +13,7 @@ import type {
createItemSchema, createItemSchema,
createSetupSchema, createSetupSchema,
createThreadSchema, createThreadSchema,
reorderCandidatesSchema,
resolveThreadSchema, resolveThreadSchema,
syncSetupItemsSchema, syncSetupItemsSchema,
updateCandidateSchema, updateCandidateSchema,
@@ -33,6 +34,7 @@ export type UpdateThread = z.infer<typeof updateThreadSchema>;
export type CreateCandidate = z.infer<typeof createCandidateSchema>; export type CreateCandidate = z.infer<typeof createCandidateSchema>;
export type UpdateCandidate = z.infer<typeof updateCandidateSchema>; export type UpdateCandidate = z.infer<typeof updateCandidateSchema>;
export type ResolveThread = z.infer<typeof resolveThreadSchema>; export type ResolveThread = z.infer<typeof resolveThreadSchema>;
export type ReorderCandidates = z.infer<typeof reorderCandidatesSchema>;
// Setup types // Setup types
export type CreateSetup = z.infer<typeof createSetupSchema>; export type CreateSetup = z.infer<typeof createSetupSchema>;

View File

@@ -55,6 +55,9 @@ export function createTestDb() {
product_url TEXT, product_url TEXT,
image_filename TEXT, image_filename TEXT,
status TEXT NOT NULL DEFAULT 'researching', status TEXT NOT NULL DEFAULT 'researching',
pros TEXT,
cons TEXT,
sort_order REAL NOT NULL DEFAULT 0,
created_at INTEGER NOT NULL DEFAULT (unixepoch()), created_at INTEGER NOT NULL DEFAULT (unixepoch()),
updated_at INTEGER NOT NULL DEFAULT (unixepoch()) updated_at INTEGER NOT NULL DEFAULT (unixepoch())
) )

View File

@@ -234,6 +234,119 @@ describe("Thread Routes", () => {
}); });
}); });
describe("PATCH /api/threads/:id/candidates/reorder", () => {
it("with valid orderedIds returns 200 + { success: true }", async () => {
const thread = await createThreadViaAPI(app, "Reorder Test");
const c1 = await createCandidateViaAPI(app, thread.id, {
name: "Candidate A",
categoryId: 1,
});
const c2 = await createCandidateViaAPI(app, thread.id, {
name: "Candidate B",
categoryId: 1,
});
const res = await app.request(
`/api/threads/${thread.id}/candidates/reorder`,
{
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ orderedIds: [c2.id, c1.id] }),
},
);
expect(res.status).toBe(200);
const body = await res.json();
expect(body.success).toBe(true);
});
it("after PATCH reorder, GET thread returns candidates in the new order", async () => {
const thread = await createThreadViaAPI(app, "Order Verify");
const c1 = await createCandidateViaAPI(app, thread.id, {
name: "First",
categoryId: 1,
});
const c2 = await createCandidateViaAPI(app, thread.id, {
name: "Second",
categoryId: 1,
});
const c3 = await createCandidateViaAPI(app, thread.id, {
name: "Third",
categoryId: 1,
});
// Reverse the order
await app.request(`/api/threads/${thread.id}/candidates/reorder`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ orderedIds: [c3.id, c2.id, c1.id] }),
});
const res = await app.request(`/api/threads/${thread.id}`);
expect(res.status).toBe(200);
const body = await res.json();
expect(body.candidates[0].id).toBe(c3.id);
expect(body.candidates[1].id).toBe(c2.id);
expect(body.candidates[2].id).toBe(c1.id);
});
it("on a resolved thread returns 400", async () => {
const thread = await createThreadViaAPI(app, "Resolved Thread");
const candidate = await createCandidateViaAPI(app, thread.id, {
name: "Winner",
categoryId: 1,
});
// Resolve the thread first
await app.request(`/api/threads/${thread.id}/resolve`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ candidateId: candidate.id }),
});
const res = await app.request(
`/api/threads/${thread.id}/candidates/reorder`,
{
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ orderedIds: [candidate.id] }),
},
);
expect(res.status).toBe(400);
});
it("with invalid body (empty orderedIds) returns 400", async () => {
const thread = await createThreadViaAPI(app, "Invalid Body");
const res = await app.request(
`/api/threads/${thread.id}/candidates/reorder`,
{
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ orderedIds: [] }),
},
);
expect(res.status).toBe(400);
});
it("with missing orderedIds field returns 400", async () => {
const thread = await createThreadViaAPI(app, "Missing Field");
const res = await app.request(
`/api/threads/${thread.id}/candidates/reorder`,
{
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({}),
},
);
expect(res.status).toBe(400);
});
});
describe("POST /api/threads/:id/resolve", () => { describe("POST /api/threads/:id/resolve", () => {
it("with valid candidateId returns 200 + created item", async () => { it("with valid candidateId returns 200 + created item", async () => {
const thread = await createThreadViaAPI(app, "Tent Decision"); const thread = await createThreadViaAPI(app, "Tent Decision");

View File

@@ -6,6 +6,7 @@ import {
deleteThread, deleteThread,
getAllThreads, getAllThreads,
getThreadWithCandidates, getThreadWithCandidates,
reorderCandidates,
resolveThread, resolveThread,
updateCandidate, updateCandidate,
updateThread, updateThread,
@@ -109,6 +110,21 @@ describe("Thread Service", () => {
const result = getThreadWithCandidates(db, 9999); const result = getThreadWithCandidates(db, 9999);
expect(result).toBeNull(); expect(result).toBeNull();
}); });
it("includes pros and cons on each candidate", () => {
const thread = createThread(db, { name: "Tent Options", categoryId: 1 });
createCandidate(db, thread.id, {
name: "Tent A",
categoryId: 1,
pros: "Lightweight",
cons: "Pricey",
});
const result = getThreadWithCandidates(db, thread.id);
expect(result).toBeDefined();
expect(result?.candidates[0].pros).toBe("Lightweight");
expect(result?.candidates[0].cons).toBe("Pricey");
});
}); });
describe("createCandidate", () => { describe("createCandidate", () => {
@@ -133,6 +149,30 @@ describe("Thread Service", () => {
expect(candidate.notes).toBe("Ultralight 2-person"); expect(candidate.notes).toBe("Ultralight 2-person");
expect(candidate.productUrl).toBe("https://example.com/tent"); expect(candidate.productUrl).toBe("https://example.com/tent");
}); });
it("stores and returns pros and cons", () => {
const thread = createThread(db, { name: "Tent Options", categoryId: 1 });
const candidate = createCandidate(db, thread.id, {
name: "Tent A",
categoryId: 1,
pros: "Lightweight\nGood reviews",
cons: "Expensive",
});
expect(candidate.pros).toBe("Lightweight\nGood reviews");
expect(candidate.cons).toBe("Expensive");
});
it("returns null for pros and cons when not provided", () => {
const thread = createThread(db, { name: "Tent Options", categoryId: 1 });
const candidate = createCandidate(db, thread.id, {
name: "Tent B",
categoryId: 1,
});
expect(candidate.pros).toBeNull();
expect(candidate.cons).toBeNull();
});
}); });
describe("updateCandidate", () => { describe("updateCandidate", () => {
@@ -157,6 +197,31 @@ describe("Thread Service", () => {
const result = updateCandidate(db, 9999, { name: "Ghost" }); const result = updateCandidate(db, 9999, { name: "Ghost" });
expect(result).toBeNull(); expect(result).toBeNull();
}); });
it("can set and clear pros and cons", () => {
const thread = createThread(db, { name: "Test", categoryId: 1 });
const candidate = createCandidate(db, thread.id, {
name: "Original",
categoryId: 1,
});
// Set pros and cons
const withPros = updateCandidate(db, candidate.id, {
pros: "Lightweight",
cons: "Expensive",
});
expect(withPros?.pros).toBe("Lightweight");
expect(withPros?.cons).toBe("Expensive");
// Clear pros and cons by setting to empty string
const cleared = updateCandidate(db, candidate.id, {
pros: "",
cons: "",
});
// Empty string stored as-is or null — either is acceptable
expect(cleared?.pros == null || cleared?.pros === "").toBe(true);
expect(cleared?.cons == null || cleared?.cons === "").toBe(true);
});
}); });
describe("deleteCandidate", () => { describe("deleteCandidate", () => {
@@ -298,6 +363,95 @@ describe("Thread Service", () => {
}); });
}); });
describe("sort_order ordering", () => {
it("getThreadWithCandidates returns candidates ordered by sort_order ascending", () => {
const thread = createThread(db, { name: "Order Test", categoryId: 1 });
const c1 = createCandidate(db, thread.id, {
name: "Candidate 1",
categoryId: 1,
});
const c2 = createCandidate(db, thread.id, {
name: "Candidate 2",
categoryId: 1,
});
const c3 = createCandidate(db, thread.id, {
name: "Candidate 3",
categoryId: 1,
});
// Manually set sort_orders out of creation order using reorderCandidates
reorderCandidates(db, thread.id, [c3.id, c1.id, c2.id]);
const result = getThreadWithCandidates(db, thread.id);
expect(result).toBeDefined();
expect(result?.candidates[0].id).toBe(c3.id);
expect(result?.candidates[1].id).toBe(c1.id);
expect(result?.candidates[2].id).toBe(c2.id);
});
it("createCandidate assigns sort_order = max existing sort_order + 1000", () => {
const thread = createThread(db, { name: "Append Test", categoryId: 1 });
// First candidate should get sort_order 1000
const c1 = createCandidate(db, thread.id, {
name: "First",
categoryId: 1,
});
expect(c1.sortOrder).toBe(1000);
// Second candidate should get sort_order 2000
const c2 = createCandidate(db, thread.id, {
name: "Second",
categoryId: 1,
});
expect(c2.sortOrder).toBe(2000);
});
});
describe("reorderCandidates", () => {
it("reorderCandidates updates sort_order so querying returns candidates in new order", () => {
const thread = createThread(db, { name: "Reorder Test", categoryId: 1 });
const c1 = createCandidate(db, thread.id, {
name: "Candidate 1",
categoryId: 1,
});
const c2 = createCandidate(db, thread.id, {
name: "Candidate 2",
categoryId: 1,
});
const c3 = createCandidate(db, thread.id, {
name: "Candidate 3",
categoryId: 1,
});
const result = reorderCandidates(db, thread.id, [c3.id, c1.id, c2.id]);
expect(result.success).toBe(true);
const fetched = getThreadWithCandidates(db, thread.id);
expect(fetched?.candidates[0].id).toBe(c3.id);
expect(fetched?.candidates[1].id).toBe(c1.id);
expect(fetched?.candidates[2].id).toBe(c2.id);
});
it("returns { success: false, error } when thread status is 'resolved'", () => {
const thread = createThread(db, { name: "Resolved Thread", categoryId: 1 });
const candidate = createCandidate(db, thread.id, {
name: "Winner",
categoryId: 1,
});
resolveThread(db, thread.id, candidate.id);
const result = reorderCandidates(db, thread.id, [candidate.id]);
expect(result.success).toBe(false);
expect(result.error).toBeDefined();
});
it("returns { success: false } when thread does not exist", () => {
const result = reorderCandidates(db, 9999, [1, 2]);
expect(result.success).toBe(false);
});
});
describe("resolveThread", () => { describe("resolveThread", () => {
it("atomically creates collection item from candidate data and archives thread", () => { it("atomically creates collection item from candidate data and archives thread", () => {
const thread = createThread(db, { name: "Tent Decision", categoryId: 1 }); const thread = createThread(db, { name: "Tent Decision", categoryId: 1 });