2020-04-28 06:33:58 +01:00
|
|
|
import {
|
2020-05-13 01:36:54 +01:00
|
|
|
BREAKPOINT_EXTRA_SMALL,
|
2020-12-17 06:34:00 +00:00
|
|
|
POPOVER_CHAT_CONVERSATION_EXPIRATION_OPTIONS,
|
2020-12-03 22:13:11 +00:00
|
|
|
POPOVER_CHAT_CONVERSATION_OPTIONS,
|
2020-12-16 00:31:30 +00:00
|
|
|
POPOVER_CHAT_MESSAGE_OPTIONS,
|
2020-12-20 17:27:24 +00:00
|
|
|
POPOVER_CHAT_SETTINGS,
|
2020-05-27 06:15:10 +01:00
|
|
|
POPOVER_COMMENT_SORTING_OPTIONS,
|
2020-12-16 00:31:30 +00:00
|
|
|
POPOVER_COMPOSE_POST_DESTINATION,
|
2020-04-28 06:33:58 +01:00
|
|
|
POPOVER_DATE_PICKER,
|
|
|
|
POPOVER_EMOJI_PICKER,
|
2020-07-25 03:41:05 +01:00
|
|
|
POPOVER_GROUP_LIST_SORT_OPTIONS,
|
2020-06-11 04:27:03 +01:00
|
|
|
POPOVER_GROUP_MEMBER_OPTIONS,
|
2020-05-07 06:55:24 +01:00
|
|
|
POPOVER_GROUP_OPTIONS,
|
2020-08-06 04:59:12 +01:00
|
|
|
POPOVER_GROUP_TIMELINE_SORT_OPTIONS,
|
|
|
|
POPOVER_GROUP_TIMELINE_SORT_TOP_OPTIONS,
|
2020-05-15 04:17:31 +01:00
|
|
|
POPOVER_NAV_SETTINGS,
|
2020-04-28 06:33:58 +01:00
|
|
|
POPOVER_PROFILE_OPTIONS,
|
|
|
|
POPOVER_SIDEBAR_MORE,
|
|
|
|
POPOVER_STATUS_OPTIONS,
|
2020-07-25 01:05:31 +01:00
|
|
|
POPOVER_STATUS_EXPIRATION_OPTIONS,
|
2020-12-24 18:27:55 +00:00
|
|
|
POPOVER_SHARE,
|
2020-04-28 06:33:58 +01:00
|
|
|
POPOVER_STATUS_VISIBILITY,
|
2020-09-14 17:40:42 +01:00
|
|
|
POPOVER_TIMELINE_INJECTION_OPTIONS,
|
2020-04-28 06:33:58 +01:00
|
|
|
POPOVER_USER_INFO,
|
2020-06-09 00:48:31 +01:00
|
|
|
POPOVER_VIDEO_STATS,
|
2020-04-28 06:33:58 +01:00
|
|
|
} from '../../constants'
|
|
|
|
import {
|
2020-12-17 06:34:00 +00:00
|
|
|
ChatConversationExpirationOptionsPopover,
|
2020-12-03 22:13:11 +00:00
|
|
|
ChatConversationOptionsPopover,
|
2020-12-16 00:31:30 +00:00
|
|
|
ChatMessageOptionsPopover,
|
2020-12-20 17:27:24 +00:00
|
|
|
ChatSettingsPopover,
|
2020-05-27 06:15:10 +01:00
|
|
|
CommentSortingOptionsPopover,
|
2020-12-16 00:31:30 +00:00
|
|
|
ComposePostDesinationPopover,
|
2020-04-28 06:33:58 +01:00
|
|
|
DatePickerPopover,
|
|
|
|
EmojiPickerPopover,
|
2020-07-25 03:41:05 +01:00
|
|
|
GroupListSortOptionsPopover,
|
2020-06-11 04:27:03 +01:00
|
|
|
GroupMemberOptionsPopover,
|
2020-05-07 06:55:24 +01:00
|
|
|
GroupOptionsPopover,
|
2020-08-06 04:59:12 +01:00
|
|
|
GroupTimelineSortOptionsPopover,
|
|
|
|
GroupTimelineSortTopOptionsPopover,
|
2020-05-15 04:17:31 +01:00
|
|
|
NavSettingsPopover,
|
2020-04-28 06:33:58 +01:00
|
|
|
ProfileOptionsPopover,
|
|
|
|
SidebarMorePopover,
|
2020-07-25 01:05:31 +01:00
|
|
|
StatusExpirationOptionsPopover,
|
2020-04-28 06:33:58 +01:00
|
|
|
StatusOptionsPopover,
|
2020-12-24 18:27:55 +00:00
|
|
|
SharePopover,
|
2020-04-28 06:33:58 +01:00
|
|
|
StatusVisibilityPopover,
|
2020-09-14 17:40:42 +01:00
|
|
|
TimelineInjectionOptionsPopover,
|
2020-04-28 06:33:58 +01:00
|
|
|
UserInfoPopover,
|
2020-06-09 00:48:31 +01:00
|
|
|
VideoStatsPopover,
|
2020-04-28 06:33:58 +01:00
|
|
|
} from '../../features/ui/util/async_components'
|
2020-05-13 01:36:54 +01:00
|
|
|
|
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-05-13 01:36:54 +01:00
|
|
|
import { closePopover } from '../../actions/popover'
|
2020-02-28 15:20:47 +00:00
|
|
|
import Bundle from '../../features/ui/util/bundle'
|
2020-05-13 01:36:54 +01:00
|
|
|
import ModalBase from '../modal/modal_base'
|
2020-02-28 15:20:47 +00:00
|
|
|
import PopoverBase from './popover_base'
|
2020-07-21 22:48:55 +01:00
|
|
|
import ErrorPopover from './error_popover'
|
|
|
|
import LoadingPopover from './loading_popover'
|
2020-02-28 15:20:47 +00:00
|
|
|
|
2020-12-03 22:13:11 +00:00
|
|
|
const POPOVER_COMPONENTS = {
|
2020-12-17 06:34:00 +00:00
|
|
|
[POPOVER_CHAT_CONVERSATION_EXPIRATION_OPTIONS]: ChatConversationExpirationOptionsPopover,
|
2020-12-03 22:13:11 +00:00
|
|
|
[POPOVER_CHAT_CONVERSATION_OPTIONS]: ChatConversationOptionsPopover,
|
2020-12-16 00:31:30 +00:00
|
|
|
[POPOVER_CHAT_MESSAGE_OPTIONS]: ChatMessageOptionsPopover,
|
2020-12-20 17:27:24 +00:00
|
|
|
[POPOVER_CHAT_SETTINGS]: ChatSettingsPopover,
|
2020-12-03 22:13:11 +00:00
|
|
|
[POPOVER_COMMENT_SORTING_OPTIONS]: CommentSortingOptionsPopover,
|
2020-12-16 00:31:30 +00:00
|
|
|
[POPOVER_COMPOSE_POST_DESTINATION]: ComposePostDesinationPopover,
|
2020-12-03 22:13:11 +00:00
|
|
|
[POPOVER_DATE_PICKER]: DatePickerPopover,
|
|
|
|
[POPOVER_EMOJI_PICKER]: EmojiPickerPopover,
|
|
|
|
[POPOVER_GROUP_LIST_SORT_OPTIONS]: GroupListSortOptionsPopover,
|
|
|
|
[POPOVER_GROUP_MEMBER_OPTIONS]: GroupMemberOptionsPopover,
|
|
|
|
[POPOVER_GROUP_OPTIONS]: GroupOptionsPopover,
|
|
|
|
[POPOVER_GROUP_TIMELINE_SORT_OPTIONS]: GroupTimelineSortOptionsPopover,
|
|
|
|
[POPOVER_GROUP_TIMELINE_SORT_TOP_OPTIONS]: GroupTimelineSortTopOptionsPopover,
|
|
|
|
[POPOVER_NAV_SETTINGS]: NavSettingsPopover,
|
|
|
|
[POPOVER_PROFILE_OPTIONS]: ProfileOptionsPopover,
|
|
|
|
[POPOVER_SIDEBAR_MORE]: SidebarMorePopover,
|
|
|
|
[POPOVER_STATUS_OPTIONS]: StatusOptionsPopover,
|
|
|
|
[POPOVER_STATUS_EXPIRATION_OPTIONS]: StatusExpirationOptionsPopover,
|
2020-12-24 18:27:55 +00:00
|
|
|
[POPOVER_SHARE]: SharePopover,
|
2020-12-03 22:13:11 +00:00
|
|
|
[POPOVER_STATUS_VISIBILITY]: StatusVisibilityPopover,
|
|
|
|
[POPOVER_TIMELINE_INJECTION_OPTIONS]: TimelineInjectionOptionsPopover,
|
|
|
|
[POPOVER_USER_INFO]: UserInfoPopover,
|
|
|
|
[POPOVER_VIDEO_STATS]: VideoStatsPopover,
|
|
|
|
}
|
2020-02-28 15:20:47 +00:00
|
|
|
|
2020-08-17 21:07:16 +01:00
|
|
|
class PopoverRoot extends React.PureComponent {
|
2020-04-08 02:06:59 +01:00
|
|
|
|
2020-05-14 07:03:22 +01:00
|
|
|
componentDidUpdate() {
|
2021-01-08 05:15:53 +00:00
|
|
|
const { type, width } = this.props
|
2020-05-14 07:03:22 +01:00
|
|
|
|
|
|
|
if (width <= BREAKPOINT_EXTRA_SMALL && !!type) {
|
|
|
|
document.body.classList.add(_s.overflowYHidden)
|
|
|
|
} else {
|
|
|
|
document.body.classList.remove(_s.overflowYHidden)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-21 22:48:55 +01:00
|
|
|
renderLoading = () => {
|
2021-01-08 05:15:53 +00:00
|
|
|
const { width } = this.props
|
2020-07-25 01:06:21 +01:00
|
|
|
const isXS = width <= BREAKPOINT_EXTRA_SMALL
|
|
|
|
|
|
|
|
return <LoadingPopover isXS={isXS} onClose={this.props.onClose} />
|
2020-07-21 22:48:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
renderError = () => {
|
2021-01-08 05:15:53 +00:00
|
|
|
const { width } = this.props
|
2020-07-25 01:06:21 +01:00
|
|
|
const isXS = width <= BREAKPOINT_EXTRA_SMALL
|
|
|
|
|
|
|
|
return <ErrorPopover isXS={isXS} onClose={this.props.onClose} />
|
2020-02-28 15:20:47 +00:00
|
|
|
}
|
|
|
|
|
2020-12-24 18:27:55 +00:00
|
|
|
setRef = () => {
|
|
|
|
// : todo : ?
|
|
|
|
}
|
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
render() {
|
2021-01-08 05:15:53 +00:00
|
|
|
const { type, props, onClose, width } = this.props
|
2020-05-13 01:36:54 +01:00
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
const visible = !!type
|
|
|
|
|
2020-05-13 01:36:54 +01:00
|
|
|
const isXS = width <= BREAKPOINT_EXTRA_SMALL
|
|
|
|
const Wrapper = isXS ? ModalBase : PopoverBase
|
|
|
|
|
2020-05-16 04:49:36 +01:00
|
|
|
//If is XS and popover is user info, dont show
|
|
|
|
//Since on mobile this should not be visible
|
|
|
|
if (isXS && type === POPOVER_USER_INFO) return null
|
|
|
|
|
2020-02-28 15:20:47 +00:00
|
|
|
return (
|
2020-05-13 01:36:54 +01:00
|
|
|
<Wrapper
|
|
|
|
onClose={onClose}
|
2020-03-11 23:56:18 +00:00
|
|
|
visible={visible}
|
2020-03-14 17:31:29 +00:00
|
|
|
innerRef={this.setRef}
|
2020-03-11 23:56:18 +00:00
|
|
|
{...props}
|
|
|
|
>
|
|
|
|
{
|
|
|
|
visible &&
|
|
|
|
<Bundle
|
|
|
|
fetchComponent={POPOVER_COMPONENTS[type]}
|
2020-07-21 22:48:55 +01:00
|
|
|
loading={this.renderLoading}
|
|
|
|
error={this.renderError}
|
|
|
|
renderDelay={150}
|
2020-03-11 23:56:18 +00:00
|
|
|
>
|
|
|
|
{
|
2020-12-20 17:27:24 +00:00
|
|
|
(Component) => <Component innerRef={this.setRef} isXS={isXS} onClose={onClose} {...props} />
|
2020-03-11 23:56:18 +00:00
|
|
|
}
|
|
|
|
</Bundle>
|
|
|
|
}
|
2020-05-13 01:36:54 +01:00
|
|
|
</Wrapper>
|
2020-02-28 15:20:47 +00:00
|
|
|
)
|
|
|
|
}
|
2020-04-08 02:06:59 +01:00
|
|
|
|
2020-08-19 01:22:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => ({
|
|
|
|
type: state.getIn(['popover', 'popoverType']),
|
|
|
|
props: state.getIn(['popover', 'popoverProps'], {}),
|
2021-01-08 05:15:53 +00:00
|
|
|
width: state.getIn(['settings', 'window_dimensions', 'width']),
|
2020-08-19 01:22:15 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
const mapDispatchToProps = (dispatch) => ({
|
|
|
|
onClose: (type) => dispatch(closePopover(type)),
|
|
|
|
})
|
|
|
|
|
|
|
|
PopoverRoot.propTypes = {
|
|
|
|
type: PropTypes.string,
|
|
|
|
props: PropTypes.object,
|
|
|
|
onClose: PropTypes.func.isRequired,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(PopoverRoot)
|