2020-08-17 21:07:16 +01:00
|
|
|
import React from 'react'
|
2020-08-17 21:59:29 +01:00
|
|
|
import PropTypes from 'prop-types'
|
2020-08-17 21:39:25 +01:00
|
|
|
import { connect } from 'react-redux'
|
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-05-01 06:50:27 +01:00
|
|
|
import ModalBase from './modal_base'
|
2020-07-21 22:48:55 +01:00
|
|
|
import BundleErrorModal from './bundle_error_modal'
|
|
|
|
import LoadingModal from './loading_modal'
|
2020-02-28 15:20:47 +00:00
|
|
|
import {
|
2020-12-16 07:39:07 +00:00
|
|
|
MODAL_ALBUM_CREATE,
|
2020-04-28 06:33:58 +01:00
|
|
|
MODAL_BLOCK_ACCOUNT,
|
2020-12-16 07:39:07 +00:00
|
|
|
MODAL_BOOKMARK_COLLECTION_CREATE,
|
2020-04-28 06:33:58 +01:00
|
|
|
MODAL_BOOST,
|
2020-12-03 04:22:51 +00:00
|
|
|
MODAL_CHAT_CONVERSATION_CREATE,
|
|
|
|
MODAL_CHAT_CONVERSATION_DELETE,
|
2020-04-28 06:33:58 +01:00
|
|
|
MODAL_COMPOSE,
|
|
|
|
MODAL_CONFIRM,
|
2020-12-08 05:07:04 +00:00
|
|
|
MODAL_DECK_COLUMN_ADD,
|
2020-12-16 00:31:30 +00:00
|
|
|
MODAL_DECK_COLUMN_ADD_OPTIONS,
|
2020-04-28 06:33:58 +01:00
|
|
|
MODAL_DISPLAY_OPTIONS,
|
|
|
|
MODAL_EDIT_PROFILE,
|
2020-07-22 04:25:20 +01:00
|
|
|
MODAL_EDIT_SHORTCUTS,
|
2020-10-16 22:25:37 +01:00
|
|
|
MODAL_EMAIL_CONFIRMATION_REMINDER,
|
2020-04-28 06:33:58 +01:00
|
|
|
MODAL_GROUP_CREATE,
|
|
|
|
MODAL_GROUP_DELETE,
|
2020-09-11 23:27:00 +01:00
|
|
|
MODAL_GROUP_PASSWORD,
|
2020-04-28 06:33:58 +01:00
|
|
|
MODAL_HOME_TIMELINE_SETTINGS,
|
|
|
|
MODAL_HOTKEYS,
|
2020-06-16 03:38:56 +01:00
|
|
|
MODAL_LIST_ADD_USER,
|
2020-04-28 06:33:58 +01:00
|
|
|
MODAL_LIST_CREATE,
|
|
|
|
MODAL_LIST_DELETE,
|
|
|
|
MODAL_LIST_EDITOR,
|
|
|
|
MODAL_LIST_TIMELINE_SETTINGS,
|
|
|
|
MODAL_MEDIA,
|
|
|
|
MODAL_MUTE,
|
|
|
|
MODAL_PRO_UPGRADE,
|
|
|
|
MODAL_REPORT,
|
2020-12-23 04:49:51 +00:00
|
|
|
MODAL_STATUS,
|
2020-05-03 06:22:49 +01:00
|
|
|
MODAL_STATUS_LIKES,
|
|
|
|
MODAL_STATUS_REPOSTS,
|
2020-04-28 06:33:58 +01:00
|
|
|
MODAL_STATUS_REVISIONS,
|
|
|
|
MODAL_UNAUTHORIZED,
|
|
|
|
MODAL_UNFOLLOW,
|
|
|
|
MODAL_VIDEO,
|
|
|
|
} from '../../constants'
|
|
|
|
import {
|
2020-12-16 07:39:07 +00:00
|
|
|
AlbumCreateModal,
|
2020-04-28 06:33:58 +01:00
|
|
|
BlockAccountModal,
|
2020-12-16 07:39:07 +00:00
|
|
|
BookmarkCollectionCreateModal,
|
2020-04-28 06:33:58 +01:00
|
|
|
BoostModal,
|
2020-12-03 04:22:51 +00:00
|
|
|
ChatConversationCreateModal,
|
|
|
|
ChatConversationDeleteModal,
|
2020-04-28 06:33:58 +01:00
|
|
|
ComposeModal,
|
|
|
|
ConfirmationModal,
|
2020-12-08 05:07:04 +00:00
|
|
|
DeckColumnAddModal,
|
2020-12-16 00:31:30 +00:00
|
|
|
DeckColumnAddOptionsModal,
|
2020-04-28 06:33:58 +01:00
|
|
|
DisplayOptionsModal,
|
|
|
|
EditProfileModal,
|
2020-07-22 04:25:20 +01:00
|
|
|
EditShortcutsModal,
|
2020-10-16 22:25:37 +01:00
|
|
|
EmailConfirmationReminderModal,
|
2020-04-28 06:33:58 +01:00
|
|
|
GroupCreateModal,
|
|
|
|
GroupDeleteModal,
|
2020-05-07 05:03:34 +01:00
|
|
|
GroupMembersModal,
|
2020-09-11 23:27:00 +01:00
|
|
|
GroupPasswordModal,
|
2020-05-07 06:55:24 +01:00
|
|
|
GroupRemovedAccountsModal,
|
2020-04-28 06:33:58 +01:00
|
|
|
HomeTimelineSettingsModal,
|
|
|
|
HotkeysModal,
|
2020-06-16 03:38:56 +01:00
|
|
|
ListAddUserModal,
|
2020-04-28 06:33:58 +01:00
|
|
|
ListCreateModal,
|
|
|
|
ListDeleteModal,
|
|
|
|
ListEditorModal,
|
|
|
|
ListTimelineSettingsModal,
|
|
|
|
MediaModal,
|
2020-02-28 15:20:47 +00:00
|
|
|
MuteModal,
|
2020-04-28 06:33:58 +01:00
|
|
|
ProUpgradeModal,
|
2020-02-28 15:20:47 +00:00
|
|
|
ReportModal,
|
2020-12-23 04:49:51 +00:00
|
|
|
StatusModal,
|
2020-05-03 06:22:49 +01:00
|
|
|
StatusLikesModal,
|
|
|
|
StatusRepostsModal,
|
2020-03-27 22:57:03 +00:00
|
|
|
StatusRevisionsModal,
|
2020-04-28 06:33:58 +01:00
|
|
|
UnauthorizedModal,
|
|
|
|
UnfollowModal,
|
|
|
|
VideoModal,
|
2020-03-25 03:08:43 +00:00
|
|
|
} from '../../features/ui/util/async_components'
|
2020-03-24 04:39:12 +00:00
|
|
|
|
2020-12-03 04:22:51 +00:00
|
|
|
const MODAL_COMPONENTS = {
|
2020-12-16 07:39:07 +00:00
|
|
|
[MODAL_ALBUM_CREATE]: AlbumCreateModal,
|
2020-12-03 04:22:51 +00:00
|
|
|
[MODAL_BLOCK_ACCOUNT]: BlockAccountModal,
|
2020-12-16 07:39:07 +00:00
|
|
|
[MODAL_BOOKMARK_COLLECTION_CREATE]: BookmarkCollectionCreateModal,
|
2020-12-03 04:22:51 +00:00
|
|
|
[MODAL_BOOST]: BoostModal,
|
|
|
|
[MODAL_CHAT_CONVERSATION_CREATE]: ChatConversationCreateModal,
|
|
|
|
[MODAL_CHAT_CONVERSATION_DELETE]: ChatConversationDeleteModal,
|
|
|
|
[MODAL_COMPOSE]: ComposeModal,
|
|
|
|
[MODAL_CONFIRM]: ConfirmationModal,
|
2020-12-08 05:07:04 +00:00
|
|
|
[MODAL_DECK_COLUMN_ADD]: DeckColumnAddModal,
|
2020-12-16 00:31:30 +00:00
|
|
|
[MODAL_DECK_COLUMN_ADD_OPTIONS]: DeckColumnAddOptionsModal,
|
2020-12-03 04:22:51 +00:00
|
|
|
[MODAL_DISPLAY_OPTIONS]: DisplayOptionsModal,
|
|
|
|
[MODAL_EDIT_SHORTCUTS]: EditShortcutsModal,
|
|
|
|
[MODAL_EDIT_PROFILE]: EditProfileModal,
|
|
|
|
[MODAL_EMAIL_CONFIRMATION_REMINDER]: EmailConfirmationReminderModal,
|
|
|
|
[MODAL_GROUP_CREATE]: GroupCreateModal,
|
|
|
|
[MODAL_GROUP_DELETE]: GroupDeleteModal,
|
|
|
|
[MODAL_GROUP_PASSWORD]: GroupPasswordModal,
|
|
|
|
[MODAL_HOME_TIMELINE_SETTINGS]: HomeTimelineSettingsModal,
|
|
|
|
[MODAL_HOTKEYS]: HotkeysModal,
|
|
|
|
[MODAL_LIST_ADD_USER]: ListAddUserModal,
|
|
|
|
[MODAL_LIST_CREATE]: ListCreateModal,
|
|
|
|
[MODAL_LIST_DELETE]: ListDeleteModal,
|
|
|
|
[MODAL_LIST_EDITOR]: ListEditorModal,
|
|
|
|
[MODAL_LIST_TIMELINE_SETTINGS]: ListTimelineSettingsModal,
|
|
|
|
[MODAL_MEDIA]: MediaModal,
|
|
|
|
[MODAL_MUTE]: MuteModal,
|
|
|
|
[MODAL_PRO_UPGRADE]: ProUpgradeModal,
|
|
|
|
[MODAL_REPORT]: ReportModal,
|
2020-12-23 04:49:51 +00:00
|
|
|
[MODAL_STATUS]: StatusModal,
|
2020-12-03 04:22:51 +00:00
|
|
|
[MODAL_STATUS_LIKES]: StatusLikesModal,
|
|
|
|
[MODAL_STATUS_REPOSTS]: StatusRepostsModal,
|
|
|
|
[MODAL_STATUS_REVISIONS]: StatusRevisionsModal,
|
|
|
|
[MODAL_UNAUTHORIZED]: UnauthorizedModal,
|
|
|
|
[MODAL_UNFOLLOW]: UnfollowModal,
|
|
|
|
[MODAL_VIDEO]: VideoModal,
|
|
|
|
}
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-05-14 21:45:39 +01:00
|
|
|
const CENTERED_XS_MODALS = [
|
|
|
|
MODAL_BLOCK_ACCOUNT,
|
|
|
|
MODAL_CONFIRM,
|
|
|
|
MODAL_GROUP_DELETE,
|
|
|
|
MODAL_LIST_DELETE,
|
|
|
|
MODAL_MUTE,
|
|
|
|
MODAL_UNAUTHORIZED,
|
|
|
|
MODAL_UNFOLLOW,
|
|
|
|
]
|
|
|
|
|
2020-08-17 21:07:16 +01:00
|
|
|
class ModalRoot extends React.PureComponent {
|
2019-07-02 08:10:25 +01:00
|
|
|
|
2020-03-24 04:39:12 +00:00
|
|
|
getSnapshotBeforeUpdate() {
|
2020-02-24 21:56:07 +00:00
|
|
|
return { visible: !!this.props.type }
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
2020-03-24 04:39:12 +00:00
|
|
|
componentDidUpdate(prevProps, prevState, { visible }) {
|
2019-07-02 08:10:25 +01:00
|
|
|
if (visible) {
|
2020-04-22 06:00:11 +01:00
|
|
|
document.body.classList.add(_s.overflowYHidden)
|
2019-07-02 08:10:25 +01:00
|
|
|
} else {
|
2020-04-22 06:00:11 +01:00
|
|
|
document.body.classList.remove(_s.overflowYHidden)
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-01 06:50:27 +01:00
|
|
|
renderLoading = () => {
|
2020-07-21 22:48:55 +01:00
|
|
|
return <LoadingModal />
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
2020-05-01 06:50:27 +01:00
|
|
|
renderError = () => {
|
2020-07-21 22:48:55 +01:00
|
|
|
return <BundleErrorModal {...this.props} onClose={this.onClickClose} />
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
onClickClose = () => {
|
2020-04-07 02:53:23 +01:00
|
|
|
this.props.onClose(this.props.type)
|
2019-07-02 08:10:25 +01:00
|
|
|
}
|
|
|
|
|
2020-03-24 04:39:12 +00: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-05-14 21:45:39 +01:00
|
|
|
<ModalBase
|
|
|
|
onClose={this.onClickClose}
|
|
|
|
isCenteredXS={CENTERED_XS_MODALS.indexOf(type) > -1}
|
|
|
|
type={type}
|
|
|
|
>
|
2020-02-24 21:56:07 +00:00
|
|
|
{
|
|
|
|
visible &&
|
|
|
|
<Bundle
|
|
|
|
fetchComponent={MODAL_COMPONENTS[type]}
|
2020-05-01 06:50:27 +01:00
|
|
|
loading={this.renderLoading}
|
2020-02-24 21:56:07 +00:00
|
|
|
error={this.renderError}
|
2020-07-21 22:48:55 +01:00
|
|
|
renderDelay={150}
|
2020-02-24 21:56:07 +00:00
|
|
|
>
|
|
|
|
{
|
2020-05-01 06:50:27 +01:00
|
|
|
(Component) => <Component {...props} onClose={this.onClickClose} />
|
2020-02-24 21:56:07 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2020-08-18 18:07:47 +01:00
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
type: state.getIn(['modal', 'modalType']),
|
|
|
|
props: state.getIn(['modal', 'modalProps'], {}),
|
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onClose(optionalType) {
|
|
|
|
if (optionalType === 'COMPOSE') {
|
|
|
|
dispatch(cancelReplyCompose())
|
|
|
|
}
|
|
|
|
|
|
|
|
dispatch(closeModal())
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
ModalRoot.propTypes = {
|
|
|
|
type: PropTypes.string,
|
|
|
|
props: PropTypes.object,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ModalRoot)
|