Parcourir la source

feat(toolbox): create SettingsButton

Only on web, since there is currently no equivalent on mobile. It encapsulates
all funcionality related to opening the settings dialog / panel.
master
Saúl Ibarra Corretgé il y a 7 ans
Parent
révision
c7d72ee3f6

+ 11
- 43
react/features/toolbox/components/Toolbox.web.js Voir le fichier

@@ -18,7 +18,6 @@ import {
18 18
 } from '../../base/participants';
19 19
 import { getLocalVideoTrack, toggleScreensharing } from '../../base/tracks';
20 20
 import { ChatCounter } from '../../chat';
21
-import { openDeviceSelectionDialog } from '../../device-selection';
22 21
 import { toggleDocument } from '../../etherpad';
23 22
 import { openFeedbackDialog } from '../../feedback';
24 23
 import {
@@ -30,8 +29,7 @@ import {
30 29
 import { openKeyboardShortcutsDialog } from '../../keyboard-shortcuts';
31 30
 import { RECORDING_TYPES, toggleRecording } from '../../recording';
32 31
 import { toggleSharedVideo } from '../../shared-video';
33
-import { shouldShowOnlyDeviceSelection } from '../../settings';
34
-import { toggleChat, toggleProfile, toggleSettings } from '../../side-panel';
32
+import { toggleChat, toggleProfile } from '../../side-panel';
35 33
 import { SpeakerStats } from '../../speaker-stats';
36 34
 import {
37 35
     OverflowMenuVideoQualityItem,
@@ -44,7 +42,12 @@ import OverflowMenuButton from './OverflowMenuButton';
44 42
 import OverflowMenuItem from './OverflowMenuItem';
45 43
 import OverflowMenuProfileItem from './OverflowMenuProfileItem';
46 44
 import ToolbarButton from './ToolbarButton';
47
-import { AudioMuteButton, HangupButton, VideoMuteButton } from './buttons';
45
+import {
46
+    AudioMuteButton,
47
+    HangupButton,
48
+    SettingsButton,
49
+    VideoMuteButton
50
+} from './buttons';
48 51
 
49 52
 type Props = {
50 53
 
@@ -227,8 +230,6 @@ class Toolbox extends Component<Props, State> {
227 230
             = this._onToolbarToggleRecording.bind(this);
228 231
         this._onToolbarToggleScreenshare
229 232
             = this._onToolbarToggleScreenshare.bind(this);
230
-        this._onToolbarToggleSettings
231
-            = this._onToolbarToggleSettings.bind(this);
232 233
         this._onToolbarToggleSharedVideo
233 234
             = this._onToolbarToggleSharedVideo.bind(this);
234 235
     }
@@ -509,21 +510,6 @@ class Toolbox extends Component<Props, State> {
509 510
         }
510 511
     }
511 512
 
512
-    /**
513
-     * Dispatches an action to toggle display of settings, be it the settings
514
-     * panel or directly to device selection.
515
-     *
516
-     * @private
517
-     * @returns {void}
518
-     */
519
-    _doToggleSettings() {
520
-        if (shouldShowOnlyDeviceSelection()) {
521
-            this.props.dispatch(openDeviceSelectionDialog());
522
-        } else {
523
-            this.props.dispatch(toggleSettings());
524
-        }
525
-    }
526
-
527 513
     /**
528 514
      * Dispatches an action to toggle YouTube video sharing.
529 515
      *
@@ -862,21 +848,6 @@ class Toolbox extends Component<Props, State> {
862 848
         this._doToggleScreenshare();
863 849
     }
864 850
 
865
-    _onToolbarToggleSettings: () => void;
866
-
867
-    /**
868
-     * Creates an analytics toolbar event and dispatches an action for toggling
869
-     * settings display.
870
-     *
871
-     * @private
872
-     * @returns {void}
873
-     */
874
-    _onToolbarToggleSettings() {
875
-        sendAnalytics(createToolbarEvent('settings'));
876
-
877
-        this._doToggleSettings();
878
-    }
879
-
880 851
     _onToolbarToggleSharedVideo: () => void;
881 852
 
882 853
     /**
@@ -993,13 +964,10 @@ class Toolbox extends Component<Props, State> {
993 964
                     text = { _editingDocument
994 965
                         ? t('toolbar.documentClose')
995 966
                         : t('toolbar.documentOpen') } />,
996
-            this._shouldShowButton('settings')
997
-                && <OverflowMenuItem
998
-                    accessibilityLabel = 'Settings'
999
-                    icon = 'icon-settings'
1000
-                    key = 'settings'
1001
-                    onClick = { this._onToolbarToggleSettings }
1002
-                    text = { t('toolbar.Settings') } />,
967
+            <SettingsButton
968
+                key = 'settings'
969
+                showLabel = { true }
970
+                visible = { this._shouldShowButton('settings') } />,
1003 971
             this._shouldShowButton('stats')
1004 972
                 && <OverflowMenuItem
1005 973
                     accessibilityLabel = 'Speaker stats'

+ 1
- 0
react/features/toolbox/components/buttons/_.native.js Voir le fichier

@@ -0,0 +1 @@
1
+export * from './native';

+ 1
- 0
react/features/toolbox/components/buttons/_.web.js Voir le fichier

@@ -0,0 +1 @@
1
+export * from './web';

+ 2
- 0
react/features/toolbox/components/buttons/index.js Voir le fichier

@@ -1,3 +1,5 @@
1
+export * from './_';
2
+
1 3
 export { default as AudioMuteButton } from './AudioMuteButton';
2 4
 export { default as HangupButton } from './HangupButton';
3 5
 export { default as VideoMuteButton } from './VideoMuteButton';

+ 0
- 0
react/features/toolbox/components/buttons/native/index.js Voir le fichier


+ 92
- 0
react/features/toolbox/components/buttons/web/SettingsButton.js Voir le fichier

@@ -0,0 +1,92 @@
1
+// @flow
2
+
3
+import { connect } from 'react-redux';
4
+
5
+import { createToolbarEvent, sendAnalytics } from '../../../../analytics';
6
+import { translate } from '../../../../base/i18n';
7
+import { openDeviceSelectionDialog } from '../../../../device-selection';
8
+import { toggleSettings } from '../../../../side-panel';
9
+
10
+import AbstractButton from '../AbstractButton';
11
+import type { Props as AbstractButtonProps } from '../AbstractButton';
12
+
13
+declare var interfaceConfig: Object;
14
+
15
+type Props = AbstractButtonProps & {
16
+
17
+    /**
18
+     * Whether we are in filmstrip only mode or not.
19
+     */
20
+    _filmStripOnly: boolean,
21
+
22
+    /**
23
+     * Array containing the enabled settings sections.
24
+     */
25
+    _sections: Array<string>,
26
+
27
+    /**
28
+     * The redux {@code dispatch} function.
29
+     */
30
+    dispatch: Function
31
+}
32
+
33
+/**
34
+ * An abstract implementation of a button for accessing settings.
35
+ */
36
+class SettingsButton extends AbstractButton<Props, *> {
37
+    accessibilityLabel = 'Settings';
38
+    iconName = 'icon-settings';
39
+    label = 'toolbar.Settings';
40
+    tooltip = 'toolbar.Settings';
41
+
42
+    /**
43
+     * Handles clicking / pressing the button, and opens the appropriate dialog.
44
+     *
45
+     * @private
46
+     * @returns {void}
47
+     */
48
+    _handleClick() {
49
+        const { _filmStripOnly, _sections, dispatch } = this.props;
50
+
51
+        sendAnalytics(createToolbarEvent('settings'));
52
+        if (_filmStripOnly
53
+                || (_sections.length === 1 && _sections.includes('devices'))) {
54
+            dispatch(openDeviceSelectionDialog());
55
+        } else {
56
+            dispatch(toggleSettings());
57
+        }
58
+    }
59
+
60
+    /**
61
+     * Indicates whether this button is disabled or not.
62
+     *
63
+     * @override
64
+     * @private
65
+     * @returns {boolean}
66
+     */
67
+    _isDisabled() {
68
+        return false;
69
+    }
70
+}
71
+
72
+/**
73
+ * Maps (parts of) the redux state to the associated props for the
74
+ * {@code SettingsButton} component.
75
+ *
76
+ * @param {Object} state - The Redux state.
77
+ * @private
78
+ * @returns {{
79
+ *     _filmStripOnly: boolean
80
+ * }}
81
+ */
82
+function _mapStateToProps(state): Object { // eslint-disable-line no-unused-vars
83
+    // XXX: We are not currently using state here, but in the future, when
84
+    // interfaceConfig is part of redux we will.
85
+
86
+    return {
87
+        _filmStripOnly: Boolean(interfaceConfig.filmStripOnly),
88
+        _sections: interfaceConfig.SETTINGS_SECTIONS || []
89
+    };
90
+}
91
+
92
+export default translate(connect(_mapStateToProps)(SettingsButton));

+ 1
- 0
react/features/toolbox/components/buttons/web/index.js Voir le fichier

@@ -0,0 +1 @@
1
+export { default as SettingsButton } from './SettingsButton';

+ 1
- 0
react/features/toolbox/components/index.js Voir le fichier

@@ -1,3 +1,4 @@
1 1
 export { default as ToolbarButton } from './ToolbarButton';
2 2
 export { default as ToolboxFilmstrip } from './ToolboxFilmstrip';
3 3
 export { default as Toolbox } from './Toolbox';
4
+export * from './buttons';

Chargement…
Annuler
Enregistrer