Skip to content

Commit 2cec9ea

Browse files
refactor: ahora con click derecho puedo editar el nombre de la lista
1 parent dc1e5d5 commit 2cec9ea

2 files changed

Lines changed: 9 additions & 24 deletions

File tree

client/src/features/lists/components/ListItem.tsx

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const ListItem = ({ list }: ListItemProps) => {
2525
const [countTasks, setCountTasks] = useState(0);
2626
const [isFocused, setIsFocused] = useState(false);
2727
const { setOpen, setHandleDelete, setListTitle } = useAlertDialogStore();
28-
const [clickTimeout, setClickTimeout] = useState<NodeJS.Timeout | null>(null);
2928
const [listName, setListName] = useState(list.name);
3029
const [previousName, setPreviousName] = useState(list.name);
3130
const listNameDebounced = useDebounce(listName, 200);
@@ -84,28 +83,14 @@ const ListItem = ({ list }: ListItemProps) => {
8483
navigate(`/b/` + list.listId);
8584
};
8685

87-
const handleDoubleClick = () => {
86+
const handleContextMenu = (e: React.MouseEvent) => {
87+
e.preventDefault();
8888
if (isFocused) return;
8989
inputRef.current?.focus();
9090
inputRef.current?.setSelectionRange(-1, -1);
9191
setIsFocused(true);
9292
};
9393

94-
const handleClicks = () => {
95-
if (clickTimeout) {
96-
clearTimeout(clickTimeout);
97-
setClickTimeout(null);
98-
handleDoubleClick();
99-
} else {
100-
handleClick();
101-
setClickTimeout(
102-
setTimeout(() => {
103-
setClickTimeout(null);
104-
}, 200)
105-
);
106-
}
107-
};
108-
10994
useEffect(() => {
11095
setCountTasks(getTaskCount(list, tasks, listId));
11196
}, [list, listId, tasks]);
@@ -118,8 +103,9 @@ const ListItem = ({ list }: ListItemProps) => {
118103
return (
119104
<li
120105
tabIndex={0}
121-
onClick={handleClicks}
122-
onKeyDown={(e) => e.key === 'Enter' && handleClicks()}
106+
onClick={handleClick}
107+
onContextMenu={handleContextMenu}
108+
onKeyDown={(e) => e.key === 'Enter' && handleClick()}
123109
className={`relative w-full h-12 mx-auto mt-1 flex items-center justify-between text-neutral-500 dark:text-neutral-100
124110
bg-neutral-50 dark:bg-neutral-900 rounded-md hover:bg-black/10 dark:hover:bg-white/20
125111
transition-colors duration-200 select-none group

client/src/features/lists/tests/ListItem.test.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, it, expect, vi, beforeEach } from 'vitest';
2-
import { render, screen } from '@testing-library/react';
2+
import { render, screen, fireEvent } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import { useTaskStore } from '@/features/tasks/store/taskStore';
55
import ListItem from '@/features/lists/components/ListItem';
@@ -122,17 +122,16 @@ describe('ListItem', () => {
122122
it('renders list item with correct name', () => {
123123
expect(screen.getByText('Test List')).toBeInTheDocument();
124124
});
125-
it('shows input field on double click', async () => {
126-
const user = userEvent.setup();
125+
it('shows input field on right click', () => {
127126
const listItem = screen.getByText('Test List');
128-
await user.dblClick(listItem);
127+
fireEvent.contextMenu(listItem);
129128
const input = screen.getByDisplayValue('Test List');
130129
expect(input).toBeVisible();
131130
});
132131
it('updates list name on input change and blur', async () => {
133132
const user = userEvent.setup();
134133
const listItem = screen.getByText('Test List');
135-
await user.dblClick(listItem);
134+
fireEvent.contextMenu(listItem);
136135
const input = screen.getByDisplayValue('Test List');
137136
await user.clear(input);
138137
await user.type(input, 'Updated List Name');

0 commit comments

Comments
 (0)