94 lines
2.5 KiB
JavaScript
Raw Normal View History

2020-04-28 01:33:58 -04:00
import {
POPOVER_CONTENT_WARNING,
POPOVER_DATE_PICKER,
POPOVER_EMOJI_PICKER,
POPOVER_GROUP_INFO,
2020-05-07 01:55:24 -04:00
POPOVER_GROUP_OPTIONS,
2020-04-28 01:33:58 -04:00
POPOVER_PROFILE_OPTIONS,
POPOVER_REPOST_OPTIONS,
POPOVER_SEARCH,
POPOVER_SIDEBAR_MORE,
POPOVER_STATUS_OPTIONS,
POPOVER_STATUS_SHARE,
POPOVER_STATUS_VISIBILITY,
POPOVER_USER_INFO,
} from '../../constants'
import {
ContentWarningPopover,
DatePickerPopover,
EmojiPickerPopover,
GroupInfoPopover,
2020-05-07 01:55:24 -04:00
GroupOptionsPopover,
2020-04-28 01:33:58 -04:00
ProfileOptionsPopover,
RepostOptionsPopover,
SearchPopover,
SidebarMorePopover,
StatusOptionsPopover,
StatusSharePopover,
StatusVisibilityPopover,
UserInfoPopover,
} from '../../features/ui/util/async_components'
2020-02-28 10:20:47 -05:00
import Bundle from '../../features/ui/util/bundle'
import PopoverBase from './popover_base'
2020-04-28 01:33:58 -04:00
const POPOVER_COMPONENTS = {}
POPOVER_COMPONENTS[POPOVER_CONTENT_WARNING] = ContentWarningPopover
POPOVER_COMPONENTS[POPOVER_DATE_PICKER] = DatePickerPopover
POPOVER_COMPONENTS[POPOVER_EMOJI_PICKER] = EmojiPickerPopover
POPOVER_COMPONENTS[POPOVER_GROUP_INFO] = GroupInfoPopover
2020-05-07 01:55:24 -04:00
POPOVER_COMPONENTS[POPOVER_GROUP_OPTIONS] = GroupOptionsPopover
2020-04-28 01:33:58 -04:00
POPOVER_COMPONENTS[POPOVER_PROFILE_OPTIONS] = ProfileOptionsPopover
POPOVER_COMPONENTS[POPOVER_REPOST_OPTIONS] = RepostOptionsPopover
POPOVER_COMPONENTS[POPOVER_SEARCH] = SearchPopover
POPOVER_COMPONENTS[POPOVER_SIDEBAR_MORE] = SidebarMorePopover
POPOVER_COMPONENTS[POPOVER_STATUS_OPTIONS] = StatusOptionsPopover
POPOVER_COMPONENTS[POPOVER_STATUS_SHARE] = StatusSharePopover
POPOVER_COMPONENTS[POPOVER_STATUS_VISIBILITY] = StatusVisibilityPopover
POPOVER_COMPONENTS[POPOVER_USER_INFO] = UserInfoPopover
2020-02-28 10:20:47 -05:00
2020-04-11 18:29:19 -04:00
const mapStateToProps = (state) => ({
2020-04-07 21:06:59 -04:00
type: state.getIn(['popover', 'popoverType']),
props: state.getIn(['popover', 'popoverProps'], {}),
2020-02-28 10:20:47 -05:00
})
export default
2020-05-01 01:50:27 -04:00
@connect(mapStateToProps)
2020-02-28 10:20:47 -05:00
class PopoverRoot extends PureComponent {
2020-04-07 21:06:59 -04:00
2020-02-28 10:20:47 -05:00
static propTypes = {
type: PropTypes.string,
props: PropTypes.object,
}
2020-05-01 01:50:27 -04:00
renderEmpty = () => {
return <div />
2020-02-28 10:20:47 -05:00
}
render() {
2020-04-23 02:13:29 -04:00
const { type, props } = this.props
2020-02-28 10:20:47 -05:00
const visible = !!type
return (
2020-03-11 19:56:18 -04:00
<PopoverBase
visible={visible}
2020-03-14 13:31:29 -04:00
innerRef={this.setRef}
2020-03-11 19:56:18 -04:00
{...props}
>
{
visible &&
<Bundle
fetchComponent={POPOVER_COMPONENTS[type]}
2020-05-01 01:50:27 -04:00
loading={this.renderEmpty}
error={this.renderEmpty}
2020-03-11 19:56:18 -04:00
renderDelay={200}
>
{
2020-04-28 01:33:58 -04:00
(Component) => <Component {...props} />
2020-03-11 19:56:18 -04:00
}
</Bundle>
}
</PopoverBase>
2020-02-28 10:20:47 -05:00
)
}
2020-04-07 21:06:59 -04:00
2020-02-28 10:20:47 -05:00
}