From f84e3c9f2215489b0ae465b02664458527792e51 Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Mon, 5 Aug 2019 21:07:34 -0700 Subject: [PATCH] Clearer variable names --- .../server/files/FileDropdownMenu.tsx | 47 +++++++++---------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/resources/scripts/components/server/files/FileDropdownMenu.tsx b/resources/scripts/components/server/files/FileDropdownMenu.tsx index 6fc8a4b77..bc92c81b0 100644 --- a/resources/scripts/components/server/files/FileDropdownMenu.tsx +++ b/resources/scripts/components/server/files/FileDropdownMenu.tsx @@ -20,7 +20,7 @@ type ModalType = 'rename' | 'move'; export default ({ uuid }: { uuid: string }) => { const menu = createRef(); const menuButton = createRef(); - const [ visible, setVisible ] = useState(false); + const [ menuVisible, setMenuVisible ] = useState(false); const [ showSpinner, setShowSpinner ] = useState(false); const [ modal, setModal ] = useState(null); const [ posX, setPosX ] = useState(0); @@ -35,7 +35,7 @@ export default ({ uuid }: { uuid: string }) => { } const windowListener = (e: MouseEvent) => { - if (e.button === 2 || !visible || !menu.current) { + if (e.button === 2 || !menuVisible || !menu.current) { return; } @@ -44,7 +44,7 @@ export default ({ uuid }: { uuid: string }) => { } if (e.target !== menu.current && !menu.current.contains(e.target as Node)) { - setVisible(false); + setMenuVisible(false); } }; @@ -70,16 +70,16 @@ export default ({ uuid }: { uuid: string }) => { }; useEffect(() => { - visible + menuVisible ? document.addEventListener('click', windowListener) : document.removeEventListener('click', windowListener); - if (visible && menu.current) { + if (menuVisible && menu.current) { menu.current.setAttribute( 'style', `margin-top: -0.35rem; left: ${Math.round(posX - menu.current.clientWidth)}px`, ); } - }, [ visible ]); + }, [ menuVisible ]); useEffect(() => () => { document.removeEventListener('click', windowListener); @@ -92,34 +92,29 @@ export default ({ uuid }: { uuid: string }) => { className={'p-3 hover:text-white'} onClick={e => { e.preventDefault(); - setModal(null); - - if (!visible) { + if (!menuVisible) { setPosX(e.clientX); } - - setVisible(!visible); + setModal(null); + setMenuVisible(!menuVisible); }} > - {visible && - - { - setModal(null); - setVisible(false); - }} - /> - - - } + { + setModal(null); + setMenuVisible(false); + }} + /> + - +
setMenuVisible(false)} className={'absolute bg-white p-2 rounded border border-neutral-700 shadow-lg text-neutral-500 min-w-48'} >