Преглед изворни кода

ref(info): be explicit when opening the dialog with a timeout

Instead of assuming the initial info dialog open should auto
close, explicitly call opening of the dialog with a flag for
auto closing. This better facilitates the auto close timeout
being set at any time.

The changes led to refactoring out state in the InfoDialogButton
in preference for always clearing the timeout instead of
first checking for interaction before clearing.
j8
Leonard Kim пре 8 година
родитељ
комит
887e1b6828

+ 7
- 1
react/features/invite/actions.js Прегледај датотеку

24
  * Opens the inline conference info dialog.
24
  * Opens the inline conference info dialog.
25
  *
25
  *
26
  * @param {boolean} visible - Whether or not the dialog should be displayed.
26
  * @param {boolean} visible - Whether or not the dialog should be displayed.
27
+ * @param {boolean} autoClose - Whether or not the dialog should automatically
28
+ * close after a set period of time.
27
  * @returns {{
29
  * @returns {{
28
  *     type: SET_INFO_DIALOG_VISIBILITY,
30
  *     type: SET_INFO_DIALOG_VISIBILITY,
31
+ *     autoClose: boolean,
29
  *     visible: boolean
32
  *     visible: boolean
30
  * }}
33
  * }}
31
  */
34
  */
32
-export function setInfoDialogVisibility(visible: boolean) {
35
+export function setInfoDialogVisibility(
36
+        visible: boolean,
37
+        autoClose: boolean = false) {
33
     return {
38
     return {
34
         type: SET_INFO_DIALOG_VISIBILITY,
39
         type: SET_INFO_DIALOG_VISIBILITY,
40
+        autoClose,
35
         visible
41
         visible
36
     };
42
     };
37
 }
43
 }

+ 57
- 33
react/features/invite/components/InfoDialogButton.web.js Прегледај датотеку

40
      * @static
40
      * @static
41
      */
41
      */
42
     static propTypes = {
42
     static propTypes = {
43
+        /**
44
+         * Whether or not the {@code InfoDialog} should close by itself after a
45
+         * a timeout.
46
+         */
47
+        _shouldAutoClose: PropTypes.bool,
48
+
43
         /**
49
         /**
44
          * Whether or not {@code InfoDialog} should be displayed.
50
          * Whether or not {@code InfoDialog} should be displayed.
45
          */
51
          */
80
          */
86
          */
81
         this._autoHideDialogTimeout = null;
87
         this._autoHideDialogTimeout = null;
82
 
88
 
83
-        this.state = {
84
-            /**
85
-             * Whether or not the dialog has been interacted with somehow, such
86
-             * as clicking or toggle display. A value of true will prevent the
87
-             * dialog from being automatically hidden.
88
-             */
89
-            hasInteractedWithDialog: false
90
-        };
91
-
92
         // Bind event handlers so they are only bound once for every instance.
89
         // Bind event handlers so they are only bound once for every instance.
93
         this._onDialogClose = this._onDialogClose.bind(this);
90
         this._onDialogClose = this._onDialogClose.bind(this);
94
         this._onDialogMouseOver = this._onDialogMouseOver.bind(this);
91
         this._onDialogMouseOver = this._onDialogMouseOver.bind(this);
101
      * @inheritdoc
98
      * @inheritdoc
102
      */
99
      */
103
     componentDidMount() {
100
     componentDidMount() {
104
-        this._autoHideDialogTimeout = setTimeout(() => {
105
-            this._maybeHideDialog();
106
-        }, INITIAL_TOOLBAR_TIMEOUT);
101
+        if (this.props._shouldAutoClose) {
102
+            this._setAutoCloseTimeout();
103
+        }
107
     }
104
     }
108
 
105
 
109
     /**
106
     /**
110
-     * Update the state when the {@code InfoDialog} visibility has been updated.
107
+     * Set or clear the timeout to automatically hide the {@code InfoDialog}.
111
      *
108
      *
112
      * @inheritdoc
109
      * @inheritdoc
113
      */
110
      */
114
-    componentWillReceiveProps(nextProps) {
115
-        if (!this.state.hasInteractedWithDialog
116
-            && (nextProps._showDialog !== this.props._showDialog)) {
117
-            this.setState({ hasInteractedWithDialog: true });
111
+    componentDidUpdate(prevProps) {
112
+        // If the _shouldAutoClose flag has been updated to be true then make
113
+        // sure to set _autoHideDialogTimeout.
114
+        if (this.props._shouldAutoClose && !prevProps._shouldAutoClose) {
115
+            this._setAutoCloseTimeout();
116
+        } else {
117
+            this._clearAutoCloseTimeout();
118
         }
118
         }
119
+    }
119
 
120
 
120
-        if (!nextProps._toolboxVisible && this.props._toolboxVisible) {
121
+    /**
122
+     * Update the visibility of the {@code InfoDialog}.
123
+     *
124
+     * @inheritdoc
125
+     */
126
+    componentWillReceiveProps(nextProps) {
127
+        // Ensure the dialog is closed when the toolbox becomes hidden.
128
+        if (nextProps._showDialog && !nextProps._toolboxVisible) {
121
             this._onDialogClose();
129
             this._onDialogClose();
122
         }
130
         }
123
     }
131
     }
128
      * @inheritdoc
136
      * @inheritdoc
129
      */
137
      */
130
     componentWillUnmount() {
138
     componentWillUnmount() {
131
-        clearTimeout(this._autoHideDialogTimeout);
139
+        this._clearAutoCloseTimeout();
132
     }
140
     }
133
 
141
 
134
     /**
142
     /**
154
                     onMouseOver = { this._onDialogMouseOver } /> }
162
                     onMouseOver = { this._onDialogMouseOver } /> }
155
                 isOpen = { _toolboxVisible && _showDialog }
163
                 isOpen = { _toolboxVisible && _showDialog }
156
                 onClose = { this._onDialogClose }
164
                 onClose = { this._onDialogClose }
157
-                onContentClick = { this._onDialogInteract }
158
                 position = { TOOLTIP_TO_POPUP_POSITION[tooltipPosition] }>
165
                 position = { TOOLTIP_TO_POPUP_POSITION[tooltipPosition] }>
159
                 <ToolbarButton
166
                 <ToolbarButton
160
                     button = { buttonConfiguration }
167
                     button = { buttonConfiguration }
165
     }
172
     }
166
 
173
 
167
     /**
174
     /**
168
-     * Callback invoked after a timeout to trigger hiding of the
169
-     * {@code InfoDialog} if there has been no interaction with the dialog
170
-     * and the dialog is currently showing.
175
+     * Cancels the timeout to automatically hide the {@code InfoDialog}.
171
      *
176
      *
172
      * @private
177
      * @private
173
      * @returns {void}
178
      * @returns {void}
174
      */
179
      */
175
-    _maybeHideDialog() {
176
-        if (!this.state.hasInteractedWithDialog && this.props._showDialog) {
177
-            this._onDialogToggle();
178
-        }
180
+    _clearAutoCloseTimeout() {
181
+        clearTimeout(this._autoHideDialogTimeout);
182
+        this._autoHideDialogTimeout = null;
179
     }
183
     }
180
 
184
 
181
     /**
185
     /**
189
     }
193
     }
190
 
194
 
191
     /**
195
     /**
192
-     * Updates the internal state to mark the {@code InfoDialog} as having been
193
-     * interacted with.
196
+     * Cancels the timeout to automatically hide the {@code InfoDialog}.
194
      *
197
      *
195
      * @private
198
      * @private
196
      * @returns {void}
199
      * @returns {void}
197
      */
200
      */
198
     _onDialogMouseOver() {
201
     _onDialogMouseOver() {
199
-        if (!this.state.hasInteractedWithDialog) {
200
-            this.setState({ hasInteractedWithDialog: true });
201
-        }
202
+        this._clearAutoCloseTimeout();
202
     }
203
     }
203
 
204
 
204
     /**
205
     /**
210
     _onDialogToggle() {
211
     _onDialogToggle() {
211
         this.props.dispatch(setInfoDialogVisibility(!this.props._showDialog));
212
         this.props.dispatch(setInfoDialogVisibility(!this.props._showDialog));
212
     }
213
     }
214
+
215
+    /**
216
+     * Set a timeout to automatically hide the {@code InfoDialog}.
217
+     *
218
+     * @private
219
+     * @returns {void}
220
+     */
221
+    _setAutoCloseTimeout() {
222
+        this._clearAutoCloseTimeout();
223
+
224
+        this._autoHideDialogTimeout = setTimeout(() => {
225
+            if (this.props._showDialog) {
226
+                this._onDialogClose();
227
+            }
228
+        }, INITIAL_TOOLBAR_TIMEOUT);
229
+    }
213
 }
230
 }
214
 
231
 
215
 /**
232
 /**
219
  * @param {Object} state - The Redux state.
236
  * @param {Object} state - The Redux state.
220
  * @private
237
  * @private
221
  * @returns {{
238
  * @returns {{
239
+ *     _shouldAutoClose: boolean,
222
  *     _showDialog: boolean,
240
  *     _showDialog: boolean,
223
  *     _toolboxVisible: boolean
241
  *     _toolboxVisible: boolean
224
  * }}
242
  * }}
225
  */
243
  */
226
 function _mapStateToProps(state) {
244
 function _mapStateToProps(state) {
245
+    const {
246
+        infoDialogVisible,
247
+        infoDialogWillAutoClose
248
+    } = state['features/invite'];
249
+
227
     return {
250
     return {
228
-        _showDialog: state['features/invite'].infoDialogVisible,
251
+        _shouldAutoClose: infoDialogWillAutoClose,
252
+        _showDialog: infoDialogVisible,
229
         _toolboxVisible: state['features/toolbox'].visible
253
         _toolboxVisible: state['features/toolbox'].visible
230
     };
254
     };
231
 }
255
 }

+ 1
- 1
react/features/invite/middleware.js Прегледај датотеку

18
 
18
 
19
     switch (action.type) {
19
     switch (action.type) {
20
     case CONFERENCE_JOINED:
20
     case CONFERENCE_JOINED:
21
-        store.dispatch(setInfoDialogVisibility(true));
21
+        store.dispatch(setInfoDialogVisibility(true, true));
22
         break;
22
         break;
23
 
23
 
24
     case UPDATE_DIAL_IN_NUMBERS_FAILED:
24
     case UPDATE_DIAL_IN_NUMBERS_FAILED:

+ 2
- 1
react/features/invite/reducer.js Прегледај датотеку

15
     case SET_INFO_DIALOG_VISIBILITY:
15
     case SET_INFO_DIALOG_VISIBILITY:
16
         return {
16
         return {
17
             ...state,
17
             ...state,
18
-            infoDialogVisible: action.visible
18
+            infoDialogVisible: action.visible,
19
+            infoDialogWillAutoClose: action.autoClose
19
         };
20
         };
20
 
21
 
21
     case UPDATE_DIAL_IN_NUMBERS_FAILED:
22
     case UPDATE_DIAL_IN_NUMBERS_FAILED:

Loading…
Откажи
Сачувај