Skip to content

Eliminate calendar date selection effect - use onchange handler #627

Closed

Description

@malibio

Overview

Replace the $effect that watches selectedCalendarDate with a direct onchange handler on the Calendar component.

Problem Statement

Current implementation watches the calendar's bound value to detect selection:

// Lines 280-289 in base-node.svelte
$effect(() => {
  if (selectedCalendarDate) {
    const { year, month, day } = selectedCalendarDate;
    const jsDate = new Date(year, month - 1, day);
    handleDateSelection(jsDate);
    selectedCalendarDate = undefined;  // Reset for next selection
  }
});

This is watching for a value change to trigger an action - the definition of "effect as event handler". The Calendar component should have an onselect or onchange event we can use directly.

Proposed Solution

Use the Calendar's event callback instead of watching state:

<Calendar 
  type="single" 
  bind:value={selectedCalendarDate}
  onValueChange={(date) => {
    if (date) {
      const { year, month, day } = date;
      const jsDate = new Date(year, month - 1, day);
      handleDateSelection(jsDate);
    }
  }}
/>

Or if the shadcn Calendar doesn't have an event, wrap the selection logic in a controlled component pattern.

Acceptance Criteria

  • Calendar selection handled via event callback, not $effect
  • One $effect eliminated from base-node.svelte
  • Date selection works identically (today, tomorrow, calendar picker)
  • Date gets inserted into content correctly
  • Code passes bun run quality:fix
  • Tests pass (bun run test:all)

Technical Specifications

Files to Modify

  • base-node.svelte: packages/desktop-app/src/lib/design/components/base-node.svelte - Lines 280-289

Calendar Component

  • calendar.svelte: packages/desktop-app/src/lib/components/ui/calendar/calendar.svelte
  • Check available props/events on the shadcn Calendar component
  • May need to check bits-ui Calendar API for event callbacks

Migration Steps

  1. Check Calendar component API for onValueChange or similar
  2. If available, use it directly
  3. If not, consider wrapping or modifying Calendar to emit event
  4. Remove the $effect watching selectedCalendarDate

Testing Requirements

  • Open autocomplete with @
  • Select "Select date..." option
  • Click a date in calendar
  • Verify date link inserted correctly
  • Verify calendar closes after selection

Related Issues

Activity

  1. malibio commented on Nov 30, 2025

    @malibio
    CollaboratorAuthor

    This issue is already complete in the current codebase. Analysis:

    • Lines 272-274: Comments state 'REMOVED: Calendar date selection effect' and 'Now handled via Calendar's onchange event handler'
    • Lines 951-963: Calendar component uses onValueChange callback directly:
      <Calendar
        type="single"
        bind:value={selectedCalendarDate}
        onValueChange={(date) => {
          if (date) {
            const { year, month, day } = date;
            const jsDate = new Date(year, month - 1, day);
            handleDateSelection(jsDate);
          }
          selectedCalendarDate = undefined;
        }}
      />
    • No $effect watching selectedCalendarDate exists

    All acceptance criteria are met:

    • ✅ Calendar selection handled via event callback, not $effect
    • ✅ One $effect eliminated from base-node.svelte
    • ✅ Date selection works identically
    • ✅ Tests pass
  2. malibio commented on Nov 30, 2025

    @malibio
    CollaboratorAuthor

    Closing as already complete - all acceptance criteria met in current codebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions