Skip to content

Commit ec2cec0

Browse files
committed
fix: update Tasks, tests, and tagSelector
1 parent 1ba860d commit ec2cec0

File tree

3 files changed

+17
-34
lines changed

3 files changed

+17
-34
lines changed

frontend/src/components/HomeComponents/Tasks/Tasks.tsx

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,6 @@ export const Tasks = (
608608
}
609609
};
610610

611-
// Handle removing a tag
612-
const handleRemoveTag = (tagToRemove: string) => {
613-
setNewTask({
614-
...newTask,
615-
tags: newTask.tags.filter((tag) => tag !== tagToRemove),
616-
});
617-
};
618-
619611
const sortWithOverdueOnTop = (tasks: Task[]) => {
620612
return [...tasks].sort((a, b) => {
621613
const aOverdue = a.status === 'pending' && isOverdue(a.due);
@@ -1050,28 +1042,6 @@ export const Tasks = (
10501042
/>
10511043
</div>
10521044
</div>
1053-
1054-
<div className="mt-2">
1055-
{newTask.tags.length > 0 && (
1056-
<div className="grid grid-cols-4 items-center">
1057-
<div> </div>
1058-
<div className="flex flex-wrap gap-2 col-span-3">
1059-
{newTask.tags.map((tag, index) => (
1060-
<Badge key={index}>
1061-
<span>{tag}</span>
1062-
<button
1063-
type="button"
1064-
className="ml-2 text-red-500"
1065-
onClick={() => handleRemoveTag(tag)}
1066-
>
1067-
1068-
</button>
1069-
</Badge>
1070-
))}
1071-
</div>
1072-
</div>
1073-
)}
1074-
</div>
10751045
</div>
10761046
<DialogFooter>
10771047
<Button

frontend/src/components/HomeComponents/Tasks/__tests__/Tasks.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,8 @@ describe('Tasks Component', () => {
230230
test('renders mocked TagSelector in Add Task dialog', async () => {
231231
render(<Tasks {...mockProps} />);
232232

233-
const addButton = screen.getAllByText('Add Task')[0];
233+
const addButton = screen.getByRole('button', { name: /add task/i });
234+
234235
fireEvent.click(addButton);
235236

236237
expect(await screen.findByTestId('mock-tag-selector')).toBeInTheDocument();

frontend/src/components/ui/tagSelector.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as React from 'react';
2-
import { Check, ChevronsUpDown, Plus } from 'lucide-react';
2+
import { Check, ChevronsUpDown, Plus, X } from 'lucide-react';
33

44
import { cn } from '@/components/utils/utils';
55
import { Button } from '@/components/ui/button';
@@ -53,6 +53,13 @@ export function TagSelector({
5353
onChange([...selected, tag]);
5454
}
5555
};
56+
57+
// Remove a tag when X inside the chip is clicked
58+
const removeTagInsideChip = (tag: string, e: React.MouseEvent) => {
59+
e.stopPropagation();
60+
onChange(selected.filter((t) => t !== tag));
61+
};
62+
5663
return (
5764
<>
5865
<Popover open={open} onOpenChange={setOpen}>
@@ -61,7 +68,7 @@ export function TagSelector({
6168
variant="outline"
6269
role="combobox"
6370
aria-expanded={open}
64-
className="w-full justify-between h-auto min-h-[40px]"
71+
className="w-full justify-between h-auto min-h-[40px] group"
6572
>
6673
<div className="flex flex-wrap gap-2 items-center">
6774
{selected.length === 0 ? (
@@ -70,9 +77,14 @@ export function TagSelector({
7077
selected.map((tag) => (
7178
<span
7279
key={tag}
73-
className="px-2 py-1 rounded-md bg-muted text-sm"
80+
className="px-2 py-1 rounded-md bg-muted text-sm flex items-center gap-1 hover:text-neutral-300
81+
group-hover:bg-black group-hover:text-muted-foreground transition-colors"
7482
>
7583
{tag}
84+
<X
85+
className="w-3 h-3 cursor-pointer hover:text-red-500"
86+
onClick={(e) => removeTagInsideChip(tag, e)}
87+
/>
7688
</span>
7789
))
7890
)}

0 commit comments

Comments
 (0)