2022-09-29 10:26:34 +00:00
|
|
|
import { ComponentType } from 'react';
|
2019-03-19 15:42:25 +00:00
|
|
|
|
2022-09-29 10:26:34 +00:00
|
|
|
import { IStore } from '../../app/types';
|
2017-09-18 20:52:10 +00:00
|
|
|
|
2022-06-20 14:53:19 +00:00
|
|
|
import {
|
|
|
|
HIDE_DIALOG,
|
|
|
|
HIDE_SHEET,
|
|
|
|
OPEN_DIALOG,
|
|
|
|
OPEN_SHEET
|
|
|
|
} 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-10-01 06:35:19 +00:00
|
|
|
* @param {Object} [component] - The {@code Dialog} component to close/hide. If
|
|
|
|
* {@code undefined}, closes/hides {@code Dialog} regardless of which
|
|
|
|
* component it's rendering; otherwise, closes/hides {@code Dialog} only if
|
|
|
|
* it's rendering the specified {@code component}.
|
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
|
|
|
* }}
|
|
|
|
*/
|
2022-10-26 06:59:21 +00:00
|
|
|
export function hideDialog(component?: ComponentType<any>) {
|
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
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-06-20 14:53:19 +00:00
|
|
|
/**
|
|
|
|
* Closes the active sheet.
|
|
|
|
*
|
|
|
|
* @returns {{
|
|
|
|
* type: HIDE_SHEET,
|
|
|
|
* }}
|
|
|
|
*/
|
|
|
|
export function hideSheet() {
|
|
|
|
return {
|
|
|
|
type: HIDE_SHEET
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2017-03-07 03:34:51 +00:00
|
|
|
/**
|
|
|
|
* Signals Dialog to open dialog.
|
|
|
|
*
|
|
|
|
* @param {Object} component - The component to display as dialog.
|
2017-10-01 06:35:19 +00:00
|
|
|
* @param {Object} [componentProps] - The React {@code Component} props of the
|
|
|
|
* specified {@code component}.
|
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
|
|
|
*/
|
2022-10-26 06:59:21 +00:00
|
|
|
export function openDialog(component: ComponentType<any>, componentProps?: Object) {
|
2017-03-07 03:34:51 +00:00
|
|
|
return {
|
|
|
|
type: OPEN_DIALOG,
|
|
|
|
component,
|
|
|
|
componentProps
|
|
|
|
};
|
|
|
|
}
|
2017-02-17 00:59:30 +00:00
|
|
|
|
2022-06-20 14:53:19 +00:00
|
|
|
/**
|
|
|
|
* Opens the requested sheet.
|
|
|
|
*
|
|
|
|
* @param {Object} component - The component to display as a sheet.
|
|
|
|
* @param {Object} [componentProps] - The React {@code Component} props of the
|
|
|
|
* specified {@code component}.
|
|
|
|
* @returns {{
|
|
|
|
* type: OPEN_SHEET,
|
|
|
|
* component: React.Component,
|
|
|
|
* componentProps: (Object | undefined)
|
|
|
|
* }}
|
|
|
|
*/
|
2022-09-29 10:26:34 +00:00
|
|
|
export function openSheet(component: ComponentType, componentProps?: Object) {
|
2022-06-20 14:53:19 +00:00
|
|
|
return {
|
|
|
|
type: OPEN_SHEET,
|
|
|
|
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-10-01 06:35:19 +00:00
|
|
|
* @param {Object} [componentProps] - The React {@code Component} props of the
|
|
|
|
* specified {@code component}.
|
2017-09-18 20:52:10 +00:00
|
|
|
* @returns {Function}
|
2017-02-17 00:59:30 +00:00
|
|
|
*/
|
2022-10-26 06:59:21 +00:00
|
|
|
export function toggleDialog(component: ComponentType<any>, componentProps?: Object) {
|
2022-09-29 10:26:34 +00:00
|
|
|
return (dispatch: IStore['dispatch'], getState: IStore['getState']) => {
|
2017-09-18 20:52:10 +00:00
|
|
|
if (isDialogOpen(getState, component)) {
|
|
|
|
dispatch(hideDialog(component));
|
2017-02-17 00:59:30 +00:00
|
|
|
} else {
|
|
|
|
dispatch(openDialog(component, componentProps));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|