0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-10 11:22:40 +00:00

Merge pull request #3885 from Gazook89/Fix-dialog.jsx

Fix Dialog.jsx to prevent crashes
This commit is contained in:
Trevor Buckner
2024-11-10 00:06:39 -05:00
committed by GitHub

View File

@@ -1,25 +1,25 @@
// Dialog box, for popups and modal blocking messages // Dialog box, for popups and modal blocking messages
import React from "react"; import React from 'react';
const { useRef, useEffect } = React; const { useRef, useEffect } = React;
function Dialog({ dismisskeys, closeText = 'Close', blocking = false, ...rest }) { function Dialog({ dismisskeys = [], closeText = 'Close', blocking = false, ...rest }) {
const dialogRef = useRef(null); const dialogRef = useRef(null);
useEffect(()=>{ useEffect(()=>{
if (dismisskeys.length !== 0) { if(dismisskeys.length !== 0) {
blocking ? dialogRef.current?.showModal() : dialogRef.current?.show(); blocking ? dialogRef.current?.showModal() : dialogRef.current?.show();
} }
}, [dialogRef.current, dismisskeys]); }, [dialogRef.current, dismisskeys]);
const dismiss = () => { const dismiss = ()=>{
dismisskeys.forEach(key => { dismisskeys.forEach((key)=>{
if (key) { if(key) {
localStorage.setItem(key, 'true'); localStorage.setItem(key, 'true');
} }
}); });
dialogRef.current?.close(); dialogRef.current?.close();
}; };
return ( return (
<dialog ref={dialogRef} onCancel={dismiss} {...rest}> <dialog ref={dialogRef} onCancel={dismiss} {...rest}>
{rest.children} {rest.children}