Skip to content

Commit

Permalink
fix(modals): crash when opening multiple modals
Browse files Browse the repository at this point in the history
resolve LN-Zap#2823
  • Loading branch information
korhaliv committed Sep 2, 2019
1 parent b1c7b8c commit c6ff0e2
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions renderer/components/ModalStack.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const ModalContent = ({ modalDefinitions, type, onClose, isAnimating }) => {
}

const props = { isAnimating, type }

const renderContent = () => (
<Modal onClose={onClose}>
{component ? React.createElement(component, props) : render(props)}
Expand All @@ -34,17 +33,6 @@ ModalContent.propTypes = {
type: PropTypes.string.isRequired,
}

/**
* hasContent - Checks whether any of the currently active modals are relevant to the current stack.
*
* @param {Array} modals array of currently active modals
* @param {object} modalDefinitions modal type to React component mapping
* @returns {boolean} true if any of the currently active modals are relevant to the current stack
*/
function hasContent(modals, modalDefinitions) {
return Boolean(modals.find(modal => modalDefinitions[modal.type]))
}

const getItems = item => item.id

/**
Expand All @@ -55,18 +43,18 @@ const getItems = item => item.id
*/
function ModalStack(props) {
const { modals, closeModal, modalDefinitions } = props
const doCloseModal = useCallback(() => closeModal(), [closeModal])
useOnKeydown('Escape', doCloseModal)
useOnKeydown('Escape', closeModal)
const [isAnimating, setIsAnimating] = useState(false)

const onStart = useCallback(() => setIsAnimating(true), [setIsAnimating])
const onRest = useCallback(() => setIsAnimating(false), [setIsAnimating])
const relevantModals = modals.filter(modal => modalDefinitions[modal.type])
return (
hasContent(modals, modalDefinitions) && (
Boolean(relevantModals.length) && (
<Transition
enter={{ opacity: 1, pointerEvents: 'auto' }}
from={{ opacity: 0, pointerEvents: 'auto' }}
items={modals}
items={relevantModals}
keys={getItems}
leave={{ opacity: 0, pointerEvents: 'none' }}
onRest={onRest}
Expand All @@ -80,7 +68,7 @@ function ModalStack(props) {
<ModalContent
isAnimating={isAnimating}
modalDefinitions={modalDefinitions}
onClose={doCloseModal}
onClose={() => closeModal(modal.id)}
type={modal.type}
/>
</Container>
Expand Down

0 comments on commit c6ff0e2

Please sign in to comment.