2017-09-18 20:52:10 +00:00
|
|
|
/* @flow */
|
|
|
|
|
2017-09-18 15:58:03 +00:00
|
|
|
import { HIDE_DIALOG, OPEN_DIALOG } from './actionTypes';
|
2017-09-18 20:52:10 +00:00
|
|
|
import { isDialogOpen } from './functions';
|
2017-03-07 03:34:51 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals Dialog to close its dialog.
|
|
|
|
*
|
2017-09-18 20:52:10 +00:00
|
|
|
* @param {Object} [component] - The <tt>Dialog</tt> component to close/hide. If
|
|
|
|
* <tt>undefined</tt>, closes/hides <tt>Dialog</tt> regardless of which
|
|
|
|
* component it's rendering; otherwise, closes/hides <tt>Dialog</tt> only if
|
|
|
|
* it's rendering the specified <tt>component</tt>.
|
2017-03-07 03:34:51 +00:00
|
|
|
* @returns {{
|
2017-09-18 20:52:10 +00:00
|
|
|
* type: HIDE_DIALOG,
|
|
|
|
* component: (React.Component | undefined)
|
2017-03-07 03:34:51 +00:00
|
|
|
* }}
|
|
|
|
*/
|
2017-09-18 20:52:10 +00:00
|
|
|
export function hideDialog(component: ?Object) {
|
2017-03-07 03:34:51 +00:00
|
|
|
return {
|
2017-09-18 20:52:10 +00:00
|
|
|
type: HIDE_DIALOG,
|
|
|
|
component
|
2017-03-07 03:34:51 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals Dialog to open dialog.
|
|
|
|
*
|
|
|
|
* @param {Object} component - The component to display as dialog.
|
2017-09-18 15:58:03 +00:00
|
|
|
* @param {Object} [componentProps] - The React <tt>Component</tt> props of the
|
|
|
|
* specified <tt>component</tt>.
|
2017-09-18 20:52:10 +00:00
|
|
|
* @returns {{
|
|
|
|
* type: OPEN_DIALOG,
|
|
|
|
* component: React.Component,
|
|
|
|
* componentProps: (Object | undefined)
|
|
|
|
* }}
|
2017-03-07 03:34:51 +00:00
|
|
|
*/
|
2017-09-18 20:52:10 +00:00
|
|
|
export function openDialog(component: Object, componentProps: ?Object) {
|
2017-03-07 03:34:51 +00:00
|
|
|
return {
|
|
|
|
type: OPEN_DIALOG,
|
|
|
|
component,
|
|
|
|
componentProps
|
|
|
|
};
|
|
|
|
}
|
2017-02-17 00:59:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Signals Dialog to open a dialog with the specified component if the component
|
2017-09-18 15:58:03 +00:00
|
|
|
* is not already open. If it is open, then Dialog is signaled to close its
|
|
|
|
* dialog.
|
2017-02-17 00:59:30 +00:00
|
|
|
*
|
|
|
|
* @param {Object} component - The component to display as dialog.
|
2017-09-18 15:58:03 +00:00
|
|
|
* @param {Object} [componentProps] - The React <tt>Component</tt> props of the
|
|
|
|
* specified <tt>component</tt>.
|
2017-09-18 20:52:10 +00:00
|
|
|
* @returns {Function}
|
2017-02-17 00:59:30 +00:00
|
|
|
*/
|
2017-09-18 20:52:10 +00:00
|
|
|
export function toggleDialog(component: Object, componentProps: ?Object) {
|
|
|
|
return (dispatch: Dispatch, getState: Function) => {
|
|
|
|
if (isDialogOpen(getState, component)) {
|
|
|
|
dispatch(hideDialog(component));
|
2017-02-17 00:59:30 +00:00
|
|
|
} else {
|
|
|
|
dispatch(openDialog(component, componentProps));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|