--- name: task-filter description: Provides comprehensive task filtering across three dimensions (Status, Priority, Due Date) with cumulative AND logic, localStorage persistence, and removable filter chips UI. Supports nine total filter options across the three categories. --- # Task Filter Skill ## Overview The task filter skill enables users to narrow down task lists using multiple filter criteria applied simultaneously. Filters are cumulative (AND logic), persist across sessions, and display as removable chips for easy management. ## When to Apply Apply this skill: - When user selects a filter option from filter controls - When displaying the current active filters as chips - When user removes a filter chip - When loading the app (to restore saved filter state) - When combining filters with search results - When filter state needs to persist to localStorage ## Filter Types and Options This skill defines **three filter types** with specific options: ### 1. Status Filter Four options to filter by task completion status: - **Not Started** - Tasks that haven't been begun - **In Progress** - Tasks currently being worked on - **Complete** - Finished tasks - **All** - No status filtering (shows all statuses) ```javascript const STATUS_OPTIONS = { NOT_STARTED: 'Not Started', IN_PROGRESS: 'In Progress', COMPLETE: 'Complete', ALL: 'All' }; ``` ### 2. Priority Filter Five options to filter by priority level: - **VERY IMPORTANT** - Highest priority tasks only - **HIGH** - High priority tasks only - **MEDIUM** - Medium priority tasks only - **LOW** - Low priority tasks only - **All** - No priority filtering (shows all priorities) ```javascript const PRIORITY_OPTIONS = { VERY_IMPORTANT: 'VERY IMPORTANT', HIGH: 'HIGH', MEDIUM: 'MEDIUM', LOW: 'LOW', ALL: 'All' }; ``` ### 3. Due Date Filter Five options to filter by temporal urgency: - **Overdue** - Tasks with past due dates - **Today** - Tasks due today (current date) - **This Week** - Tasks due within current calendar week - **This Month** - Tasks due within current calendar month - **All** - No due date filtering (shows all due dates) ```javascript const DUE_DATE_OPTIONS = { OVERDUE: 'Overdue', TODAY: 'Today', THIS_WEEK: 'This Week', THIS_MONTH: 'This Month', ALL: 'All' }; ``` ## Filter Combination Logic ### Cumulative AND Logic Multiple filters combine using **AND logic** - a task must match ALL active filters: ```javascript function applyFilters(tasks, filters) { return tasks.filter(task => { // Check status filter if (filters.status !== 'All' && task.status !== filters.status) { return false; } // Check priority filter if (filters.priority !== 'All' && task.priority !== filters.priority) { return false; } // Check due date filter if (filters.dueDate !== 'All' && !matchesDueDateFilter(task, filters.dueDate)) { return false; } return true; // Task matches all filters }); } ``` ### AND Logic Examples ```javascript // Example 1: Status + Priority filters // Filters: { status: 'In Progress', priority: 'HIGH', dueDate: 'All' } // Result: Only tasks that are BOTH "In Progress" AND "HIGH" priority // Example 2: All three filters // Filters: { status: 'Not Started', priority: 'VERY IMPORTANT', dueDate: 'Today' } // Result: Only tasks that are "Not Started" AND "VERY IMPORTANT" AND due "Today" // Example 3: Single filter // Filters: { status: 'Complete', priority: 'All', dueDate: 'All' } // Result: Only completed tasks (no priority or due date restrictions) ``` ### "All" Option Behavior Setting a filter to **"All"** clears that specific filter dimension: ```javascript // Before: { status: 'In Progress', priority: 'HIGH', dueDate: 'Today' } // User sets priority to "All" // After: { status: 'In Progress', priority: 'All', dueDate: 'Today' } // Effect: Shows In Progress tasks due Today, regardless of priority ``` ## Due Date Filter Logic ### Date Comparison Implementation ```javascript function matchesDueDateFilter(task, dueDateFilter) { if (!task.dueDate) return false; // Tasks without due dates excluded const taskDue = new Date(task.dueDate); const now = new Date(); now.setHours(0, 0, 0, 0); // Normalize to start of day switch (dueDateFilter) { case 'Overdue': return taskDue < now; case 'Today': const today = new Date(now); const tomorrow = new Date(now); tomorrow.setDate(tomorrow.getDate() + 1); return taskDue >= today && taskDue < tomorrow; case 'This Week': const weekStart = getStartOfWeek(now); const weekEnd = new Date(weekStart); weekEnd.setDate(weekEnd.getDate() + 7); return taskDue >= weekStart && taskDue < weekEnd; case 'This Month': const monthStart = new Date(now.getFullYear(), now.getMonth(), 1); const monthEnd = new Date(now.getFullYear(), now.getMonth() + 1, 1); return taskDue >= monthStart && taskDue < monthEnd; case 'All': return true; default: return true; } } function getStartOfWeek(date) { const day = date.getDay(); const diff = date.getDate() - day; // Sunday as start of week const startOfWeek = new Date(date); startOfWeek.setDate(diff); startOfWeek.setHours(0, 0, 0, 0); return startOfWeek; } ``` ### Due Date Examples ```javascript // Assume today is 2025-12-16 // Task due 2025-12-15 (yesterday) matchesDueDateFilter(task, 'Overdue'); // true matchesDueDateFilter(task, 'Today'); // false // Task due 2025-12-16 (today) matchesDueDateFilter(task, 'Overdue'); // false matchesDueDateFilter(task, 'Today'); // true matchesDueDateFilter(task, 'This Week'); // true // Task due 2025-12-18 (this week) matchesDueDateFilter(task, 'This Week'); // true matchesDueDateFilter(task, 'This Month'); // true // Task due 2025-12-28 (this month, but not this week) matchesDueDateFilter(task, 'This Week'); // false matchesDueDateFilter(task, 'This Month'); // true // Task with no due date matchesDueDateFilter(task, 'Overdue'); // false (excluded) matchesDueDateFilter(task, 'All'); // true ``` ## Filter Persistence ### localStorage Storage Filter state persists across browser sessions using localStorage: ```javascript const FILTER_STORAGE_KEY = 'todo-app-filters'; function saveFilters(filters) { try { localStorage.setItem(FILTER_STORAGE_KEY, JSON.stringify(filters)); } catch (error) { console.error('Failed to save filters:', error); } } function loadFilters() { try { const saved = localStorage.getItem(FILTER_STORAGE_KEY); if (saved) { return JSON.parse(saved); } } catch (error) { console.error('Failed to load filters:', error); } // Return default filters if none saved return { status: 'All', priority: 'All', dueDate: 'All' }; } function clearFilters() { try { localStorage.removeItem(FILTER_STORAGE_KEY); } catch (error) { console.error('Failed to clear filters:', error); } } ``` ### Persistence Behavior - **On filter change**: Save immediately to localStorage - **On app load**: Restore filters from localStorage - **On clear all**: Remove from localStorage and reset to defaults - **On logout**: Optionally clear filters (user preference) ## Filter Chips UI ### Active Filter Display Active filters display as removable chips above the task list: ```jsx function FilterChips({ filters, onRemoveFilter }) { const activeFilters = []; if (filters.status !== 'All') { activeFilters.push({ type: 'status', value: filters.status }); } if (filters.priority !== 'All') { activeFilters.push({ type: 'priority', value: filters.priority }); } if (filters.dueDate !== 'All') { activeFilters.push({ type: 'dueDate', value: filters.dueDate }); } if (activeFilters.length === 0) { return null; // No active filters } return (