Skip to content

Commit

Permalink
Feature/use escape key to close documents modal (#2222)
Browse files Browse the repository at this point in the history
* Add ability to use Esc keypress to close modal for documents

* move escape close to hook

---------

Co-authored-by: Mr Simon C <[email protected]>
  • Loading branch information
timothycarambat and MrSimonC authored Sep 4, 2024
1 parent 7594841 commit aa4c953
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions frontend/src/components/Modals/ManageWorkspace/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,32 @@ const ModalTabSwitcher = ({ selectedTab, setSelectedTab }) => {
</div>
);
};

export function useManageWorkspaceModal() {
const { user } = useUser();
const [showing, setShowing] = useState(false);

const showModal = () => {
function showModal() {
if (user?.role !== "default") {
setShowing(true);
}
};
}

const hideModal = () => {
function hideModal() {
setShowing(false);
};
}

useEffect(() => {
function onEscape(event) {
if (!showing || event.key !== "Escape") return;
setShowing(false);
}

document.addEventListener("keydown", onEscape);
return () => {
document.removeEventListener("keydown", onEscape);
};
}, [showing]);

return { showing, showModal, hideModal };
}

0 comments on commit aa4c953

Please sign in to comment.