From 27961983ec49779537c37a24534a880812a92124 Mon Sep 17 00:00:00 2001 From: Abhishek Kumar Date: Sun, 19 May 2024 01:23:33 +0530 Subject: [PATCH] Extract anchor element and associated controls into a separate hook Signed-off-by: Abhishek Kumar --- webapp/src/PlayPage/Word.tsx | 39 ++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/webapp/src/PlayPage/Word.tsx b/webapp/src/PlayPage/Word.tsx index c699cfb..24ed10c 100644 --- a/webapp/src/PlayPage/Word.tsx +++ b/webapp/src/PlayPage/Word.tsx @@ -15,25 +15,14 @@ import { updateWordEasinessFactor } from '../queries'; export default function Word({ wordText, wordScore }: WordProps) { const { color, setEF } = useWordColor(wordScore); - - const [anchorEl, setAnchorEl] = useState(null); - - const handleClick = (event: React.MouseEvent) => { - setAnchorEl(event.currentTarget); - }; - - const handleClose = () => { - setAnchorEl(null); - }; - - const open = Boolean(anchorEl); + const { anchorEl, isOpen, onOpen, onClose } = useAnchorEl(); return ( <> (null); + const isOpen = Boolean(anchorEl); + + const onOpen = (event: React.MouseEvent) => { + setAnchorEl(event.currentTarget); + }; + + const onClose = () => { + setAnchorEl(null); + }; + + return { + anchorEl, + isOpen, + onOpen, + onClose, + }; +} + interface WordPopoverProps { wordScore: CorrectedWordScoreType; setEF: (ef: number) => void;