gab-social/app/javascript/gabsocial/components/modal/modal_root.js

173 lines
4.7 KiB
JavaScript
Raw Normal View History

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'
import BundleModalError from '../bundle_modal_error'
2020-02-28 15:20:47 +00:00
import {
2020-04-28 06:33:58 +01:00
MODAL_ACTIONS,
MODAL_BLOCK_ACCOUNT,
MODAL_BLOCK_DOMAIN,
MODAL_BOOST,
MODAL_COMMUNITY_TIMELINE_SETTINGS,
MODAL_COMPOSE,
MODAL_CONFIRM,
MODAL_DISPLAY_OPTIONS,
MODAL_EDIT_PROFILE,
MODAL_EMBED,
MODAL_GIF_PICKER,
MODAL_GROUP_CREATE,
MODAL_GROUP_DELETE,
MODAL_GROUP_EDITOR,
MODAL_HASHTAG_TIMELINE_SETTINGS,
MODAL_HOME_TIMELINE_SETTINGS,
MODAL_HOTKEYS,
MODAL_LIST_CREATE,
MODAL_LIST_DELETE,
MODAL_LIST_EDITOR,
MODAL_LIST_TIMELINE_SETTINGS,
MODAL_MEDIA,
MODAL_MUTE,
MODAL_PRO_UPGRADE,
MODAL_REPORT,
MODAL_STATUS_REVISIONS,
MODAL_UNAUTHORIZED,
MODAL_UNFOLLOW,
MODAL_VIDEO,
} from '../../constants'
import {
ActionsModal,
BlockAccountModal,
BlockDomainModal,
BoostModal,
CommunityTimelineSettingsModal,
ComposeModal,
ConfirmationModal,
DisplayOptionsModal,
EditProfileModal,
EmbedModal,
GifPickerModal,
GroupCreateModal,
GroupDeleteModal,
GroupEditorModal,
HashtagTimelineSettingsModal,
HomeTimelineSettingsModal,
HotkeysModal,
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-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-04-28 06:33:58 +01:00
const MODAL_COMPONENTS = {}
MODAL_COMPONENTS[MODAL_ACTIONS] = ActionsModal
MODAL_COMPONENTS[MODAL_BLOCK_ACCOUNT] = BlockAccountModal
MODAL_COMPONENTS[MODAL_BLOCK_DOMAIN] = BlockDomainModal
MODAL_COMPONENTS[MODAL_BOOST] = BoostModal
MODAL_COMPONENTS[MODAL_COMMUNITY_TIMELINE_SETTINGS] = CommunityTimelineSettingsModal
MODAL_COMPONENTS[MODAL_COMPOSE] = ComposeModal
MODAL_COMPONENTS[MODAL_CONFIRM] = ConfirmationModal
MODAL_COMPONENTS[MODAL_DISPLAY_OPTIONS] = DisplayOptionsModal
MODAL_COMPONENTS[MODAL_EDIT_PROFILE] = EditProfileModal
MODAL_COMPONENTS[MODAL_EMBED] = EmbedModal
MODAL_COMPONENTS[MODAL_GIF_PICKER] = GifPickerModal
MODAL_COMPONENTS[MODAL_GROUP_CREATE] = GroupCreateModal
MODAL_COMPONENTS[MODAL_GROUP_DELETE] = GroupDeleteModal
MODAL_COMPONENTS[MODAL_GROUP_EDITOR] = GroupEditorModal
MODAL_COMPONENTS[MODAL_HASHTAG_TIMELINE_SETTINGS] = HashtagTimelineSettingsModal
MODAL_COMPONENTS[MODAL_HOME_TIMELINE_SETTINGS] = HomeTimelineSettingsModal
MODAL_COMPONENTS[MODAL_HOTKEYS] = HotkeysModal
MODAL_COMPONENTS[MODAL_LIST_CREATE] = ListCreateModal
MODAL_COMPONENTS[MODAL_LIST_DELETE] = ListDeleteModal
MODAL_COMPONENTS[MODAL_LIST_EDITOR] = ListEditorModal
MODAL_COMPONENTS[MODAL_LIST_TIMELINE_SETTINGS] = ListTimelineSettingsModal
MODAL_COMPONENTS[MODAL_MEDIA] = MediaModal
MODAL_COMPONENTS[MODAL_MUTE] = MuteModal
MODAL_COMPONENTS[MODAL_PRO_UPGRADE] = ProUpgradeModal
MODAL_COMPONENTS[MODAL_REPORT] = ReportModal
MODAL_COMPONENTS[MODAL_STATUS_REVISIONS] = StatusRevisionsModal
MODAL_COMPONENTS[MODAL_UNAUTHORIZED] = UnauthorizedModal
MODAL_COMPONENTS[MODAL_UNFOLLOW] = UnfollowModal
MODAL_COMPONENTS[MODAL_VIDEO] = VideoModal
2019-07-02 08:10:25 +01:00
2020-04-11 23:29:19 +01:00
const mapStateToProps = (state) => ({
2020-04-08 02:06:59 +01:00
type: state.getIn(['modal', 'modalType']),
props: state.getIn(['modal', 'modalProps'], {}),
2020-02-28 15:20:47 +00:00
})
const mapDispatchToProps = (dispatch) => ({
2020-03-24 04:39:12 +00:00
onClose(optionalType) {
2020-02-28 15:20:47 +00:00
if (optionalType === 'COMPOSE') {
2020-03-24 04:39:12 +00:00
dispatch(cancelReplyCompose())
2020-02-28 15:20:47 +00:00
}
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
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 = () => {
return <ModalLoading />
2019-07-02 08:10:25 +01:00
}
2020-05-01 06:50:27 +01:00
renderError = () => {
return <BundleModalError {...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-02-24 21:56:07 +00:00
<ModalBase onClose={this.onClickClose} type={type}>
{
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}
renderDelay={200}
>
{
2020-05-01 06:50:27 +01:00
(Component) => <Component {...props} onClose={this.onClickClose} />
2020-02-24 21:56:07 +00:00
}
</Bundle>
2020-02-24 21:56:07 +00:00
}
</ModalBase>
)
2019-07-02 08:10:25 +01:00
}
}