2020-02-28 15:20:47 +00:00
|
|
|
import { closeModal } from '../../actions/modal'
|
|
|
|
import { cancelReplyCompose } from '../../actions/compose'
|
2020-02-24 21:56:07 +00:00
|
|
|
import Bundle from '../../features/ui/util/bundle'
|
2020-02-28 15:20:47 +00:00
|
|
|
import {
|
|
|
|
MuteModal,
|
|
|
|
ReportModal,
|
|
|
|
EmbedModal,
|
|
|
|
// ListEditor,
|
|
|
|
// ListAdder,
|
|
|
|
StatusRevisionModal,
|
|
|
|
} from '../../features/ui/util/async-components'
|
|
|
|
import ModalBase from './modal_base'
|
2020-02-24 21:56:07 +00:00
|
|
|
import BundleModalError from '../bundle_modal_error'
|
2020-02-24 23:25:55 +00:00
|
|
|
import ActionsModal from './actions_modal'
|
|
|
|
import MediaModal from './media_modal'
|
2020-02-28 15:20:47 +00:00
|
|
|
import VideoModal from './video_modal'
|
2020-02-24 23:25:55 +00:00
|
|
|
import BoostModal from './boost_modal'
|
|
|
|
import ConfirmationModal from './confirmation_modal'
|
|
|
|
import HotkeysModal from './hotkeys_modal'
|
|
|
|
import ComposeModal from './compose_modal'
|
|
|
|
import UnauthorizedModal from './unauthorized_modal'
|
|
|
|
import ProUpgradeModal from './pro_upgrade_modal'
|
|
|
|
import ModalLoading from './modal_loading'
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
const MODAL_COMPONENTS = {
|
2020-02-28 15:20:47 +00:00
|
|
|
'ACTIONS': () => Promise.resolve({ default: ActionsModal }),
|
2019-07-02 08:10:25 +01:00
|
|
|
'BOOST': () => Promise.resolve({ default: BoostModal }),
|
2020-02-28 15:20:47 +00:00
|
|
|
'COMPOSE': () => Promise.resolve({ default: ComposeModal }),
|
2019-07-02 08:10:25 +01:00
|
|
|
'CONFIRM': () => Promise.resolve({ default: ConfirmationModal }),
|
|
|
|
'EMBED': EmbedModal,
|
|
|
|
'HOTKEYS': () => Promise.resolve({ default: HotkeysModal }),
|
2020-02-28 15:20:47 +00:00
|
|
|
'MEDIA': () => Promise.resolve({ default: MediaModal }),
|
|
|
|
'MUTE': MuteModal,
|
|
|
|
'PRO_UPGRADE': () => Promise.resolve({ default: ProUpgradeModal }),
|
|
|
|
'REPORT': ReportModal,
|
2019-09-17 16:23:51 +01:00
|
|
|
'STATUS_REVISION': StatusRevisionModal,
|
2019-07-02 08:10:25 +01:00
|
|
|
'UNAUTHORIZED': () => Promise.resolve({ default: UnauthorizedModal }),
|
2020-02-28 15:20:47 +00:00
|
|
|
'VIDEO': () => Promise.resolve({ default: VideoModal }),
|
|
|
|
// 'LIST_EDITOR': ListEditor,
|
|
|
|
// 'LIST_ADDER': ListAdder,
|
|
|
|
// group create
|
|
|
|
// group members
|
2020-02-24 21:56:07 +00:00
|
|
|
}
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
const mapStateToProps = state => ({
|
|
|
|
type: state.get('modal').modalType,
|
|
|
|
props: state.get('modal').modalProps,
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onClose (optionalType) {
|
|
|
|
if (optionalType === 'COMPOSE') {
|
|
|
|
dispatch(cancelReplyCompose())
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(closeModal())
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
export default
|
|
|
|
@connect(mapStateToProps, mapDispatchToProps)
|
|
|
|
class ModalRoot extends PureComponent {
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
type: PropTypes.string,
|
|
|
|
props: PropTypes.object,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
2020-02-24 21:56:07 +00:00
|
|
|
}
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
getSnapshotBeforeUpdate () {
|
2020-02-24 21:56:07 +00:00
|
|
|
return { visible: !!this.props.type }
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps, prevState, { visible }) {
|
|
|
|
if (visible) {
|
2020-02-24 21:56:07 +00:00
|
|
|
document.body.classList.add('with-modals--active')
|
2019-07-02 08:10:25 +01:00
|
|
|
} else {
|
2020-02-24 21:56:07 +00:00
|
|
|
document.body.classList.remove('with-modals--active')
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
renderLoading = modalId => () => {
|
2020-02-24 21:56:07 +00:00
|
|
|
return ['MEDIA', 'VIDEO', 'BOOST', 'CONFIRM', 'ACTIONS'].indexOf(modalId) === -1 ? <ModalLoading /> : null
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
renderError = (props) => {
|
2020-02-24 21:56:07 +00:00
|
|
|
return <BundleModalError {...props} onClose={this.onClickClose} />
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onClickClose = () => {
|
2020-02-24 21:56:07 +00:00
|
|
|
const { onClose, type } = this.props
|
|
|
|
onClose(type)
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
2020-02-24 21:56:07 +00:00
|
|
|
const { type, props } = this.props
|
|
|
|
const visible = !!type
|
2019-07-02 08:10:25 +01:00
|
|
|
|
|
|
|
return (
|
2020-02-24 21:56:07 +00:00
|
|
|
<ModalBase onClose={this.onClickClose} type={type}>
|
|
|
|
{
|
|
|
|
visible &&
|
|
|
|
<Bundle
|
|
|
|
fetchComponent={MODAL_COMPONENTS[type]}
|
|
|
|
loading={this.renderLoading(type)}
|
|
|
|
error={this.renderError}
|
|
|
|
renderDelay={200}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
(SpecificComponent) => <SpecificComponent {...props} onClose={this.onClickClose} />
|
|
|
|
}
|
2019-08-07 06:02:36 +01:00
|
|
|
</Bundle>
|
2020-02-24 21:56:07 +00:00
|
|
|
}
|
|
|
|
</ModalBase>
|
|
|
|
)
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|