2016-12-13 10:25:17 +00:00
|
|
|
( function ( popups, nextState ) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reducer for actions that modify the state of the settings
|
|
|
|
*
|
|
|
|
* @param {Object} state
|
|
|
|
* @param {Object} action
|
|
|
|
* @return {Object} state after action
|
|
|
|
*/
|
|
|
|
popups.reducers.settings = function ( state, action ) {
|
|
|
|
if ( state === undefined ) {
|
|
|
|
state = {
|
2016-12-13 18:04:03 +00:00
|
|
|
shouldShow: false,
|
|
|
|
showHelp: false
|
2016-12-13 10:25:17 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
switch ( action.type ) {
|
|
|
|
case popups.actionTypes.SETTINGS_SHOW:
|
|
|
|
return nextState( state, {
|
2016-12-13 18:04:03 +00:00
|
|
|
shouldShow: true,
|
|
|
|
showHelp: false
|
2016-12-13 10:25:17 +00:00
|
|
|
} );
|
|
|
|
case popups.actionTypes.SETTINGS_HIDE:
|
|
|
|
return nextState( state, {
|
2016-12-13 18:04:03 +00:00
|
|
|
shouldShow: false,
|
|
|
|
showHelp: false
|
2016-12-13 10:25:17 +00:00
|
|
|
} );
|
2016-12-13 18:04:03 +00:00
|
|
|
case popups.actionTypes.SETTINGS_CHANGE:
|
|
|
|
return action.wasEnabled === action.enabled ?
|
|
|
|
// If the setting is the same, just hide the dialogs
|
|
|
|
nextState( state, {
|
|
|
|
shouldShow: false
|
|
|
|
} ) :
|
|
|
|
// If the settings have changed...
|
|
|
|
nextState( state, {
|
|
|
|
// If we enabled, we just hide directly, no help
|
|
|
|
// If we disabled, keep it showing and let the ui show the help.
|
|
|
|
shouldShow: !action.enabled,
|
|
|
|
showHelp: !action.enabled
|
|
|
|
} );
|
2016-12-13 10:25:17 +00:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( mediaWiki.popups, mediaWiki.popups.nextState ) );
|