Skip to content

Commit

Permalink
fix: Repair swapping footer pages
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSusa committed May 31, 2019
1 parent 6f0946e commit 1a889bd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,11 @@ function mapStateToProps({
pageTargets = [],
availableDrivers: { inputs = {}, outputs = {} } = {}
},
//sliders: { sliderList }
}) {
const pageTarget = pageTargets.find((item) => item.id === lastFocusedPage)
return {
lastFocusedPage,
isSettingsMode,
// sliderList,
pageTarget,
inputs,
outputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import Button from '@material-ui/core/Button'
import Tooltip from '@material-ui/core/Tooltip'
import { PAGE_TYPES } from '../../../reducers'
import PropTypes from 'prop-types'

export function DriverEmtpyRedirectButton({
i,
Expand All @@ -12,7 +13,7 @@ export function DriverEmtpyRedirectButton({
<Button
onClick={() => {
toggleSettingsDialogMode({
i: i,
i,
isSettingsDialogMode: false,
})
togglePage({
Expand All @@ -25,3 +26,8 @@ export function DriverEmtpyRedirectButton({
</Tooltip>
)
}

DriverEmtpyRedirectButton.propTypes = {
i: PropTypes.string,
actions: PropTypes.object
}
20 changes: 8 additions & 12 deletions packages/midi-bricks/src/reducers/view-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,20 +221,20 @@ export const viewSettings = {
})
},

// TODO: REPAIR
[ActionTypeViewSettings.SWAP_FOOTER_PAGES](state, action) {
const { srcIdx, offset } = action.payload
const srcItem = state.footerPages[srcIdx]
const { srcIdx: srcI, offset } = action.payload
const srcItem = state.pageTargets.find(item => item.id === srcI)
const srcIdx = state.pageTargets.findIndex(item => item.id === srcI)
const newIdx =
srcIdx === 0 && offset === -1 ? state.footerPages.length : srcIdx
srcIdx === 0 && offset === -1 ? state.pageTargets.length : srcIdx
const targetIdx =
newIdx === state.footerPages.length - 1 && offset === 1
newIdx === state.pageTargets.length - 1 && offset === 1
? 0
: offset + newIdx
const otherItem = state.footerPages[targetIdx]
const otherItem = state.pageTargets[targetIdx]

let newArray = []
state.footerPages.forEach((item, idx) => {
state.pageTargets.forEach((item, idx) => {
if (idx === srcIdx) {
newArray.push(otherItem)
} else if (idx === targetIdx) {
Expand All @@ -245,7 +245,7 @@ export const viewSettings = {
})

return Object.assign({}, state, {
footerPages: newArray
pageTargets: newArray
})
},
[ActionTypeViewSettings.TOGGLE_SETTINGS_DIALOG_MODE](state, action) {
Expand Down Expand Up @@ -312,10 +312,6 @@ export const viewSettings = {
}
}

// return {
// ...state,
// availableDrivers
// }
return createNextState(state, (draftState) => {
draftState.availableDrivers = availableDrivers
return draftState
Expand Down

0 comments on commit 1a889bd

Please sign in to comment.