gab-social/app/javascript/gabsocial/components/popover/popover_root.js

91 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-04-28 06:33:58 +01:00
import {
POPOVER_CONTENT_WARNING,
POPOVER_DATE_PICKER,
POPOVER_EMOJI_PICKER,
POPOVER_GROUP_INFO,
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,
ProfileOptionsPopover,
RepostOptionsPopover,
SearchPopover,
SidebarMorePopover,
StatusOptionsPopover,
StatusSharePopover,
StatusVisibilityPopover,
UserInfoPopover,
} from '../../features/ui/util/async_components'
2020-02-28 15:20:47 +00:00
import Bundle from '../../features/ui/util/bundle'
import PopoverBase from './popover_base'
2020-04-28 06:33:58 +01: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
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 15:20:47 +00:00
2020-04-11 23:29:19 +01:00
const mapStateToProps = (state) => ({
2020-04-08 02:06:59 +01:00
type: state.getIn(['popover', 'popoverType']),
props: state.getIn(['popover', 'popoverProps'], {}),
2020-02-28 15:20:47 +00:00
})
export default
2020-05-01 06:50:27 +01:00
@connect(mapStateToProps)
2020-02-28 15:20:47 +00:00
class PopoverRoot extends PureComponent {
2020-04-08 02:06:59 +01:00
2020-02-28 15:20:47 +00:00
static propTypes = {
type: PropTypes.string,
props: PropTypes.object,
}
2020-05-01 06:50:27 +01:00
renderEmpty = () => {
return <div />
2020-02-28 15:20:47 +00:00
}
render() {
2020-04-23 07:13:29 +01:00
const { type, props } = this.props
2020-02-28 15:20:47 +00:00
const visible = !!type
return (
2020-03-11 23:56:18 +00:00
<PopoverBase
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-05-01 06:50:27 +01:00
loading={this.renderEmpty}
error={this.renderEmpty}
2020-03-11 23:56:18 +00:00
renderDelay={200}
>
{
2020-04-28 06:33:58 +01:00
(Component) => <Component {...props} />
2020-03-11 23:56:18 +00:00
}
</Bundle>
}
</PopoverBase>
2020-02-28 15:20:47 +00:00
)
}
2020-04-08 02:06:59 +01:00
2020-02-28 15:20:47 +00:00
}