Skip to content

Commit c8dfcab

Browse files
feat: Enhance TagContext to collect unique tags from tasks and update tag state
1 parent 7630673 commit c8dfcab

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/context/TagContext.jsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { createContext, useState, useContext } from 'react';
1+
import React, { createContext, useState, useContext, useEffect } from 'react';
22
import { useTaskContext } from './TaskContext';
33

44
// Create the tag context
@@ -12,6 +12,25 @@ export const TagProvider = ({ children }) => {
1212
const [tags, setTags] = useState([]);
1313
const { tasks } = useTaskContext();
1414

15+
// Extract and collect all unique tags from tasks when tasks change
16+
useEffect(() => {
17+
const uniqueTags = new Set();
18+
19+
// Collect all tags from all tasks
20+
tasks.forEach(task => {
21+
if (task.tags && Array.isArray(task.tags)) {
22+
task.tags.forEach(tag => uniqueTags.add(tag));
23+
}
24+
});
25+
26+
// Add these to our existing tags (without duplicates)
27+
const updatedTags = Array.from(uniqueTags);
28+
setTags(prevTags => {
29+
const allTags = new Set([...prevTags, ...updatedTags]);
30+
return Array.from(allTags);
31+
});
32+
}, [tasks]);
33+
1534
const addTag = (tag) => {
1635
if (!tags.includes(tag)) {
1736
setTags([...tags, tag]);

src/features/lists/components/TaskBoard.jsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ function TaskBoard() {
113113
<div className="flex flex-wrap gap-4" data-testid="task-lists-container">
114114
{taskLists.map(list => {
115115
const filteredTasks = getFilteredTasks(list.filters, tasks);
116-
const hasCompletedTasks = filteredTasks.some(task => task.isCompleted);
116+
const completedTasksCount = filteredTasks.filter(task => task.isCompleted).length;
117+
const hasCompletedTasks = completedTasksCount > 0;
117118
const allTasksCompleted = filteredTasks.length > 0 && filteredTasks.every(task => task.isCompleted);
118119

119120
return (
@@ -132,7 +133,13 @@ function TaskBoard() {
132133
<>
133134
<div className="list-header p-4 border-b border-neutral-100 flex justify-between items-center">
134135
<h2 className="font-medium text-lg" data-testid={`list-title-${list.id}`}>{list.title}</h2>
135-
<div className="flex gap-2">
136+
<div className="flex items-center gap-2">
137+
<span
138+
className="text-xs font-medium text-neutral-500 bg-neutral-100 px-2 py-0.5 rounded"
139+
data-testid={`task-count-${list.id}`}
140+
>
141+
{completedTasksCount}/{filteredTasks.length}
142+
</span>
136143
<button
137144
type="button"
138145
className="text-sm text-neutral-500 hover:text-neutral-700 px-2 py-1 hover:bg-neutral-100 rounded"

0 commit comments

Comments
 (0)