feat: implement tap & hold to select shelf items#415
Conversation
- Add useLongPress hook for gesture detection (500ms delay) - Extend useBookListView with enterSelectModeWithSelection function - Update BookListItem to support long-press activation - Wire DraggableBookList and shelves page to new functionality - Separate touch targets: drag handle (200ms) vs card body (500ms) Resolves #414 Co-authored-by: OpenCode <assistant@opencode.ai>
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## develop #415 +/- ##
===========================================
+ Coverage 78.67% 78.79% +0.11%
===========================================
Files 167 168 +1
Lines 7559 7605 +46
Branches 1850 1860 +10
===========================================
+ Hits 5947 5992 +45
Misses 1127 1127
- Partials 485 486 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
- Add useEffect cleanup to prevent memory leaks on unmount - Add keyboard accessibility (Space key triggers selection) - Add ARIA attributes for screen readers - Add comprehensive test coverage for useLongPress hook (21 tests) Addresses critical issues: - Memory leak: timeout not cleared on component unmount - Accessibility: no keyboard or screen reader support - Testing: missing test coverage violating constitution All 4034 tests passing.
|
@copilot review this PR |
Agent-Logs-Url: https://github.com/masonfox/tome/sessions/3ab0d2da-413e-4bc3-8487-21a15b36066f Co-authored-by: masonfox <13393712+masonfox@users.noreply.github.com>
Reviewed the PR. The implementation is clean and well-structured. Two issues found and fixed in commit Bug fix — missing Accessibility fix — Everything else looks solid — movement tolerance, cleanup on unmount, prop drilling pattern, conditional handler spreading, and memo comparison all look correct. CodeQL scan and code review both came back clean. |
PR #415 was marked as merged but commits never made it to develop branch. Cherry-picked the three feature commits to restore functionality: - Add enterSelectModeWithSelection to useBookListView - Integrate useLongPress hook in BookListItem - Wire up long-press handlers in DraggableBookList and shelves page - Add keyboard accessibility (Space/Enter keys) - Add comprehensive test coverage (22 tests) Note: hooks/useLongPress.ts already existed on develop from commit 9f2ca50 and matches the final PR version, so it was kept unchanged. Original commits: - b88e3fc feat: implement tap & hold to select shelf items - 990c8aa fix: implement @review feedback (iteration 1) - f623bb4 fix: add onTouchCancel handler and Enter key accessibility support Resolves #414 Fixes #415 Co-authored-by: OpenCode <assistant@opencode.ai>
## Summary Fixes PR #415 which was marked as MERGED in GitHub but the commits never actually made it into the develop branch. This PR cherry-picks the three orphaned feature commits to restore the tap & hold to select functionality. **Problem:** PR #415 shows as merged, but the feature code is missing from develop (except for `useLongPress.ts` which was added separately in commit 9f2ca50). **Solution:** Cherry-picked the three orphaned commits and squashed them into a single commit with proper attribution. --- ## Changes ### Modified Files (5) 1. **`hooks/useBookListView.ts`** - Added `enterSelectModeWithSelection()` function 2. **`components/Books/BookListItem.tsx`** - Integrated useLongPress hook + keyboard accessibility 3. **`components/Books/DraggableBookList.tsx`** - Added long-press props and wiring 4. **`app/shelves/[id]/page.tsx`** - Wired up long-press handlers to list views ### New Files (1) 5. **`__tests__/hooks/useLongPress.test.ts`** - Comprehensive test suite (22 tests) **Note:** `hooks/useLongPress.ts` already existed on develop (added by commit 9f2ca50) and matches the final PR version, so it was kept unchanged. --- ## Feature: Tap & Hold to Select Implements long-press gesture to enter select mode on shelf items, eliminating the need to scroll to the top to press the "Select" button. **Key Features:** - Long-press (500ms) on book card body enters select mode and auto-selects the item - Separate touch targets: drag handle (200ms) vs card body (500ms) to avoid conflicts - 10px movement tolerance to prevent activation during scrolling - Keyboard accessibility: Space and Enter keys trigger selection - ARIA attributes for screen readers - Mobile-focused UX improvement **Behavior:** 1. User long-presses on book card (NOT in select mode) 2. After 500ms: enters select mode + selects that book 3. BulkActionBar appears at bottom 4. User can tap other books to select/deselect 5. Existing "Select" button still works --- ## Testing ✅ **All 4044 tests pass** (includes 22 new useLongPress tests) ✅ **Build succeeds** with no TypeScript errors ### Test Coverage - Mouse events (down, up, move, leave) - Touch events (start, end, cancel, move) - Keyboard events (Space, Enter) - Movement tolerance (cancels when exceeding 10px) - Configurable delay and tolerance options - Memory leak prevention (cleanup on unmount) - ARIA attributes for accessibility --- ## Original Commits This PR incorporates the following orphaned commits: - `b88e3fc` - feat: implement tap & hold to select shelf items - `990c8aa` - fix: implement @review feedback (iteration 1) - `f623bb4` - fix: add onTouchCancel handler and Enter key accessibility support --- ## References - **Original PR:** #415 - **Issue:** #414 - **Problem Commit:** 9f2ca50 (added useLongPress.ts but not integration code) **Resolves:** #414 **Fixes:** #415 Co-authored-by: OpenCode <assistant@opencode.ai>
Summary
Implements tap & hold gesture to enter select mode on shelf items, eliminating the need to scroll to the top to press the "Select" button.
Key Features:
Resolves: #414
Changes
New Files
hooks/useLongPress.ts- Reusable long-press detection hookModified Files
hooks/useBookListView.ts- AddedenterSelectModeWithSelection(bookId)functioncomponents/Books/BookListItem.tsx- Integrated long-press handlers on card bodycomponents/Books/DraggableBookList.tsx- Passes long-press handler to itemsapp/shelves/[id]/page.tsx- Wires up new functionality on mobile list viewsTechnical Details
Touch Target Separation
This eliminates timing conflicts between drag and select gestures.
Behavior
Safeguards
Testing
✅ All 4013 tests pass
Manual Testing Checklist
Mobile UX Benefits
Before: User must scroll to top → press "Select" button → scroll back down → select items
After: User long-presses on any item → immediately in select mode with that item selected → continue selecting
Much faster and more intuitive, especially on mobile devices.