diff options
author | 2021-08-22 14:33:54 +0200 | |
---|---|---|
committer | 2021-08-29 15:35:49 +0200 | |
commit | 9f74c550927671f4ded301d0cf3e9d592716375c (patch) | |
tree | 6075bead5939bfb9c3b6137fc5ef865f088b57cb /components/Popup.js | |
parent | 71cc09db93ec9b079a30593e14ca57c98fdc94ac (diff) | |
download | my_apps-9f74c550927671f4ded301d0cf3e9d592716375c.tar.gz my_apps-9f74c550927671f4ded301d0cf3e9d592716375c.tar.bz2 my_apps-9f74c550927671f4ded301d0cf3e9d592716375c.zip |
settings
Diffstat (limited to 'components/Popup.js')
-rw-r--r-- | components/Popup.js | 38 |
1 files changed, 15 insertions, 23 deletions
diff --git a/components/Popup.js b/components/Popup.js index 911d2fa..3df11c5 100644 --- a/components/Popup.js +++ b/components/Popup.js @@ -1,32 +1,24 @@ -import React, {useState, useEffect} from 'react' +import React from 'react' +import usePopup from 'hooks/usePopup' -const Popup = ({popup}) => { - const [visible, setVisible] = useState(false) - const { - content = null, - time = null, - error = null, - yes = null, - no = null, - } = popup +const Popup = () => { + const {popupData: p} = usePopup() - useEffect(() => { - setVisible(true) - time && setTimeout(() => setVisible(false), time) - }, [popup]) + if (!p || !p.content) return null - if (!content) return null - - return visible ? ( - <div className={`window window--popup${error ? ' window--error' : ''}`}> - <div className="window__content--popup">{ content }</div> + return ( + <div className={`window window--popup${p.error ? ' window--error' : ''}`}> + <div className="window__content--popup">{p.content}</div> { - (yes || no) && (<div className="window__buttons--popup"> - {[yes, no].map(a => a && <input key={a.label} className='window__button' type="button" onClick={() => { setVisible(false); a.action() }} value={a.label} />)} - </div>) + (p.yes || p.no) && ( + <div className="window__buttons--popup"> + {[p.no, p.yes].map(a => a && <input key={a.label} className='window__button' type="button" onClick={async () => a.action()} value={a.label} />)} + </div> + ) } </div> - ) : null + ) } export default Popup + |