Fix Task Board Filters and Counters
Medium
Users report that the task board application exhibits several bugs when adding tasks, switching status filters, and maintaining the task counter accurate.
Requirements
- Display the count of currently visible tasks inside the element with data-testid
task-counterin the formatShowing X tasks(orShowing 1 taskwhen exactly 1 task is visible). - The list of tasks should display items fetched from
/api/tasksupon initial page load. - Submitting the task form with a non-empty title adds a new task with status
pendingto the list. Clear the input field after adding. - If submitting an empty or whitespace-only task title, display an error message
Task title cannot be emptyin the form's error container with classerror-messageand do not add a task. - Clicking status filter buttons (
All,Pending,Completed) filters the displayed tasks accordingly. The active filter button must have the classactiveand aria-pressed attribute set totrue. - Toggling a task's checkbox updates its completed state, updates the filter view if a specific filter is active, and recalculates the counter accurately.
- Deleting a task removes it from the list and updates the counter immediately.
Reported bugs
- When switching filters (e.g. to
Pending), checking off a pending task keeps it displayed until the filter tab is re-clicked, and the task counter shows the wrong count. - When adding a new task while a filter like
Completedis active, the newly created task (which is pending) immediately appears in the list even though the active filter is set toCompleted. - Attempting to add an empty task shows no validation error, and clearing invalid text after an error retains the old error message.
The setup
HTML, CSS & JSJavaScriptPlain CSSFix the bugEnd-to-end
The app is complete but has bugs in it. Find and fix them without rewriting what works.
- index.html
- styles.css
- script.js
The preview has no network. fetch is answered by this problem's API:
- GET /api/tasks
Follow-up: How would you persist local updates back to the backend API with optimistic updates and rollback on failure?
Constraints:
You may edit index.html, styles.css, and script.js. Ensure accessibility attributes (aria-pressed on filters, semantic labels) are preserved.
- Views
- 1