mirror of
https://github.com/Mintplex-Labs/anything-llm.git
synced 2024-11-19 12:40:09 +01:00
Feature/use escape key to close documents modal (#2222)
* Add ability to use Esc keypress to close modal for documents * move escape close to hook --------- Co-authored-by: Mr Simon C <iamontheinternet@yahoo.com>
This commit is contained in:
parent
7594841dac
commit
aa4c9533aa
@ -127,19 +127,32 @@ const ModalTabSwitcher = ({ selectedTab, setSelectedTab }) => {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export function useManageWorkspaceModal() {
|
export function useManageWorkspaceModal() {
|
||||||
const { user } = useUser();
|
const { user } = useUser();
|
||||||
const [showing, setShowing] = useState(false);
|
const [showing, setShowing] = useState(false);
|
||||||
|
|
||||||
const showModal = () => {
|
function showModal() {
|
||||||
if (user?.role !== "default") {
|
if (user?.role !== "default") {
|
||||||
setShowing(true);
|
setShowing(true);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
const hideModal = () => {
|
function hideModal() {
|
||||||
setShowing(false);
|
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 };
|
return { showing, showModal, hideModal };
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user