Repository navigation
feat(tasks): due dates + multi-trigger task autocomplete (0172) #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e1cc4b1
docs(exploration): explore task due dates and rich inline editing
crs48 de25647
feat(tasks): canonical due-date conversion module (0172 phase 0)
crs48 ad03189
feat(tasks): natural-language due-date entry in the picker (0172 phas…
crs48 4b61fcf
feat(tasks): multi-trigger composer + d shortcut (0172 phases 2-3)
crs48 1218683
test(tasks): cover TaskDueDatePalette; check off 0172 phases 0-3
crs48 f66acdb
Merge remote-tracking branch 'origin/main' into feat/task-due-dates
crs48 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { fireEvent, render, screen } from '@testing-library/react' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { TaskDueDatePalette } from './TaskDueDatePalette' | ||
|
|
||
| function paletteInput(): HTMLInputElement { | ||
| return screen.getByTestId('task-due-palette').querySelector('input') as HTMLInputElement | ||
| } | ||
|
|
||
| describe('TaskDueDatePalette', () => { | ||
| it('commits a typed natural-language date and closes', () => { | ||
| const onSelect = vi.fn() | ||
| const onClose = vi.fn() | ||
| render(<TaskDueDatePalette onSelect={onSelect} onClose={onClose} />) | ||
|
|
||
| fireEvent.change(paletteInput(), { target: { value: '2026-07-01' } }) | ||
| expect(screen.getByText(/Set due/)).toBeTruthy() | ||
| fireEvent.keyDown(paletteInput(), { key: 'Enter' }) | ||
|
|
||
| expect(onSelect).toHaveBeenCalledWith(Date.UTC(2026, 6, 1)) | ||
| expect(onClose).toHaveBeenCalledTimes(1) | ||
| }) | ||
|
|
||
| it('clears the due date via the preset', () => { | ||
| const onSelect = vi.fn() | ||
| render(<TaskDueDatePalette onSelect={onSelect} onClose={() => {}} />) | ||
|
|
||
| fireEvent.click(screen.getByText('Clear due date')) | ||
| expect(onSelect).toHaveBeenCalledWith(null) | ||
| }) | ||
|
|
||
| it('navigates presets with arrow keys and commits on Enter', () => { | ||
| const onSelect = vi.fn() | ||
| render(<TaskDueDatePalette onSelect={onSelect} onClose={() => {}} />) | ||
|
|
||
| // Default list starts at "Today"; ArrowDown→Tomorrow, ArrowUp→Today. | ||
| fireEvent.keyDown(paletteInput(), { key: 'ArrowDown' }) | ||
| fireEvent.keyDown(paletteInput(), { key: 'ArrowUp' }) | ||
| fireEvent.keyDown(paletteInput(), { key: 'Enter' }) | ||
| expect(onSelect).toHaveBeenCalledTimes(1) | ||
| expect(typeof onSelect.mock.calls[0][0]).toBe('number') | ||
| }) | ||
|
|
||
| it('closes on Escape and backdrop click without selecting', () => { | ||
| const onSelect = vi.fn() | ||
| const onClose = vi.fn() | ||
| render(<TaskDueDatePalette onSelect={onSelect} onClose={onClose} />) | ||
|
|
||
| fireEvent.keyDown(paletteInput(), { key: 'Escape' }) | ||
| fireEvent.click(screen.getByTestId('task-due-palette')) | ||
| expect(onClose).toHaveBeenCalled() | ||
| expect(onSelect).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('filters presets by the typed query when it is not a date', () => { | ||
| render(<TaskDueDatePalette onSelect={() => {}} onClose={() => {}} />) | ||
|
|
||
| fireEvent.change(paletteInput(), { target: { value: 'week' } }) | ||
| expect(screen.getByText('Next week')).toBeTruthy() | ||
| expect(screen.queryByText('Today')).toBeNull() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| /** | ||
| * TaskDueDatePalette - keyboard-first due-date entry for a focused task. | ||
| * | ||
| * Opened by the `d` verb on the Tasks surface. Typing a natural-language date | ||
| * ("next friday", "in 3 days", "2026-07-01") surfaces a live "Set due …" row; | ||
| * Enter commits the highlighted option. Presets and a clear action round out | ||
| * the list. Mirrors TaskMiniPalette so the registry's single-key verbs stay | ||
| * suppressed while its input is focused. | ||
| */ | ||
| import { parseDueDate, utcDayFromNow } from '@xnetjs/ui' | ||
| import { useMemo, useRef, useState, type JSX } from 'react' | ||
|
|
||
| export interface TaskDueDatePaletteProps { | ||
| /** Commit a due date (UTC-midnight ms) or null to clear. */ | ||
| onSelect: (dueDate: number | null) => void | ||
| onClose: () => void | ||
| } | ||
|
|
||
| interface DueOption { | ||
| id: string | ||
| label: string | ||
| ms: number | null | ||
| } | ||
|
|
||
| function formatDue(ms: number): string { | ||
| return new Date(ms).toLocaleDateString(undefined, { | ||
| weekday: 'short', | ||
| month: 'short', | ||
| day: 'numeric', | ||
| timeZone: 'UTC' | ||
| }) | ||
| } | ||
|
|
||
| export function TaskDueDatePalette({ onSelect, onClose }: TaskDueDatePaletteProps): JSX.Element { | ||
| const [query, setQuery] = useState('') | ||
| const [activeIndex, setActiveIndex] = useState(0) | ||
| const inputRef = useRef<HTMLInputElement>(null) | ||
|
|
||
| const options = useMemo<DueOption[]>(() => { | ||
| const trimmed = query.trim() | ||
| const parsed = trimmed ? parseDueDate(trimmed) : null | ||
| const presets: DueOption[] = [ | ||
| { id: 'today', label: 'Today', ms: utcDayFromNow(0) }, | ||
| { id: 'tomorrow', label: 'Tomorrow', ms: utcDayFromNow(1) }, | ||
| { | ||
| id: 'weekend', | ||
| label: 'This weekend', | ||
| ms: parseDueDate('this weekend')?.ms ?? utcDayFromNow(0) | ||
| }, | ||
| { id: 'nextweek', label: 'Next week', ms: utcDayFromNow(7) }, | ||
| { id: 'clear', label: 'Clear due date', ms: null } | ||
| ] | ||
| const filtered = trimmed | ||
| ? presets.filter((option) => option.label.toLowerCase().includes(trimmed.toLowerCase())) | ||
| : presets | ||
| return parsed | ||
| ? [{ id: 'parsed', label: `Set due ${formatDue(parsed.ms)}`, ms: parsed.ms }, ...filtered] | ||
| : filtered | ||
| }, [query]) | ||
|
|
||
| const commit = (option: DueOption | undefined) => { | ||
| if (!option) return | ||
| onSelect(option.ms) | ||
| onClose() | ||
| } | ||
|
|
||
| return ( | ||
| <div | ||
| className="fixed inset-0 z-50 flex items-start justify-center bg-black/30 pt-32" | ||
| onClick={onClose} | ||
| data-testid="task-due-palette" | ||
| > | ||
| <div | ||
| className="w-full max-w-xs overflow-hidden rounded-lg border border-border bg-background shadow-2xl" | ||
| onClick={(event) => event.stopPropagation()} | ||
| > | ||
| <input | ||
| ref={inputRef} | ||
| autoFocus | ||
| type="text" | ||
| value={query} | ||
| placeholder="Set due date… (e.g. next friday)" | ||
| onChange={(event) => { | ||
| setQuery(event.target.value) | ||
| setActiveIndex(0) | ||
| }} | ||
| onKeyDown={(event) => { | ||
| if (event.key === 'ArrowDown') { | ||
| event.preventDefault() | ||
| setActiveIndex((index) => Math.min(index + 1, options.length - 1)) | ||
| } else if (event.key === 'ArrowUp') { | ||
| event.preventDefault() | ||
| setActiveIndex((index) => Math.max(index - 1, 0)) | ||
| } else if (event.key === 'Enter') { | ||
| event.preventDefault() | ||
| commit(options[activeIndex]) | ||
| } else if (event.key === 'Escape') { | ||
| event.preventDefault() | ||
| event.stopPropagation() | ||
| onClose() | ||
| } | ||
| }} | ||
| className="w-full border-b border-border bg-transparent px-3 py-2 text-sm text-foreground outline-none placeholder:text-muted-foreground" | ||
| /> | ||
| <ul className="max-h-60 list-none overflow-y-auto p-1"> | ||
| {options.map((option, index) => ( | ||
| <li | ||
| key={option.id} | ||
| className={`flex cursor-pointer items-center gap-2 rounded-md px-2 py-1.5 text-sm text-foreground ${ | ||
| index === activeIndex ? 'bg-secondary' : 'hover:bg-secondary' | ||
| }`} | ||
| onClick={() => commit(option)} | ||
| onMouseEnter={() => setActiveIndex(index)} | ||
| > | ||
| {option.label} | ||
| </li> | ||
| ))} | ||
| {options.length === 0 && ( | ||
| <li className="px-2 py-1.5 text-sm text-muted-foreground">No matches</li> | ||
| )} | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clamp keyboard index when the options list is empty.
With zero options, ArrowDown currently drives
activeIndexto-1. Keep the index at0when the list is empty so keyboard state stays valid.Suggested fix
onKeyDown={(event) => { if (event.key === 'ArrowDown') { event.preventDefault() - setActiveIndex((index) => Math.min(index + 1, options.length - 1)) + setActiveIndex((index) => + options.length > 0 ? Math.min(index + 1, options.length - 1) : 0 + ) } else if (event.key === 'ArrowUp') { event.preventDefault() - setActiveIndex((index) => Math.max(index - 1, 0)) + setActiveIndex((index) => (options.length > 0 ? Math.max(index - 1, 0) : 0)) } else if (event.key === 'Enter') {📝 Committable suggestion
🤖 Prompt for AI Agents