Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
188 changes: 188 additions & 0 deletions docs/tasks-todo/task-x-move-incomplete-tasks-to-today.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
# Move Incomplete Tasks to Today

**GitHub Issue:** [#38](https://github.com/dannysmith/taskdn/issues/38)
**Work Directory:** `tdn-desktop/`

## Requirements

Add a command that bulk-reschedules overdue incomplete tasks to today. The command sets the `scheduled` date to today for all tasks matching **all three** criteria:

1. Has a `scheduled` date set
2. Status is NOT `done` or `dropped`
3. The `scheduled` date is strictly before today
4. Not archived — the backend's `listTasks()` only reads direct files in the tasks directory (not subdirectories), so archived tasks in `tasks/archive/` are never returned and require no additional filtering

Completed and dropped tasks keep their original scheduled date.

### Surfaces

The command must be accessible from:

1. **Command palette** — searchable by name/keywords
2. **Button in the Today column header** — visible in the This Week calendar view only, inside the day header of the column representing today

## Implementation Plan

### Step 1: Add `getTasks()` to CommandContext

The existing `CommandContext` exposes `getAreas()` and `getProjects()` but not tasks. The bulk command needs to read all tasks from the TanStack Query cache.

**Files to change:**

- `src/lib/commands/types.ts` — Add `getTasks: () => Task[]` to the `CommandContext` interface, next to `getAreas()` and `getProjects()` in the "Data access" section
- `src/hooks/use-command-context.ts` — Implement `getTasks()` following the exact pattern of `getAreas()`/`getProjects()`:
```typescript
getTasks: () => {
const tasks = queryClient.getQueryData<Task[]>(vaultQueryKeys.tasks())
return tasks ?? []
},
```

### Step 2: Add the command

**File:** `src/lib/commands/task-commands.ts`

Add a new `move-incomplete-to-today` command to the `taskCommands` array. This is a **global command** (not scoped to a selected task), so it does NOT use `isTaskCommandAvailable` or `getTargetTask`.

```typescript
{
id: 'move-incomplete-to-today',
labelKey: 'commands.moveIncompleteToToday.label',
descriptionKey: 'commands.moveIncompleteToToday.description',
icon: CalendarArrowUp, // from lucide-react
group: 'tasks',
keywords: ['move', 'incomplete', 'overdue', 'reschedule', 'today', 'catch up', 'past'],
surfaces: { commandPalette: true, appMenu: 'Edit' },

execute: async context => {
const today = getTodayISO()
const tasks = context.getTasks()

const overdueTasks = tasks.filter(task =>
task.scheduled &&
task.scheduled < today &&
task.status !== 'done' &&
task.status !== 'dropped'
)

if (overdueTasks.length === 0) {
context.showToast(t('commands.moveIncompleteToToday.noTasks'), 'info')
return
}

markMutationStart()

const results = await Promise.all(
overdueTasks.map(task =>
commands.updateTask({
id: task.id,
title: null,
status: null,
project: null,
area: null,
scheduled: today,
due: null,
deferUntil: null,
body: null,
})
)
)

markMutationComplete()

// Update cache for successful updates, log failures
let successCount = 0
for (let i = 0; i < results.length; i++) {
const result = results[i]
if (result.status === 'ok') {
context.updateTaskInCache(overdueTasks[i].id, result.data)
successCount++
} else {
logger.error('Failed to reschedule task', {
taskId: overdueTasks[i].id,
error: result.error,
})
}
}

if (successCount === 0) {
context.showToast(t('commands.moveIncompleteToToday.error'), 'error')
} else {
context.showToast(
t('commands.moveIncompleteToToday.success', { count: successCount }),
'success'
)
}
},
}
```

**Design notes:**

- Uses `Promise.all` to update all tasks in parallel rather than sequentially — the Rust backend handles file writes independently and ~50ms per task would add up for many tasks
- String comparison `task.scheduled < today` works correctly because both are ISO date strings (`YYYY-MM-DD`)
- `markMutationStart()`/`markMutationComplete()` wraps the entire batch to prevent file watcher cache invalidation during the operation
- Partial failure is handled gracefully: successful updates are cached, failures logged, toast reflects actual count

### Step 3: Add i18n strings

**File:** `locales/en.json`

Add these keys:

```json
"commands.moveIncompleteToToday.label": "Move Incomplete Tasks to Today",
"commands.moveIncompleteToToday.description": "Reschedule all overdue incomplete tasks to today",
"commands.moveIncompleteToToday.success": "Moved {{count}} task(s) to today",
"commands.moveIncompleteToToday.noTasks": "No overdue tasks to reschedule",
"commands.moveIncompleteToToday.error": "Failed to reschedule tasks"
```

### Step 4: Add button to the Today column in WeekCalendar

The button should appear in the day header of the column that represents today, only in the This Week calendar view.

**File: `src/components/calendar/DayColumn.tsx`**

- Add an optional `onMoveIncompleteToToday?: () => void` prop to `DayColumnProps`
- When `isCurrentDay` is true AND the prop is provided, render a small icon button in the day header between the day name and the date number. Use a subtle style (`ghost` variant, small size) so it doesn't crowd the header. Use the same `CalendarArrowUp` icon as the command for consistency.

Rough placement in the header:

```tsx
<div className="flex items-center justify-between">
<span className="text-xs font-medium text-muted-foreground uppercase">
{format(date, 'EEE')}
</span>
<div className="flex items-center gap-1">
{isCurrentDay && onMoveIncompleteToToday && (
<Button variant="ghost" size="icon" className="size-6" onClick={onMoveIncompleteToToday}>
<CalendarArrowUp className="size-3.5" />
</Button>
)}
<span className={cn(/* existing date styles */)}>
{format(date, 'd')}
</span>
</div>
</div>
```

Add a tooltip for discoverability (the existing `Tooltip` component from shadcn/ui).

**File: `src/components/calendar/WeekCalendar.tsx`**

- Import `executeCommand` from the command registry and `commandContext` from `use-command-context`
- When rendering DayColumns, pass `onMoveIncompleteToToday` only for the today column:
```typescript
onMoveIncompleteToToday={isToday(day)
? () => executeCommand('move-incomplete-to-today', commandContext)
: undefined
}
```

This ensures the button triggers the exact same code path as the command palette and keyboard shortcut.

### Step 5: Quality checks

- Run `bun run check:all` to verify TypeScript, ESLint, Prettier, ast-grep, and Rust checks pass
- Manual testing against `dummy-demo-vault/` — the demo vault has tasks with various statuses and scheduled dates that should exercise the filtering logic
6 changes: 6 additions & 0 deletions tdn-desktop/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,12 @@
"commands.deleteTask.success": "Task deleted",
"commands.deleteTask.error": "Failed to delete task",

"commands.moveIncompleteToToday.label": "Move Incomplete Tasks to Today",
"commands.moveIncompleteToToday.description": "Reschedule all overdue incomplete tasks to today",
"commands.moveIncompleteToToday.success": "Moved {{count}} task(s) to today",
"commands.moveIncompleteToToday.noTasks": "No overdue tasks to reschedule",
"commands.moveIncompleteToToday.error": "Failed to reschedule tasks",

"commands.editScheduledDate.label": "Edit Scheduled Date",
"commands.editScheduledDate.description": "Open the scheduled date picker",
"commands.editDueDate.label": "Edit Due Date",
Expand Down
46 changes: 36 additions & 10 deletions tdn-desktop/src/components/calendar/DayColumn.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { useDroppable } from '@dnd-kit/core'
import { SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable'
import { format, isToday, isWeekend } from 'date-fns'
import { Flag, Plus } from 'lucide-react'
import { CalendarArrowUp, Flag, Plus } from 'lucide-react'
import { useTranslation } from 'react-i18next'

import { cn } from '@/lib/utils'
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from '@/components/ui/tooltip'
import type { Task, TaskStatus } from '@/lib/tauri-bindings'
import { getCalendarTaskDragId } from '@/types/calendar-order'
import { SortableTaskCard } from './DraggableTaskCard'
Expand Down Expand Up @@ -48,6 +54,8 @@ interface DayColumnProps {
onTaskContextMenu?: (task: Task) => void
/** Called when + button is clicked to create a task */
onCreateTask?: () => void
/** Called when the "move incomplete to today" button is clicked (only shown for today) */
onMoveIncompleteToToday?: () => void
/** ID of task currently being edited (for auto-focus) */
editingTaskId?: string | null
/** Whether this column is being dragged over */
Expand All @@ -73,9 +81,11 @@ export function DayColumn({
onNavigateToArea,
onTaskContextMenu,
onCreateTask,
onMoveIncompleteToToday,
editingTaskId,
isDropTarget = false,
}: DayColumnProps) {
const { t } = useTranslation()
const dateString = format(date, 'yyyy-MM-dd')
const isCurrentDay = isToday(date)
const isWeekendDay = isWeekend(date)
Expand Down Expand Up @@ -108,16 +118,32 @@ export function DayColumn({
<span className="text-xs font-medium text-muted-foreground uppercase">
{format(date, 'EEE')}
</span>
<span
className={cn(
'size-6 flex items-center justify-center text-sm font-semibold tabular-nums rounded-full',
isCurrentDay
? 'bg-primary text-primary-foreground'
: 'bg-transparent'
<div className="flex items-center gap-1">
{isCurrentDay && onMoveIncompleteToToday && (
<Tooltip>
<TooltipTrigger
onClick={onMoveIncompleteToToday}
aria-label={t('commands.moveIncompleteToToday.label')}
className="size-6 flex items-center justify-center rounded-full text-muted-foreground hover:text-foreground hover:bg-muted/50 transition-colors"
>
<CalendarArrowUp className="size-3.5" />
</TooltipTrigger>
<TooltipContent>
{t('commands.moveIncompleteToToday.label')}
</TooltipContent>
Comment thread
coderabbitai[bot] marked this conversation as resolved.
</Tooltip>
)}
>
{format(date, 'd')}
</span>
<span
className={cn(
'size-6 flex items-center justify-center text-sm font-semibold tabular-nums rounded-full',
isCurrentDay
? 'bg-primary text-primary-foreground'
: 'bg-transparent'
)}
>
{format(date, 'd')}
</span>
</div>
</div>
</div>

Expand Down
11 changes: 11 additions & 0 deletions tdn-desktop/src/components/calendar/WeekCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
} from 'date-fns'
import { ChevronLeft, ChevronRight } from 'lucide-react'

import { executeCommand } from '@/lib/commands/registry'
import { commandContext } from '@/hooks/use-command-context'
import { cn } from '@/lib/utils'
import type { Task, TaskStatus } from '@/lib/tauri-bindings'
import { useCalendarOrder } from '@/hooks/use-calendar-order'
Expand Down Expand Up @@ -332,6 +334,15 @@ export function WeekCalendar({
onCreateTask={
onCreateTask ? () => handleCreateTask(dateKey) : undefined
}
onMoveIncompleteToToday={
isToday(day)
? () =>
executeCommand(
'move-incomplete-to-today',
commandContext
)
: undefined
}
editingTaskId={editingTaskId}
isDropTarget={isDropTarget}
/>
Expand Down
4 changes: 4 additions & 0 deletions tdn-desktop/src/hooks/use-command-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ export const commandContext: CommandContext = {
canGoForward: () => useNavigationStore.getState().canGoForward(),

// Data access (reads from TanStack Query cache)
getTasks: () => {
const tasks = queryClient.getQueryData<Task[]>(vaultQueryKeys.tasks())
return tasks ?? []
},
getAreas: () => {
const areas = queryClient.getQueryData<Area[]>(vaultQueryKeys.areas())
return areas ?? []
Expand Down
1 change: 1 addition & 0 deletions tdn-desktop/src/hooks/use-global-shortcuts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('useGlobalShortcuts', () => {
navigateToArea: vi.fn(),
navigateToProject: vi.fn(),
navigateToNoArea: vi.fn(),
getTasks: vi.fn(() => []),
goBack: vi.fn(),
goForward: vi.fn(),
canGoBack: vi.fn(() => false),
Expand Down
Loading