Added promotions to redux and added selector for setting promotions if not PRO
• Added: - promotions to redux - selector for setting promotions if not PRO • Updated: - StatusList, SidebarPanelGroup to use promotions from redux
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { me, promotions } from '../initial_state'
|
||||
import { connect } from 'react-redux'
|
||||
import { me } from '../initial_state'
|
||||
import { getPromotions } from '../selectors'
|
||||
import Bundle from '../features/ui/util/bundle'
|
||||
import WrappedBundle from '../features/ui/util/wrapped_bundle'
|
||||
import {
|
||||
@@ -10,16 +12,20 @@ import {
|
||||
class SidebarPanelGroup extends React.PureComponent {
|
||||
|
||||
render() {
|
||||
const { layout, page } = this.props
|
||||
const {
|
||||
layout,
|
||||
page,
|
||||
promotions,
|
||||
} = this.props
|
||||
|
||||
if (Array.isArray(promotions) && Array.isArray(layout) && !!me) {
|
||||
if (!!promotions && promotions.count() > 0 && Array.isArray(layout) && !!me) {
|
||||
const sidebarPromotionPageId = `${page}.sidebar`
|
||||
const promotion = promotions.find(p => p.timeline_id === sidebarPromotionPageId)
|
||||
const promotion = promotions.find((p) => p.get('timeline_id') === sidebarPromotionPageId)
|
||||
|
||||
if (!!promotion) {
|
||||
const correctedPosition = promotion.position - 1 > layout.length ? layout.length - 1 : promotion.position
|
||||
const correctedPosition = promotion.get('position') - 1 > layout.length ? layout.length - 1 : promotion.get('position')
|
||||
if (!layout.find(p => p.key === 'status-promotion-panel')) {
|
||||
layout.splice(correctedPosition, 0, <WrappedBundle key='status-promotion-panel' component={StatusPromotionPanel} componentParams={{ statusId: promotion.status_id }} />)
|
||||
layout.splice(correctedPosition, 0, <WrappedBundle key='status-promotion-panel' component={StatusPromotionPanel} componentParams={{ statusId: promotion.get('status_id') }} />)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -56,10 +62,14 @@ class SidebarPanelGroup extends React.PureComponent {
|
||||
|
||||
}
|
||||
|
||||
const mapStateToProps = (state) => ({
|
||||
promotions: getPromotions()(state)
|
||||
})
|
||||
|
||||
SidebarPanelGroup.propTypes = {
|
||||
layout: PropTypes.array.isRequired,
|
||||
page: PropTypes.string.isRequired,
|
||||
promotion: PropTypes.object,
|
||||
}
|
||||
|
||||
export default SidebarPanelGroup
|
||||
export default connect(mapStateToProps)(SidebarPanelGroup)
|
||||
@@ -6,7 +6,8 @@ import ImmutablePropTypes from 'react-immutable-proptypes'
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component'
|
||||
import { createSelector } from 'reselect'
|
||||
import debounce from 'lodash.debounce'
|
||||
import { me, promotions } from '../initial_state'
|
||||
import { me } from '../initial_state'
|
||||
import { getPromotions } from '../selectors'
|
||||
import {
|
||||
TIMELINE_INJECTION_FEATURED_GROUPS,
|
||||
TIMELINE_INJECTION_GROUP_CATEGORIES,
|
||||
@@ -45,15 +46,16 @@ class StatusList extends ImmutablePureComponent {
|
||||
promotedStatuses,
|
||||
timelineId,
|
||||
statusIds,
|
||||
promotions,
|
||||
} = this.props
|
||||
|
||||
if (Array.isArray(promotions)) {
|
||||
promotions.forEach((promotionBlock) => {
|
||||
|
||||
if (!!promotions && promotions.count() > 0) {
|
||||
promotions.forEach((promotion) => {
|
||||
|
||||
if (promotionBlock.timeline_id === timelineId &&
|
||||
statusIds.count() >= promotionBlock.position &&
|
||||
!promotedStatuses[promotionBlock.status_id]) {
|
||||
onFetchStatus(promotionBlock.status_id)
|
||||
if (promotion.get('timeline_id') === timelineId &&
|
||||
statusIds.count() >= promotion.get('position') &&
|
||||
!promotedStatuses[promotion.get('status_id')]) {
|
||||
onFetchStatus(promotion.get('status_id'))
|
||||
}
|
||||
|
||||
})
|
||||
@@ -158,9 +160,12 @@ class StatusList extends ImmutablePureComponent {
|
||||
emptyMessage,
|
||||
onScrollToTop,
|
||||
onScroll,
|
||||
promotions,
|
||||
} = this.props
|
||||
const { fetchedContext, isRefreshing } = this.state
|
||||
|
||||
console.log("promotions:", promotions)
|
||||
|
||||
if (isPartial || (isLoading && statusIds.size === 0)) {
|
||||
return (
|
||||
<React.Fragment>
|
||||
@@ -200,13 +205,13 @@ class StatusList extends ImmutablePureComponent {
|
||||
/>
|
||||
)
|
||||
} else {
|
||||
if (Array.isArray(promotions)) {
|
||||
const promotionBlock = promotions.find(p => (p.position === i && p.timeline_id === timelineId))
|
||||
if (promotionBlock) {
|
||||
if (!!promotions && promotions.count() > 0) {
|
||||
const promotion = promotions.find((p) => (p.get('position') === i && p.get('timeline_id') === timelineId))
|
||||
if (promotion) {
|
||||
scrollableContent.push(
|
||||
<StatusContainer
|
||||
key={`promotion-${i}-${promotionBlock.status_id}`}
|
||||
id={promotionBlock.status_id}
|
||||
key={`promotion-${i}-${promotion.get('status_id')}`}
|
||||
id={promotion.get('status_id')}
|
||||
onMoveUp={this.handleMoveUp}
|
||||
onMoveDown={this.handleMoveDown}
|
||||
contextType={timelineId}
|
||||
@@ -340,21 +345,24 @@ const mapStateToProps = (state, { timelineId }) => {
|
||||
if (!timelineId) return {}
|
||||
|
||||
const getStatusIds = makeGetStatusIds()
|
||||
const promotions = getPromotions()(state)
|
||||
|
||||
const statusIds = getStatusIds(state, {
|
||||
type: timelineId.substring(0, 5) === 'group' ? 'group' : timelineId,
|
||||
id: timelineId
|
||||
})
|
||||
|
||||
const promotedStatuses = Array.isArray(promotions) ?
|
||||
promotions.map((block) => {
|
||||
const promotedStatuses = (!!promotions && promotions.count() > 0) ?
|
||||
promotions.map((promotion) => {
|
||||
const s = {}
|
||||
s[block.status_id] = state.getIn(['statuses', block.status_id])
|
||||
s[promotion.get('status_id')] = state.getIn(['statuses', promotion.get('status_id')])
|
||||
return s
|
||||
}) : []
|
||||
|
||||
|
||||
return {
|
||||
statusIds,
|
||||
promotions,
|
||||
promotedStatuses,
|
||||
isLoading: state.getIn(['timelines', timelineId, 'isLoading'], true),
|
||||
isPartial: state.getIn(['timelines', timelineId, 'isPartial'], false),
|
||||
|
||||
Reference in New Issue
Block a user