|
@@ -1,15 +1,24 @@
|
|
1
|
+/* @flow */
|
|
2
|
+
|
1
|
3
|
import { HIDE_DIALOG, OPEN_DIALOG } from './actionTypes';
|
|
4
|
+import { isDialogOpen } from './functions';
|
2
|
5
|
|
3
|
6
|
/**
|
4
|
7
|
* Signals Dialog to close its dialog.
|
5
|
8
|
*
|
|
9
|
+ * @param {Object} [component] - The <tt>Dialog</tt> component to close/hide. If
|
|
10
|
+ * <tt>undefined</tt>, closes/hides <tt>Dialog</tt> regardless of which
|
|
11
|
+ * component it's rendering; otherwise, closes/hides <tt>Dialog</tt> only if
|
|
12
|
+ * it's rendering the specified <tt>component</tt>.
|
6
|
13
|
* @returns {{
|
7
|
|
- * type: HIDE_DIALOG
|
|
14
|
+ * type: HIDE_DIALOG,
|
|
15
|
+ * component: (React.Component | undefined)
|
8
|
16
|
* }}
|
9
|
17
|
*/
|
10
|
|
-export function hideDialog() {
|
|
18
|
+export function hideDialog(component: ?Object) {
|
11
|
19
|
return {
|
12
|
|
- type: HIDE_DIALOG
|
|
20
|
+ type: HIDE_DIALOG,
|
|
21
|
+ component
|
13
|
22
|
};
|
14
|
23
|
}
|
15
|
24
|
|
|
@@ -19,9 +28,13 @@ export function hideDialog() {
|
19
|
28
|
* @param {Object} component - The component to display as dialog.
|
20
|
29
|
* @param {Object} [componentProps] - The React <tt>Component</tt> props of the
|
21
|
30
|
* specified <tt>component</tt>.
|
22
|
|
- * @returns {Object}
|
|
31
|
+ * @returns {{
|
|
32
|
+ * type: OPEN_DIALOG,
|
|
33
|
+ * component: React.Component,
|
|
34
|
+ * componentProps: (Object | undefined)
|
|
35
|
+ * }}
|
23
|
36
|
*/
|
24
|
|
-export function openDialog(component, componentProps) {
|
|
37
|
+export function openDialog(component: Object, componentProps: ?Object) {
|
25
|
38
|
return {
|
26
|
39
|
type: OPEN_DIALOG,
|
27
|
40
|
component,
|
|
@@ -37,12 +50,12 @@ export function openDialog(component, componentProps) {
|
37
|
50
|
* @param {Object} component - The component to display as dialog.
|
38
|
51
|
* @param {Object} [componentProps] - The React <tt>Component</tt> props of the
|
39
|
52
|
* specified <tt>component</tt>.
|
40
|
|
- * @returns {Object}
|
|
53
|
+ * @returns {Function}
|
41
|
54
|
*/
|
42
|
|
-export function toggleDialog(component, componentProps) {
|
43
|
|
- return (dispatch, getState) => {
|
44
|
|
- if (getState()['features/base/dialog'].component === component) {
|
45
|
|
- dispatch(hideDialog());
|
|
55
|
+export function toggleDialog(component: Object, componentProps: ?Object) {
|
|
56
|
+ return (dispatch: Dispatch, getState: Function) => {
|
|
57
|
+ if (isDialogOpen(getState, component)) {
|
|
58
|
+ dispatch(hideDialog(component));
|
46
|
59
|
} else {
|
47
|
60
|
dispatch(openDialog(component, componentProps));
|
48
|
61
|
}
|