mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2026-01-07 14:12:43 +00:00
Break Dialog out of NotificationPopup, restore NotificationPopup to original position
This commit is contained in:
48
client/components/dialog.jsx
Normal file
48
client/components/dialog.jsx
Normal file
@@ -0,0 +1,48 @@
|
||||
// Modal as a separate component
|
||||
const React = require('react');
|
||||
const { useState, useRef, useEffect } = React;
|
||||
|
||||
function Modal({ dismissKey, blocking, children, ...rest }) {
|
||||
const ref = useRef();
|
||||
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
useEffect(()=>{
|
||||
if(!window || !dismissKey) return;
|
||||
if(!localStorage.getItem(dismissKey)){
|
||||
setOpen(true);
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(()=>{
|
||||
if(blocking) {
|
||||
modal ? ref.current?.showModal() : ref.current?.show();
|
||||
} else {
|
||||
ref.current?.close();
|
||||
}
|
||||
}, [blocking]);
|
||||
|
||||
const dismiss = function(){
|
||||
localStorage.setItem(dismissKey, true);
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
if(!open) return;
|
||||
return (
|
||||
<dialog
|
||||
ref={ref}
|
||||
onCancel={()=>dismiss()}
|
||||
{...rest}
|
||||
>
|
||||
<button
|
||||
className='dismiss'
|
||||
onClick={()=>dismiss()}
|
||||
>
|
||||
Close
|
||||
</button>
|
||||
{children}
|
||||
</dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default Modal;
|
||||
Reference in New Issue
Block a user