FrontendInterviews.dev

Loading problem…

57. Todo List II

Medium•
Acceptance: 48.00%
•
🔓3/3 Pro unlocks today

This problem builds on todo-list. Complete that first, then load your solution to continue.

Build an enhanced Todo List component that extends the basic todo list with filtering, drag-and-drop reordering, and local storage persistence.

New Features

1. Filter Functionality

  • Filter todos by status: All / Active / Completed
  • Visual indication of active filter
  • Update count for each filter

2. Drag and Drop Reordering

  • Drag todos to reorder them
  • Visual feedback during drag
  • Maintain order after reorder

3. Local Storage Persistence

  • Save todos to localStorage
  • Load todos on component mount
  • Persist across page refreshes

4. Clear Completed

  • Button to remove all completed todos at once
  • Only show when there are completed todos

5. Enhanced Data Structure

interface Todo {
  id: number;
  text: string;
  completed: boolean;
  order: number; // For drag-drop ordering
}

type Filter = 'all' | 'active' | 'completed';

Constraints

  • Implement drag-and-drop using HTML5 Drag API or a library
  • Persist data to localStorage
  • Handle localStorage errors gracefully
  • Maintain filter state