Просмотр исходного кода

feat(settings) removed openTwoButtonDialog from UI module and created react LogoutDialog component

j8
Calin Chitu 4 лет назад
Родитель
Сommit
546df558e3

+ 0
- 216
modules/UI/util/MessageHandler.js Просмотреть файл

@@ -1,8 +1,5 @@
1 1
 /* global $, APP */
2 2
 
3
-import { jitsiLocalStorage } from '@jitsi/js-utils';
4
-import Logger from 'jitsi-meet-logger';
5
-
6 3
 import {
7 4
     NOTIFICATION_TIMEOUT,
8 5
     showErrorNotification,
@@ -10,223 +7,10 @@ import {
10 7
     showWarningNotification
11 8
 } from '../../../react/features/notifications';
12 9
 
13
-const logger = Logger.getLogger(__filename);
14
-
15
-/**
16
- * Currently displayed two button dialog.
17
- * @type {null}
18
- */
19
-let twoButtonDialog = null;
20
-
21
-/**
22
- * Generates html for dont show again checkbox.
23
- * @param {object} options options
24
- * @param {string} options.id the id of the checkbox.
25
- * @param {string} options.textKey the key for the text displayed next to
26
- * checkbox
27
- * @param {boolean} options.checked if true the checkbox is foing to be checked
28
- * by default.
29
- * @returns {string}
30
- */
31
-function generateDontShowCheckbox(options) {
32
-    if (!isDontShowAgainEnabled(options)) {
33
-        return '';
34
-    }
35
-
36
-    const checked
37
-        = options.checked === true ? 'checked' : '';
38
-
39
-
40
-    return `<br />
41
-        <label>
42
-            <input type='checkbox' ${checked} id='${options.id}' />
43
-            <span data-i18n='${options.textKey}'></span>
44
-        </label>`;
45
-}
46
-
47
-/**
48
- * Checks whether the dont show again checkbox was checked before.
49
- * @param {object} options - options for dont show again checkbox.
50
- * @param {string} options.id the id of the checkbox.
51
- * @param {string} options.localStorageKey the key for the local storage. if
52
- * not provided options.id will be used.
53
- * @returns {boolean} true if the dialog mustn't be displayed and
54
- * false otherwise.
55
- */
56
-function dontShowTheDialog(options) {
57
-    if (isDontShowAgainEnabled(options)) {
58
-        if (jitsiLocalStorage.getItem(options.localStorageKey || options.id)
59
-            === 'true') {
60
-            return true;
61
-        }
62
-    }
63
-
64
-    return false;
65
-}
66
-
67
-/**
68
- * Wraps the submit function to process the dont show again status and store
69
- * it.
70
- * @param {object} options - options for dont show again checkbox.
71
- * @param {string} options.id the id of the checkbox.
72
- * @param {Array} options.buttonValues The button values that will trigger
73
- * storing he checkbox value
74
- * @param {string} options.localStorageKey the key for the local storage. if
75
- * not provided options.id will be used.
76
- * @param {Function} submitFunction the submit function to be wrapped
77
- * @returns {Function} wrapped function
78
- */
79
-function dontShowAgainSubmitFunctionWrapper(options, submitFunction) {
80
-    if (isDontShowAgainEnabled(options)) {
81
-        return (...args) => {
82
-            logger.debug(args, options.buttonValues);
83
-
84
-            // args[1] is the value associated with the pressed button
85
-            if (!options.buttonValues || options.buttonValues.length === 0
86
-                || options.buttonValues.indexOf(args[1]) !== -1) {
87
-                const checkbox = $(`#${options.id}`);
88
-
89
-                if (checkbox.length) {
90
-                    jitsiLocalStorage.setItem(
91
-                        options.localStorageKey || options.id,
92
-                        checkbox.prop('checked'));
93
-                }
94
-            }
95
-            submitFunction(...args);
96
-        };
97
-    }
98
-
99
-    return submitFunction;
100
-
101
-}
102
-
103
-/**
104
- * Check whether dont show again checkbox is enabled or not.
105
- * @param {object} options - options for dont show again checkbox.
106
- * @returns {boolean} true if enabled and false if not.
107
- */
108
-function isDontShowAgainEnabled(options) {
109
-    return typeof options === 'object';
110
-}
111
-
112 10
 const messageHandler = {
113 11
     OK: 'dialog.OK',
114 12
     CANCEL: 'dialog.Cancel',
115 13
 
116
-    /**
117
-     * Shows a message to the user with two buttons: first is given as a
118
-     * parameter and the second is Cancel.
119
-     *
120
-     * @param titleKey the key for the title of the message
121
-     * @param msgKey the key for the message
122
-     * @param msgString the text of the message
123
-     * @param persistent boolean value which determines whether the message is
124
-     *        persistent or not
125
-     * @param leftButton the fist button's text
126
-     * @param submitFunction function to be called on submit
127
-     * @param loadedFunction function to be called after the prompt is fully
128
-     *        loaded
129
-     * @param closeFunction function to be called after the prompt is closed
130
-     * @param focus optional focus selector or button index to be focused after
131
-     *        the dialog is opened
132
-     * @param defaultButton index of default button which will be activated when
133
-     *        the user press 'enter'. Indexed from 0.
134
-     * @param {object} dontShowAgain - options for dont show again checkbox.
135
-     * @param {string} dontShowAgain.id the id of the checkbox.
136
-     * @param {string} dontShowAgain.textKey the key for the text displayed
137
-     * next to checkbox
138
-     * @param {boolean} dontShowAgain.checked if true the checkbox is foing to
139
-     * be checked
140
-     * @param {Array} dontShowAgain.buttonValues The button values that will
141
-     * trigger storing the checkbox value
142
-     * @param {string} dontShowAgain.localStorageKey the key for the local
143
-     * storage. if not provided dontShowAgain.id will be used.
144
-     * @return the prompt that was created, or null
145
-     */
146
-    openTwoButtonDialog(options) {
147
-        const {
148
-            titleKey,
149
-            msgKey,
150
-            msgString,
151
-            leftButtonKey,
152
-            submitFunction,
153
-            loadedFunction,
154
-            closeFunction,
155
-            focus,
156
-            size,
157
-            defaultButton,
158
-            wrapperClass,
159
-            dontShowAgain
160
-        } = options;
161
-
162
-        let { classes } = options;
163
-
164
-        if (twoButtonDialog) {
165
-            return null;
166
-        }
167
-
168
-        if (dontShowTheDialog(dontShowAgain)) {
169
-            // Maybe we should pass some parameters here? I'm not sure
170
-            // and currently we don't need any parameters.
171
-            submitFunction();
172
-
173
-            return null;
174
-        }
175
-
176
-        const buttons = [];
177
-
178
-        const leftButton = leftButtonKey
179
-            ? APP.translation.generateTranslationHTML(leftButtonKey)
180
-            : APP.translation.generateTranslationHTML('dialog.Submit');
181
-
182
-        buttons.push({ title: leftButton,
183
-            value: true });
184
-
185
-        const cancelButton
186
-            = APP.translation.generateTranslationHTML('dialog.Cancel');
187
-
188
-        buttons.push({ title: cancelButton,
189
-            value: false });
190
-
191
-        let message = msgString;
192
-
193
-        if (msgKey) {
194
-            message = APP.translation.generateTranslationHTML(msgKey);
195
-        }
196
-        message += generateDontShowCheckbox(dontShowAgain);
197
-        classes = classes || this._getDialogClasses(size);
198
-        if (wrapperClass) {
199
-            classes.prompt += ` ${wrapperClass}`;
200
-        }
201
-
202
-        twoButtonDialog = $.prompt(message, {
203
-            title: this._getFormattedTitleString(titleKey),
204
-            persistent: false,
205
-            buttons,
206
-            defaultButton,
207
-            focus,
208
-            loaded: loadedFunction,
209
-            promptspeed: 0,
210
-            classes,
211
-            submit: dontShowAgainSubmitFunctionWrapper(dontShowAgain,
212
-                (e, v, m, f) => { // eslint-disable-line max-params
213
-                    twoButtonDialog = null;
214
-                    if (v && submitFunction) {
215
-                        submitFunction(e, v, m, f);
216
-                    }
217
-                }),
218
-            close(e, v, m, f) { // eslint-disable-line max-params
219
-                twoButtonDialog = null;
220
-                if (closeFunction) {
221
-                    closeFunction(e, v, m, f);
222
-                }
223
-            }
224
-        });
225
-        APP.translation.translateElement(twoButtonDialog);
226
-
227
-        return $.prompt.getApi();
228
-    },
229
-
230 14
     /**
231 15
      * Returns the formatted title string.
232 16
      *

+ 12
- 1
react/features/settings/actions.js Просмотреть файл

@@ -10,11 +10,22 @@ import {
10 10
     SET_AUDIO_SETTINGS_VISIBILITY,
11 11
     SET_VIDEO_SETTINGS_VISIBILITY
12 12
 } from './actionTypes';
13
-import { SettingsDialog } from './components';
13
+import { LogoutDialog, SettingsDialog } from './components';
14 14
 import { getMoreTabProps, getProfileTabProps } from './functions';
15 15
 
16 16
 declare var APP: Object;
17 17
 
18
+/**
19
+ * Opens {@code LogoutDialog}.
20
+ *
21
+ * @param {Function} onLogout - The event in {@code LogoutDialog} that should be
22
+ *  enabled on click.
23
+ * @returns {Function}
24
+ */
25
+export function openLogoutDialog(onLogout: Function) {
26
+    return openDialog(LogoutDialog, { onLogout });
27
+}
28
+
18 29
 /**
19 30
  * Opens {@code SettingsDialog}.
20 31
  *

+ 48
- 0
react/features/settings/components/web/LogoutDialog.js Просмотреть файл

@@ -0,0 +1,48 @@
1
+// @flow
2
+
3
+import React from 'react';
4
+
5
+import { Dialog } from '../../../base/dialog';
6
+import { translate } from '../../../base/i18n';
7
+import { connect } from '../../../base/redux';
8
+
9
+/**
10
+ * The type of {@link LogoutDialog}'s React {@code Component} props.
11
+ */
12
+type Props = {
13
+
14
+    /**
15
+     * Logout handler.
16
+     */
17
+    onLogout: Function,
18
+
19
+    /**
20
+     * Function to be used to translate i18n labels.
21
+     */
22
+    t: Function
23
+};
24
+
25
+/**
26
+ * Implements the Logout dialog.
27
+ *
28
+ * @param {Object} props - The props of the component.
29
+ * @returns {React$Element}.
30
+ */
31
+function LogoutDialog(props: Props) {
32
+    const { onLogout, t } = props;
33
+
34
+    return (
35
+        <Dialog
36
+            hideCancelButton = { false }
37
+            okKey = { t('dialog.Yes') }
38
+            onSubmit = { onLogout }
39
+            titleKey = { t('dialog.logoutTitle') }
40
+            width = { 'small' }>
41
+            <div>
42
+                { t('dialog.logoutQuestion') }
43
+            </div>
44
+        </Dialog>
45
+    );
46
+}
47
+
48
+export default translate(connect()(LogoutDialog));

+ 4
- 12
react/features/settings/components/web/ProfileTab.js Просмотреть файл

@@ -12,6 +12,7 @@ import {
12 12
 import { AbstractDialogTab } from '../../../base/dialog';
13 13
 import type { Props as AbstractDialogTabProps } from '../../../base/dialog';
14 14
 import { translate } from '../../../base/i18n';
15
+import { openLogoutDialog } from '../../actions';
15 16
 
16 17
 declare var APP: Object;
17 18
 
@@ -138,23 +139,14 @@ class ProfileTab extends AbstractDialogTab<Props> {
138 139
         if (this.props.authLogin) {
139 140
             sendAnalytics(createProfilePanelButtonEvent('logout.button'));
140 141
 
141
-            APP.UI.messageHandler.openTwoButtonDialog({
142
-                leftButtonKey: 'dialog.Yes',
143
-                msgKey: 'dialog.logoutQuestion',
144
-                submitFunction(evt, yes) {
145
-                    if (yes) {
146
-                        APP.UI.emitEvent(UIEvents.LOGOUT);
147
-                    }
148
-                },
149
-                titleKey: 'dialog.logoutTitle'
150
-            });
142
+            APP.store.dispatch(openLogoutDialog(
143
+                () => APP.UI.emitEvent(UIEvents.LOGOUT)
144
+            ));
151 145
         } else {
152 146
             sendAnalytics(createProfilePanelButtonEvent('login.button'));
153 147
 
154 148
             APP.UI.emitEvent(UIEvents.AUTH_CLICKED);
155 149
         }
156
-
157
-        this.props.closeDialog();
158 150
     }
159 151
 
160 152
     /**

+ 1
- 0
react/features/settings/components/web/index.js Просмотреть файл

@@ -1,3 +1,4 @@
1
+export { default as LogoutDialog } from './LogoutDialog';
1 2
 export { default as SettingsButton } from './SettingsButton';
2 3
 export { default as SettingsDialog } from './SettingsDialog';
3 4
 export { default as AudioSettingsPopup } from './audio/AudioSettingsPopup';

Загрузка…
Отмена
Сохранить