Skip to content

Commit

Permalink
fix: Loading and saving new pages
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSusa committed May 11, 2019
1 parent 97b2f86 commit a8e28f2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 62 deletions.
20 changes: 13 additions & 7 deletions packages/midi-bricks/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async function onFileChange(
{ presetName, content },
e
) {
actions.deleteFooterPages()
actions.deleteAll()
window.localStorage.clear()

// will load content to slider-list-reducer
Expand All @@ -96,7 +96,7 @@ async function onFileChange(
const {
viewSettings = {},
viewSettings: { availableDrivers } = {},
sliders: { sliderList } = {}
sliders: { sliderList, pages } = {}
} = content
const drivers = availableDrivers || {
inputs: {
Expand All @@ -113,15 +113,21 @@ async function onFileChange(
}
}

// Either will will have pages or sliderList
if (pages) {
actions.updateViewSettings({
viewSettings: { ...viewSettings, availableDrivers: drivers },
pages
})
}
// Will load content to view-settings-reducer
sliderList && Array.isArray(sliderList)
? actions.updateViewSettings({
&& actions.updateViewSettings({
viewSettings: { ...viewSettings, availableDrivers: drivers },
sliderList: sliderList
})
: actions.updateViewSettings({
viewSettings: { ...viewSettings, availableDrivers: drivers }
sliderList: sliderList,
pages
})

await initApp()
actions.togglePage({
pageType: PAGE_TYPES.GLOBAL_MODE
Expand Down
4 changes: 2 additions & 2 deletions packages/midi-bricks/src/pages/GlobalSettingsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ function GlobalSettingsPage(props) {
const list = Object.values(pages) || sliderList
return list.map((thing, idx) => {
const { sliderList } = thing
const label = pageTargets[idx]&&pageTargets[idx].label || thing.label
const label = (pageTargets[idx] && pageTargets[idx].label) || thing.label
return (
<DriverExpansionPanel label={label} isEmpty={false}>
<DriverExpansionPanel label={label} isEmpty={false} key={`exp-${idx}`}>
<Paper style={{ flexDirection: 'column' }} className={classes.root}>
<Table className={classes.table}>
<TableHead>
Expand Down
99 changes: 46 additions & 53 deletions packages/midi-bricks/src/reducers/slider-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,30 +415,22 @@ export const reducers = {
// This is actuall only envolved in web app mode, not in electron mode
const {
viewSettings,
sliders: { sliderList = [], presetName }
sliders
} = action.payload

// Clean out older preset fields
const filteredSliderList = sliderList.map((entry) => ({
...entry,
midi: undefined
}))

const filteredFooterpageList = viewSettings.footerPages.map((item) => ({
...item,
midi: undefined
}))
// const filteredSliderList = sliderList.map((entry) => ({
// ...entry,
// midi: undefined
// }))

// const filteredFooterpageList = viewSettings.footerPages.map((item) => ({
// ...item,
// midi: undefined
// }))
const tmpFilterStore = {
viewSettings: {
...viewSettings,
footerPages: filteredFooterpageList
},
sliders: {
sliderList: filteredSliderList,
presetName,
sliderListBackup: [],
midi: undefined
}
viewSettings,
sliders
}
const content = JSON.stringify(tmpFilterStore)
const fileName = 'midi-bricks-preset.js'
Expand All @@ -448,49 +440,50 @@ export const reducers = {
a.href = URL.createObjectURL(file)
a.download = fileName
a.click()
return { ...state }
return state
},
[ActionTypeSliderList.LOAD_FILE](state, action) {
const {
payload: {
presetName,
content: { sliders: { sliderList: sliderListOld = [] } = {} } = {}
content: { sliders } = {}
} = {}
} = action

const sliderList =
(Array.isArray(sliderListOld) &&
sliderListOld.map((item) => {
const {
val = 0,
onVal = 127,
offVal = 0,
minVal = 0,
maxVal = 127,
driverName = 'None',
driverNameInput = 'None'
} = item

return {
...item,
lastSavedVal: val,
onVal,
offVal,
minVal,
maxVal,
midi: undefined,
outputId: undefined,
driverName,
driverNameInput
}
})) ||
[]
// const arr = Array.isArray(pages) && pages[0] || sliderListOld
// const sliderList =
// (
// arr.map((item) => {
// const {
// val = 0,
// onVal = 127,
// offVal = 0,
// minVal = 0,
// maxVal = 127,
// driverName = 'None',
// driverNameInput = 'None'
// } = item

// return {
// ...item,
// lastSavedVal: val,
// onVal,
// offVal,
// minVal,
// maxVal,
// midi: undefined,
// outputId: undefined,
// driverName,
// driverNameInput
// }
// })) ||
// []

return {
...state,
sliderList,
presetName,
sliderListBackup: sliderList
...sliders,
pages: sliders.pages,
presetName
//sliderListBackup: sliderList
}
},
[ActionTypeSliderList.CHANGE_LIST_ORDER](state, action) {
Expand Down

0 comments on commit a8e28f2

Please sign in to comment.