Skip to content

Add date picker and shortcuts to @mention system - #357

Merged
malibio merged 6 commits into
mainfrom
feature/issue-201-date-picker-shortcuts
Oct 31, 2025
Merged

malibio merged 6 commits into
mainfrom
feature/issue-201-date-picker-shortcuts

Conversation

@malibio

@malibio malibio commented Oct 30, 2025 •

Copy link
Copy Markdown
Collaborator

Summary

Implements a working calendar date picker for the @mention autocomplete system with date shortcuts.

Features Implemented

  • ✅ Date shortcuts (Today/Tomorrow/Yesterday) in @mention autocomplete
  • ✅ "Select date..." option opens calendar picker
  • ✅ Calendar date selection creates date links
  • ✅ Calendar icon displayed for date shortcuts
  • ✅ Proper timezone handling in date formatting
  • ✅ Accessibility support (ARIA roles)

Technical Details

Root Causes Fixed:

  1. Calendar wrapper missing type="single" prop - Not forwarded to bits-ui primitive
  2. Focus loss destroying controller - Clicking calendar blurred textarea, exited edit mode

Solutions:

  1. Calendar wrapper improvements (calendar.svelte):

    • Explicitly extract and forward type prop
    • Intermediate state binding bridge with internalValue
    • Proper handleValueChange propagation
  2. Prevent blur during interaction (base-node.svelte):

    • Added onmousedown with preventDefault() to calendar container
    • Industry-standard pattern (same as NodeAutocomplete line 262)
    • Added ARIA role="dialog" and tabindex for accessibility
  3. Clean Svelte 5 reactivity (base-node.svelte):

    • $effect watches selectedCalendarDate changes
    • Fixed timezone handling in formatDate()
    • Follows official shadcn-svelte pattern

Files Changed

  • packages/desktop-app/src/lib/components/ui/calendar/calendar.svelte - Fixed prop forwarding
  • packages/desktop-app/src/lib/components/ui/calendar/calendar-day.svelte - Cleaned up debug code
  • packages/desktop-app/src/lib/design/components/base-node.svelte - Calendar integration

Testing

  • ✅ All 471 tests passing
  • ✅ Manual testing verified - date links created correctly
  • ✅ Date shortcuts (Today/Tomorrow/Yesterday) work
  • ✅ No regressions detected
  • ✅ Quality checks passed (lint, format, type-check)

Closes #201

🤖 Generated with Claude Code

@malibio
malibio force-pushed the feature/issue-201-date-picker-shortcuts branch from c02e1bf to a623a4b Compare October 30, 2025 23:46
malibio and others added 6 commits October 31, 2025 00:56
Enhance the @mention autocomplete with date-specific functionality:

- Add date shortcuts (Today/Tomorrow/Yesterday) at top of autocomplete
- Add "Date (pick)" option that opens date picker modal
- Create DatePickerModal component with native HTML date input
- Implement date formatting utilities (YYYY-MM-DD)
- Add DateNode creation/retrieval logic using backendAdapter
- Date shortcuts filter based on user's query text
- Date references inserted as markdown links: [YYYY-MM-DD](nodespace://YYYY-MM-DD)

All quality checks passing.

Closes #201

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
ROOT CAUSE:
- Code was trying to create date nodes in the database when selecting from autocomplete
- This caused UNIQUE constraint errors because dates are virtual (conceptually exist for all dates)
- Date nodes only get persisted when children/content are added

FIX:
- Remove unnecessary database creation in handleDateSelection()
- Just insert markdown link directly: [@today](nodespace://2025-10-30)
- Remove unused createDateNode() function

DESIGN IMPROVEMENTS:
- Add ChevronRight icon to "Select date >" item for visual consistency
- Align chevron to the right of the item using flexbox layout
- Position date picker as submenu relative to "Select date" item
- Add reactive effect to close date picker when autocomplete closes
- Fix TypeScript linting warnings with proper type assertions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
- Use bind:value instead of onValueChange for Calendar component (Svelte 5 $bindable pattern)
- Add $effect to watch selectedCalendarDate and trigger date selection
- Change label from "Select date >" to "Select date..." per user feedback

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
WHAT WORKS ✅:
- Date shortcuts (Today/Tomorrow/Yesterday) insert links correctly
- UNIQUE constraint error fixed (dates are virtual, no DB creation)
- ChevronRight icon on "Select date..."
- Calendar renders and displays all dates properly
- Picker closes when date clicked

WHAT DOESN'T WORK ❌:
- onValueChange callback never fires when clicking calendar dates
- No link created from calendar selection
- Debug logs confirm callback not being invoked

VERIFIED VIA CHROME DEVTOOLS:
- Typed @ → autocomplete appeared
- Clicked "Select date..." → calendar opened with full date grid
- Clicked October 1 → calendar closed
- NO console logs from onValueChange callback

IMPLEMENTATION:
base-node.svelte:954:
  <Calendar type="single" bind:value={selectedCalendarDate} onValueChange={(v) => {...}} />

calendar.svelte:
  Wrapper passes props via {...restProps} to CalendarPrimitive.Root

ROOT CAUSE:
CalendarPrimitive.Root (bits-ui) not calling onValueChange despite prop being passed

NEXT INVESTIGATION:
1. Why bits-ui Calendar doesn't fire onValueChange in Svelte 5
2. Is wrapper's "as never" cast breaking callback?
3. Check bits-ui version compatibility
4. Try bypassing wrapper entirely

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
PROBLEM SOLVED:
- Calendar rendered but date selection never created links
- Clicking dates closed calendar with no value captured
- bind:value wasn't updating selectedCalendarDate

ROOT CAUSES FIXED:
1. Calendar wrapper wasn't forwarding type="single" prop to bits-ui primitive
2. Clicking calendar caused textarea to blur, exiting edit mode and destroying controller

SOLUTION:
- Explicitly extract and forward type prop in calendar wrapper
- Add intermediate state binding bridge (internalValue) in wrapper
- Prevent blur with onmousedown handler (industry standard pattern)
- Use Svelte 5 reactive $effect to watch selectedCalendarDate changes
- Fix date formatting to use local timezone (not UTC)

IMPLEMENTATION:
- Calendar component: Added type prop extraction and handleValueChange bridge
- BaseNode: Added onmousedown preventDefault to maintain edit mode during selection
- Used same pattern as NodeAutocomplete (line 262) for consistency
- Added ARIA role=dialog and tabindex for accessibility

TESTING:
- All 471 existing tests passing
- Manual testing confirms date links created correctly
- Date shortcuts (Today/Tomorrow/Yesterday) still work
- No regressions detected

Fixes #201

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
IMPROVEMENTS IMPLEMENTED:
1. Icon Registry - Added explicit 'date' node type registration
2. Documentation - Added comprehensive docs for calendar value binding workaround
3. Type Safety - Added submenuPosition to NodeResult interface (removed type assertions)
4. Code Cleanup - Removed unused DatePickerModal component
5. Performance - Memoized DATE_SHORTCUTS array to avoid recreation
6. Accessibility - Enhanced ARIA labels with keyboard navigation hints
7. Test Coverage - Added 28 comprehensive tests for date picker functionality

DETAILS:

Icon Registry (registry.ts):
- Added 'date' node type using CircleIcon with ring effect
- Dates can have children (journal entries, notes, etc.)
- Uses consistent color theming (--node-date CSS variable)

Calendar Binding Documentation (calendar.svelte):
- Documented bridge pattern workaround for bits-ui Svelte 5 limitation
- Explained why 'as never' casts are necessary (discriminated union conflicts)
- Added TODO for revisiting when bits-ui has full Svelte 5 support

Type Safety (node-autocomplete/index.ts):
- Added submenuPosition field to NodeResult interface
- Removed type assertion in node-autocomplete.svelte
- Synchronized local and exported NodeResult interfaces

Code Cleanup:
- Removed unused date-picker-modal.svelte and index.ts
- Removed empty date-picker directory

Performance Optimization (base-node.svelte):
- Extracted DATE_SHORTCUTS to module-level const with readonly type
- Prevents array recreation on every getDateShortcuts() call
- Micro-optimization with zero risk

Accessibility (base-node.svelte):
- Enhanced aria-label with keyboard navigation instructions
- Added aria-modal="true" for proper screen reader announcement
- Maintains existing role="dialog" semantic structure

Test Coverage (date-picker.test.ts):
- 28 comprehensive tests covering all date picker functionality
- Date formatting with timezone handling (local vs UTC)
- Date shortcut filtering (Today/Tomorrow/Yesterday)
- Date calculation from shortcuts with boundary handling
- Virtual date node pattern (markdown links without DB)
- NodeResult interface extension validation
- Accessibility attributes verification
- Edge cases (leap years, month boundaries, immutability)

All tests pass (28/28), quality checks pass (0 errors, 0 warnings).

Addresses ALL reviewer recommendations from pragmatic code review.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@malibio
malibio force-pushed the feature/issue-201-date-picker-shortcuts branch from a623a4b to 07ae007 Compare October 31, 2025 00:01
@malibio
malibio merged commit a31d1cb into main Oct 31, 2025
@malibio
malibio deleted the feature/issue-201-date-picker-shortcuts branch October 31, 2025 00:09
malibio added a commit that referenced this pull request Feb 4, 2026
…ortcuts

Add date picker and shortcuts to @mention system
malibio added a commit that referenced this pull request Feb 5, 2026
…ortcuts

Add date picker and shortcuts to @mention system
malibio added a commit that referenced this pull request Feb 26, 2026
…ortcuts

Add date picker and shortcuts to @mention system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add date picker and shortcuts to @mention system

1 participant