-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #58 from Elizabethhub/fix-bug/modal-edit
Fix bug/modal edit
- Loading branch information
Showing
4 changed files
with
55 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { useDispatch } from 'react-redux'; | ||
import { changeModalClose } from '../store/water/waterSlice.js'; | ||
|
||
const useClickBackdrop = () => { | ||
const dispatch = useDispatch(); | ||
|
||
const clickBackdrop = (e) => { | ||
if (e.target === e.currentTarget) { | ||
dispatch(changeModalClose(false)); | ||
} | ||
}; | ||
|
||
return clickBackdrop; | ||
}; | ||
|
||
export default useClickBackdrop; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useEffect } from 'react'; | ||
import { useDispatch } from 'react-redux'; | ||
import { changeModalClose } from '../store/water/waterSlice'; | ||
|
||
const useKeyDown = () => { | ||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
const handleKeyDown = (e) => { | ||
if (e.key === 'Escape') { | ||
dispatch(changeModalClose(false)); | ||
} | ||
}; | ||
|
||
document.addEventListener('keydown', handleKeyDown); | ||
|
||
return () => { | ||
document.removeEventListener('keydown', handleKeyDown); | ||
}; | ||
}); | ||
}; | ||
|
||
export default useKeyDown; |