Skip to content

Conversation

@AnasMansy
Copy link
Contributor

for undo using "ctrl + z "

I've added support for undo using shortcuts implement undo functions.

function TodoApp(props: TodoAppProps) {
const { defaultItems = [], onChange } = props;
const [items, setItems] = useState<TodoItem[]>(defaultItems);
const [undo, setUndo] = useState<TodoItem[]>(defaultItems);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be an array right?
In this implementation undo will only work for single undo but multiple undo should also work.


};
const handleKeyPress = (event: any) => {
if (`${event.key}` == 'z' && `${event.key.control}`) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the function is misleading as keypress is another event. Also please use type for event instead of any.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i used " keyboardEvent" but throw error and shortcuts don't work
Type '(event: KeyboardEvent) => void' is not assignable to type 'EventListener'.
Types of parameters 'event' and 'evt' are incompatible.
Type 'Event' is missing the following properties from type 'KeyboardEvent': altKey, charCode, ctrlKey, code, and 15 more

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay. You can ignore the type issue. Please fix the undo behavier for a textfield and outside text field as mentioned in this comment.
#47 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kamalkishor1991 while focus on item undo work on text otherwise on multiple items
but i have problem when i passing props from todo to item
"i am not good with typscript"

@kamalkishor1991
Copy link
Contributor

@AnasMansy thanks for the pull request. Overall approach looks good to me.
I tested it also and noticed that in this implementation undo is working at a item level. This is a problem for user as the whole item disapare on pressing undo but user might want to just undo the text in the text field. Please refer to keep for the behavior.

I think we should store full item state in the undo stack and priodically push state into the stack on change and update the whole state from the stack on pressing undo.
We will have to also make sure that the stack history has max limit.

@shahanahmed86
Copy link
Contributor

@kamalkishor1991, I wonder if it's a duplicate one then should be closed. I think we have covered this functionality on this Pull Request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants