Fixed issue with promotions count checking in StatusList, SidebarPanelGroup

• Fixed:
- issue with promotions count checking in StatusList, SidebarPanelGroup
This commit is contained in:
mgabdev 2020-11-09 14:31:19 -06:00
parent 6f8a1c012d
commit 2649c19a50
3 changed files with 17 additions and 21 deletions

@ -18,14 +18,14 @@ class SidebarPanelGroup extends React.PureComponent {
promotions, promotions,
} = this.props } = this.props
if (!!promotions && promotions.count() > 0 && Array.isArray(layout) && !!me) { if (Array.isArray(promotions) && Array.isArray(layout) && !!me) {
const sidebarPromotionPageId = `${page}.sidebar` const sidebarPromotionPageId = `${page}.sidebar`
const promotion = promotions.find((p) => p.get('timeline_id') === sidebarPromotionPageId) const promotion = promotions.find((promotion) => promotion.timeline_id === sidebarPromotionPageId)
if (!!promotion) { if (!!promotion) {
const correctedPosition = promotion.get('position') - 1 > layout.length ? layout.length - 1 : promotion.get('position') const correctedPosition = promotion.position - 1 > layout.length ? layout.length - 1 : promotion.position
if (!layout.find(p => p.key === 'status-promotion-panel')) { if (!layout.find(p => p.key === 'status-promotion-panel')) {
layout.splice(correctedPosition, 0, <WrappedBundle key='status-promotion-panel' component={StatusPromotionPanel} componentParams={{ statusId: promotion.get('status_id') }} />) layout.splice(correctedPosition, 0, <WrappedBundle key='status-promotion-panel' component={StatusPromotionPanel} componentParams={{ statusId: promotion.status_id }} />)
} }
} }
} }

@ -49,13 +49,13 @@ class StatusList extends ImmutablePureComponent {
promotions, promotions,
} = this.props } = this.props
if (!!promotions && promotions.count() > 0) { if (Array.isArray(promotions)) {
promotions.forEach((promotion) => { promotions.forEach((promotion) => {
if (promotion.get('timeline_id') === timelineId && if (promotion.timeline_id === timelineId &&
statusIds.count() >= promotion.get('position') && statusIds.count() >= promotion.position &&
!promotedStatuses[promotion.get('status_id')]) { !promotedStatuses[promotion.status_id]) {
onFetchStatus(promotion.get('status_id')) onFetchStatus(promotion.status_id)
} }
}) })
@ -203,13 +203,13 @@ class StatusList extends ImmutablePureComponent {
/> />
) )
} else { } else {
if (!!promotions && promotions.count() > 0) { if (Array.isArray(promotions)) {
const promotion = promotions.find((p) => (p.get('position') === i && p.get('timeline_id') === timelineId)) const promotion = promotions.find((promotion) => (promotion.position === i && promotion.timeline_id === timelineId))
if (promotion) { if (promotion) {
scrollableContent.push( scrollableContent.push(
<StatusContainer <StatusContainer
key={`promotion-${i}-${promotion.get('status_id')}`} key={`promotion-${i}-${promotion.status_id}`}
id={promotion.get('status_id')} id={promotion.status_id}
onMoveUp={this.handleMoveUp} onMoveUp={this.handleMoveUp}
onMoveDown={this.handleMoveDown} onMoveDown={this.handleMoveDown}
contextType={timelineId} contextType={timelineId}
@ -350,10 +350,10 @@ const mapStateToProps = (state, { timelineId }) => {
id: timelineId id: timelineId
}) })
const promotedStatuses = (!!promotions && promotions.count() > 0) ? const promotedStatuses = Array.isArray(promotions) ?
promotions.map((promotion) => { promotions.map((promotion) => {
const s = {} const s = {}
s[promotion.get('status_id')] = state.getIn(['statuses', promotion.get('status_id')]) s[promotion.status_id] = state.getIn(['statuses', promotion.status_id])
return s return s
}) : [] }) : []

@ -1,14 +1,10 @@
import {
List as ImmutableList,
fromJS,
}from 'immutable'
import { import {
PROMOTIONS_FETCH_REQUEST, PROMOTIONS_FETCH_REQUEST,
PROMOTIONS_FETCH_SUCCESS, PROMOTIONS_FETCH_SUCCESS,
PROMOTIONS_FETCH_FAIL, PROMOTIONS_FETCH_FAIL,
} from '../actions/promotions' } from '../actions/promotions'
const initialState = ImmutableList() const initialState = []
export default function promotions(state = initialState, action) { export default function promotions(state = initialState, action) {
switch (action.type) { switch (action.type) {
@ -16,7 +12,7 @@ export default function promotions(state = initialState, action) {
case PROMOTIONS_FETCH_FAIL: case PROMOTIONS_FETCH_FAIL:
return initialState return initialState
case PROMOTIONS_FETCH_SUCCESS: case PROMOTIONS_FETCH_SUCCESS:
return fromJS(action.items) return action.items
default: default:
return state return state
} }