0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2025-12-30 00:12:56 +00:00

Tweak Dialog to work with showModal and show LockNotifications

This commit is contained in:
G.Ambatte
2024-06-06 12:01:55 +12:00
parent 0efcd5d258
commit 556ded9b08
3 changed files with 36 additions and 33 deletions

View File

@@ -8,18 +8,24 @@ function Dialog({ dismissKey, closeText = 'Close', blocking = false, ...rest })
useEffect(()=>{
if(!dismissKey || !localStorage.getItem(dismissKey)) {
blocking ? dialogRef.current?.showModal() : dialogRef.current?.show();
setOpen(true);
!open && setOpen(true);
}
}, []);
useEffect(()=>{
if(open && !dialogRef.current?.open){
blocking ? dialogRef.current?.showModal() : dialogRef.current?.show();
} else {
dialogRef.current?.close();
}
}, [open]);
const dismiss = ()=>{
dismissKey && localStorage.setItem(dismissKey, true);
dialogRef.current?.close();
setOpen(false);
};
if(!open) return null;
return (
<dialog ref={dialogRef} onCancel={dismiss} {...rest}>
<button className='dismiss' onClick={dismiss}>