Skip to content

Commit

Permalink
fix: Persisting element settings changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TimSusa committed May 31, 2019
1 parent b3ec5f9 commit 70493ff
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function ChannelStripList(props) {
const classes = makeStyles(styles, { withTheme: true })()
const {
actions,
sliderList =[],
sliderList = [],
monitorVal: { driver = 'None', cC = 'None', channel = 'None' } = {},
viewSettings: {
pageType,
Expand All @@ -41,7 +41,8 @@ function ChannelStripList(props) {
isSettingsDialogMode = false,
// isLiveMode = false,
isMidiLearnMode = false,
lastFocusedIdxs=[],
lastFocusedIdxs = [],
lastFocusedPage,
rowHeight,
columns,
isAutoSize,
Expand Down Expand Up @@ -103,7 +104,10 @@ function ChannelStripList(props) {
e.stopPropagation()
}}
onClick={
!isLayoutMode && isSettingsMode && !isSettingsDialogMode && !lastFocusedIdxs.includes(i)
!isLayoutMode &&
isSettingsMode &&
!isSettingsDialogMode &&
!lastFocusedIdxs.includes(i)
? (e) => {
actions.setLastFocusedIndex({ i })
e.preventDefault()
Expand All @@ -123,9 +127,7 @@ function ChannelStripList(props) {
}
}
>
<SizeMe
monitorHeight
>
<SizeMe monitorHeight>
{({ size }) => {
return (
<div
Expand Down Expand Up @@ -183,7 +185,12 @@ function ChannelStripList(props) {
isFocused
)
}
toggleSettings={toggleSettings.bind(this, actions)}
toggleSettings={toggleSettings.bind(
this,
lastFocusedPage,
i,
actions
)}
sliderEntry={sliderEntry}
/>
</span>
Expand All @@ -202,22 +209,24 @@ function ChannelStripList(props) {
<Typography variant='h4' className={classes.noMidiTypography}>
<br />
<br />
Dear user,
I suggest for you to load an example preset.
Dear user, I suggest for you to load an example preset.
<br />
<br />
<Button
onClick={() =>
// TODO: use thunkLoadFile
props.actions.loadFile({ content: preset, presetName: 'APC-40 Preset' })
props.actions.loadFile({
content: preset,
presetName: 'APC-40 Preset'
})
}
>
LOAD EXAMPLE PRESET
</Button>
<br />
<br />
Otherwise, feel free to play arround and add a page or buttons.
You can do this with the button at the right top in the AppBar → ↑
Otherwise, feel free to play arround and add a page or buttons. You can
do this with the button at the right top in the AppBar → ↑
</Typography>
)
}
Expand Down Expand Up @@ -329,8 +338,8 @@ function styles(theme) {
}
}

function toggleSettings(actions, { isSettingsDialogMode }) {
actions.toggleSettingsDialogMode({ isSettingsDialogMode })
function toggleSettings(lastFocusedPage, i, actions, { isSettingsDialogMode }) {
actions.toggleSettingsDialogMode({ i, lastFocusedPage, isSettingsDialogMode })
}

function mapStateToProps({
Expand Down
3 changes: 2 additions & 1 deletion packages/midi-bricks/src/components/footer/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ function Footer(props) {
actions.setLastFocusedIndex({ i: '' })
actions.toggleSettingsDialogMode({
i: '',
isSettingsDialogMode: false
isSettingsDialogMode: false,
lastFocusedPage
})
}}
sliderEntry={pageTargets.find(
Expand Down
3 changes: 2 additions & 1 deletion packages/midi-bricks/src/components/footer/FooterButton.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export function FooterButton(props) {
actions.setLastFocusedPage({ lastFocusedPage: id })
actions.toggleSettingsDialogMode({
i: id,
isSettingsDialogMode: true
isSettingsDialogMode: true,
lastFocusedPage: id
})
}
: handleClick.bind(this, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function MidiSettings(props) {
classes={classes}
label={type === undefined ? pageTarget.label : label}
i={i}
lastFocusedPage={lastFocusedPage}
actions={actions}
type={type}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function DriverEmtpyRedirectButton({
toggleSettingsDialogMode({
i,
isSettingsDialogMode: false,
lastFocusedPage: i
})
togglePage({
pageType: PAGE_TYPES.MIDI_DRIVER_MODE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ MidiSettingsLabelInput.propTypes = {
export function MidiSettingsLabelInput({
label,
i,
lastFocusedPage,
classes,
actions,
type
Expand All @@ -30,25 +31,27 @@ export function MidiSettingsLabelInput({
type='label'
name={`input-label-name-${i}`}
value={label}
onChange={handleLabelChange.bind(this, i, actions, type)}
onChange={handleLabelChange.bind(this, lastFocusedPage, i, actions, type)}
autoFocus
/>
</FormControl>
)
}

function handleLabelChange(i, actions, type, e) {
function handleLabelChange(lastFocusedPage, i, actions, type, e) {
e.preventDefault()
e.stopPropagation()

if (type === undefined) {
actions.setPageTargetSettings({
label: e.target.value
label: e.target.value,
lastFocusedPage
})
} else {
actions.changeLabel({
i,
val: e.target.value
val: e.target.value,
lastFocusedPage
})
}
}
7 changes: 5 additions & 2 deletions packages/midi-bricks/src/pages/GlobalSettingsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function GlobalSettingsPage(props) {
sliderList,
viewSettings: {
isSettingsDialogMode,
lastFocusedPage,
lastFocusedIdx,
availableDrivers: { outputs: chosenOutputs, inputs: chosenInputs },
pageTargets
Expand Down Expand Up @@ -111,7 +112,8 @@ function GlobalSettingsPage(props) {
open
onClose={actions.toggleSettingsDialogMode.bind(this, {
i,
isSettingsDialogMode: false
isSettingsDialogMode: false,
lastFocusedPage
})}
sliderEntry={sliderEntry}
/>
Expand Down Expand Up @@ -204,7 +206,8 @@ function GlobalSettingsPage(props) {
actions.setLastFocusedIndex({ i })
actions.toggleSettingsDialogMode({
i,
isSettingsDialogMode: true
isSettingsDialogMode: true,
lastFocusedPage
})
}}
>
Expand Down
4 changes: 2 additions & 2 deletions packages/midi-bricks/src/reducers/view-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,10 @@ export const viewSettings = {
})
},
[ActionTypeViewSettings.TOGGLE_SETTINGS_DIALOG_MODE](state, action) {
const { isSettingsDialogMode, i } = action.payload
const { isSettingsDialogMode, i, lastFocusedPage } = action.payload
return createNextState(state, (draftState) => {
draftState.isSettingsDialogMode = isSettingsDialogMode
draftState.lastFocusedPage = i
draftState.lastFocusedPage = lastFocusedPage
draftState.lastFocusedIdx = i
return draftState
})
Expand Down

0 comments on commit 70493ff

Please sign in to comment.