ref(settings-dialog) Update to use new Dialog component (#12912)

* ref(settings-dialog) Update to use new Dialog component

Created new DialogWithTabs component
Refactored Dialog into Dialog and BaseDialog
Updated dialog functionality on mobile
This commit is contained in:
Robert Pintilii 2023-02-17 11:34:30 +02:00 committed by GitHub
parent 0a464a5223
commit c424884201
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 650 additions and 291 deletions

View File

@ -5,11 +5,6 @@ import { Component } from 'react';
*/
export interface IProps {
/**
* Function that closes the dialog.
*/
closeDialog: Function;
/**
* Callback to invoke on change.
*/

View File

@ -27,6 +27,7 @@ import ShareAudioDialog from '../../screen-share/components/web/ShareAudioDialog
import ShareScreenWarningDialog from '../../screen-share/components/web/ShareScreenWarningDialog';
import SecurityDialog from '../../security/components/security-dialog/web/SecurityDialog';
import LogoutDialog from '../../settings/components/web/LogoutDialog';
import SettingsDialog from '../../settings/components/web/SettingsDialog';
import SharedVideoDialog from '../../shared-video/components/web/SharedVideoDialog';
import SpeakerStats from '../../speaker-stats/components/web/SpeakerStats';
import LanguageSelectorDialog from '../../subtitles/components/LanguageSelectorDialog.web';
@ -51,7 +52,7 @@ const NEW_DIALOG_LIST = [ KeyboardShortcutsDialog, ChatPrivacyDialog, DisplayNam
SharedVideoDialog, SpeakerStats, LanguageSelectorDialog, MuteEveryoneDialog, MuteEveryonesVideoDialog,
GrantModeratorDialog, KickRemoteParticipantDialog, MuteRemoteParticipantsVideoDialog, VideoQualityDialog,
VirtualBackgroundDialog, LoginDialog, WaitForOwnerDialog, DesktopPicker, RemoteControlAuthorizationDialog,
LogoutDialog, SalesforceLinkDialog, ParticipantVerificationDialog, PasswordRequiredPrompt ];
LogoutDialog, SalesforceLinkDialog, ParticipantVerificationDialog, PasswordRequiredPrompt, SettingsDialog ];
// This function is necessary while the transition from @atlaskit dialog to our component is ongoing.
const isNewDialog = (component: any) => NEW_DIALOG_LIST.some(comp => comp === component);

View File

@ -0,0 +1,3 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M12 1.5C11.5858 1.5 11.25 1.83579 11.25 2.25V3C11.25 3.01239 11.2503 3.0247 11.2509 3.03694C7.46047 3.41282 4.5 6.61068 4.5 10.5V12.0949C4.5 12.9852 4.10453 13.8296 3.42055 14.3995L3.07702 14.6858C2.55299 15.1225 2.25 15.7694 2.25 16.4515C2.25 17.7209 3.27906 18.75 4.54846 18.75H8.25C8.25 20.8211 9.92893 22.5 12 22.5C14.0711 22.5 15.75 20.8211 15.75 18.75H19.3635C20.6815 18.75 21.75 17.6815 21.75 16.3635C21.75 15.7306 21.4986 15.1236 21.051 14.676L20.3787 14.0037C19.8161 13.4411 19.5 12.678 19.5 11.8824V10.5C19.5 6.61068 16.5395 3.41282 12.7491 3.03694C12.7497 3.0247 12.75 3.01239 12.75 3V2.25C12.75 1.83579 12.4142 1.5 12 1.5ZM18 10.5C18 7.18629 15.3137 4.5 12 4.5C8.68629 4.5 6 7.18629 6 10.5V12.7974C6 13.6878 5.60453 14.5321 4.92055 15.1021L4.0373 15.8381C3.85526 15.9898 3.75 16.2146 3.75 16.4515C3.75 16.8925 4.10748 17.25 4.54846 17.25H19.3635C19.8531 17.25 20.25 16.8531 20.25 16.3635C20.25 16.1284 20.1566 15.9029 19.9904 15.7367L18.8787 14.625C18.3161 14.0624 18 13.2993 18 12.5037V10.5ZM14.25 18.75H9.75C9.75 19.9926 10.7574 21 12 21C13.2426 21 14.25 19.9926 14.25 18.75Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 1.2 KiB

View File

@ -8,6 +8,7 @@ export { default as IconArrowUpLarge } from './arrow-up-large.svg';
export { default as IconAudioOnly } from './visibility.svg';
export { default as IconAudioOnlyOff } from './visibility-off.svg';
export { default as IconBluetooth } from './bluetooth.svg';
export { default as IconBell } from './bell.svg';
export { default as IconCalendar } from './calendar.svg';
export { default as IconCameraRefresh } from './camera-refresh.svg';
export { default as IconCar } from './car.svg';
@ -88,6 +89,7 @@ export { default as IconTileView } from './tile-view.svg';
export { default as IconTrash } from './trash.svg';
export { default as IconUserDeleted } from './user-deleted.svg';
export { default as IconUsers } from './users.svg';
export { default as IconUser } from './user.svg';
export { default as IconVideo } from './video.svg';
export { default as IconVideoOff } from './video-off.svg';
export { default as IconVolumeOff } from './volume-off.svg';

View File

@ -0,0 +1,4 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M16.5 6.75C16.5 9.23528 14.4853 11.25 12 11.25C9.51472 11.25 7.5 9.23528 7.5 6.75C7.5 4.26472 9.51472 2.25 12 2.25C14.4853 2.25 16.5 4.26472 16.5 6.75ZM15 6.75C15 8.40685 13.6569 9.75 12 9.75C10.3431 9.75 9 8.40685 9 6.75C9 5.09315 10.3431 3.75 12 3.75C13.6569 3.75 15 5.09315 15 6.75Z" fill="white"/>
<path fill-rule="evenodd" clip-rule="evenodd" d="M19.5 17.25C19.5 19.7353 16.1421 21.75 12 21.75C7.85786 21.75 4.5 19.7353 4.5 17.25C4.5 14.7647 7.85786 12.75 12 12.75C16.1421 12.75 19.5 14.7647 19.5 17.25ZM18 17.25C18 17.7588 17.6485 18.4756 16.5316 19.1457C15.4445 19.798 13.8459 20.25 12 20.25C10.1541 20.25 8.55549 19.798 7.46844 19.1457C6.35154 18.4756 6 17.7588 6 17.25C6 16.7412 6.35154 16.0244 7.46844 15.3543C8.55549 14.702 10.1541 14.25 12 14.25C13.8459 14.25 15.4445 14.702 16.5316 15.3543C17.6485 16.0244 18 16.7412 18 17.25Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 1016 B

View File

@ -0,0 +1,199 @@
import React, { ReactNode, useCallback, useContext, useEffect } from 'react';
import FocusLock from 'react-focus-lock';
import { useTranslation } from 'react-i18next';
import { keyframes } from 'tss-react';
import { makeStyles } from 'tss-react/mui';
import { withPixelLineHeight } from '../../../styles/functions.web';
import { DialogTransitionContext } from './DialogTransition';
const useStyles = makeStyles()(theme => {
return {
container: {
width: '100%',
height: '100%',
position: 'fixed',
color: theme.palette.text01,
...withPixelLineHeight(theme.typography.bodyLongRegular),
top: 0,
left: 0,
display: 'flex',
justifyContent: 'center',
alignItems: 'flex-start',
zIndex: 301,
animation: `${keyframes`
0% {
opacity: 0.4;
}
100% {
opacity: 1;
}
`} 0.2s forwards ease-out`,
'&.unmount': {
animation: `${keyframes`
0% {
opacity: 1;
}
100% {
opacity: 0.5;
}
`} 0.15s forwards ease-in`
}
},
backdrop: {
position: 'absolute',
width: '100%',
height: '100%',
top: 0,
left: 0,
backgroundColor: theme.palette.ui02,
opacity: 0.75
},
modal: {
backgroundColor: theme.palette.ui01,
border: `1px solid ${theme.palette.ui03}`,
boxShadow: '0px 4px 25px 4px rgba(20, 20, 20, 0.6)',
borderRadius: `${theme.shape.borderRadius}px`,
display: 'flex',
flexDirection: 'column',
height: 'auto',
minHeight: '200px',
maxHeight: '80vh',
marginTop: '64px',
animation: `${keyframes`
0% {
margin-top: 85px
}
100% {
margin-top: 64px
}
`} 0.2s forwards ease-out`,
'&.medium': {
width: '400px'
},
'&.large': {
width: '664px'
},
'&.unmount': {
animation: `${keyframes`
0% {
margin-top: 64px
}
100% {
margin-top: 40px
}
`} 0.15s forwards ease-in`
},
'@media (max-width: 448px)': {
width: '100% !important',
maxHeight: 'initial',
height: '100%',
margin: 0,
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
animation: `${keyframes`
0% {
margin-top: 15px
}
100% {
margin-top: 0
}
`} 0.2s forwards ease-out`,
'&.unmount': {
animation: `${keyframes`
0% {
margin-top: 0
}
100% {
margin-top: 15px
}
`} 0.15s forwards ease-in`
}
}
},
focusLock: {
zIndex: 1
}
};
});
export interface IProps {
children?: ReactNode;
className?: string;
description?: string;
disableBackdropClose?: boolean;
disableEnter?: boolean;
onClose?: () => void;
size?: 'large' | 'medium';
submit?: () => void;
title?: string;
titleKey?: string;
}
const BaseDialog = ({
children,
className,
description,
disableBackdropClose,
disableEnter,
onClose,
size = 'medium',
submit,
title,
titleKey
}: IProps) => {
const { classes, cx } = useStyles();
const { isUnmounting } = useContext(DialogTransitionContext);
const { t } = useTranslation();
const onBackdropClick = useCallback(() => {
!disableBackdropClose && onClose?.();
}, [ disableBackdropClose, onClose ]);
const handleKeyDown = useCallback((e: KeyboardEvent) => {
if (e.key === 'Escape') {
onClose?.();
}
if (e.key === 'Enter' && !disableEnter) {
submit?.();
}
}, []);
useEffect(() => {
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}, []);
return (
<div className = { cx(classes.container, isUnmounting && 'unmount') }>
<div
className = { classes.backdrop }
onClick = { onBackdropClick } />
<FocusLock className = { classes.focusLock }>
<div
aria-describedby = { description }
aria-labelledby = { title ?? t(titleKey ?? '') }
aria-modal = { true }
className = { cx(classes.modal, isUnmounting && 'unmount', size, className) }
role = 'dialog'>
{children}
</div>
</FocusLock>
</div>
);
};
export default BaseDialog;

View File

@ -178,7 +178,14 @@ const ContextMenuItem = ({
className = { styles.contextMenuItemIcon }
size = { 20 }
src = { icon } />}
{text && <span className = { cx(styles.text, textClassName) }>{text}</span>}
{text && (
<span
className = { cx(styles.text,
_overflowDrawer && styles.drawerText,
textClassName) }>
{text}
</span>
)}
{children}
</div>
);

View File

@ -1,134 +1,19 @@
import React, { useCallback, useContext, useEffect } from 'react';
import FocusLock from 'react-focus-lock';
import React, { useCallback } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch } from 'react-redux';
import { keyframes } from 'tss-react';
import { makeStyles } from 'tss-react/mui';
import { hideDialog } from '../../../dialog/actions';
import { IconCloseLarge } from '../../../icons/svg';
import { withPixelLineHeight } from '../../../styles/functions.web';
import BaseDialog, { IProps as IBaseDialogProps } from './BaseDialog';
import Button from './Button';
import ClickableIcon from './ClickableIcon';
import { DialogTransitionContext } from './DialogTransition';
const useStyles = makeStyles()(theme => {
return {
container: {
width: '100%',
height: '100%',
position: 'fixed',
color: theme.palette.text01,
...withPixelLineHeight(theme.typography.bodyLongRegular),
top: 0,
left: 0,
display: 'flex',
justifyContent: 'center',
alignItems: 'flex-start',
zIndex: 301,
animation: `${keyframes`
0% {
opacity: 0.4;
}
100% {
opacity: 1;
}
`} 0.2s forwards ease-out`,
'&.unmount': {
animation: `${keyframes`
0% {
opacity: 1;
}
100% {
opacity: 0.5;
}
`} 0.15s forwards ease-in`
}
},
backdrop: {
position: 'absolute',
width: '100%',
height: '100%',
top: 0,
left: 0,
backgroundColor: theme.palette.ui02,
opacity: 0.75
},
modal: {
backgroundColor: theme.palette.ui01,
border: `1px solid ${theme.palette.ui03}`,
boxShadow: '0px 4px 25px 4px rgba(20, 20, 20, 0.6)',
borderRadius: `${theme.shape.borderRadius}px`,
display: 'flex',
flexDirection: 'column',
height: 'auto',
minHeight: '200px',
maxHeight: '80vh',
marginTop: '64px',
animation: `${keyframes`
0% {
margin-top: 85px
}
100% {
margin-top: 64px
}
`} 0.2s forwards ease-out`,
'&.medium': {
width: '400px'
},
'&.large': {
width: '664px'
},
'&.unmount': {
animation: `${keyframes`
0% {
margin-top: 64px
}
100% {
margin-top: 40px
}
`} 0.15s forwards ease-in`
},
'@media (max-width: 448px)': {
width: '100% !important',
maxHeight: 'initial',
height: '100%',
margin: 0,
position: 'absolute',
top: 0,
left: 0,
bottom: 0,
animation: `${keyframes`
0% {
margin-top: 15px
}
100% {
margin-top: 0
}
`} 0.2s forwards ease-out`,
'&.unmount': {
animation: `${keyframes`
0% {
margin-top: 0
}
100% {
margin-top: 15px
}
`} 0.15s forwards ease-in`
}
}
},
header: {
width: '100%',
padding: '24px',
@ -176,15 +61,11 @@ const useStyles = makeStyles()(theme => {
'& button:last-child': {
marginLeft: '16px'
}
},
focusLock: {
zIndex: 1
}
};
});
interface IDialogProps {
interface IDialogProps extends IBaseDialogProps {
back?: {
hidden?: boolean;
onClick?: () => void;
@ -195,11 +76,7 @@ interface IDialogProps {
translationKey?: string;
};
children?: React.ReactNode;
className?: string;
description?: string;
disableAutoHideOnSubmit?: boolean;
disableBackdropClose?: boolean;
disableEnter?: boolean;
hideCloseButton?: boolean;
ok?: {
disabled?: boolean;
@ -208,9 +85,6 @@ interface IDialogProps {
};
onCancel?: () => void;
onSubmit?: () => void;
size?: 'large' | 'medium';
title?: string;
titleKey?: string;
}
const Dialog = ({
@ -226,13 +100,12 @@ const Dialog = ({
ok = { translationKey: 'dialog.Ok' },
onCancel,
onSubmit,
size = 'medium',
size,
title,
titleKey
}: IDialogProps) => {
const { classes, cx } = useStyles();
const { classes } = useStyles();
const { t } = useTranslation();
const { isUnmounting } = useContext(DialogTransitionContext);
const dispatch = useDispatch();
const onClose = useCallback(() => {
@ -245,81 +118,59 @@ const Dialog = ({
onSubmit?.();
}, [ onSubmit ]);
const handleKeyDown = useCallback((e: KeyboardEvent) => {
if (e.key === 'Escape') {
onClose();
}
if (e.key === 'Enter' && !disableEnter) {
submit();
}
}, []);
const onBackdropClick = useCallback(() => {
!disableBackdropClose && onClose();
}, [ disableBackdropClose, onClose ]);
useEffect(() => {
window.addEventListener('keydown', handleKeyDown);
return () => window.removeEventListener('keydown', handleKeyDown);
}, []);
return (
<div className = { cx(classes.container, isUnmounting && 'unmount') }>
<BaseDialog
className = { className }
description = { description }
disableBackdropClose = { disableBackdropClose }
disableEnter = { disableEnter }
onClose = { onClose }
size = { size }
submit = { submit }
title = { title }
titleKey = { titleKey }>
<div className = { classes.header }>
<p
className = { classes.title }
id = 'dialog-title'>
{title ?? t(titleKey ?? '')}
</p>
{!hideCloseButton && (
<ClickableIcon
accessibilityLabel = { t('dialog.close') }
className = { classes.closeIcon }
icon = { IconCloseLarge }
id = 'modal-header-close-button'
onClick = { onClose } />
)}
</div>
<div
className = { classes.backdrop }
onClick = { onBackdropClick } />
<FocusLock className = { classes.focusLock }>
<div
aria-describedby = { description }
aria-labelledby = { title ?? t(titleKey ?? '') }
aria-modal = { true }
className = { cx(classes.modal, isUnmounting && 'unmount', size, className) }
role = 'dialog'>
<div className = { classes.header }>
<p
className = { classes.title }
id = 'dialog-title'>
{title ?? t(titleKey ?? '')}
</p>
{!hideCloseButton && (
<ClickableIcon
accessibilityLabel = { t('dialog.close') }
className = { classes.closeIcon }
icon = { IconCloseLarge }
id = 'modal-header-close-button'
onClick = { onClose } />
)}
</div>
<div
className = { classes.content }
data-autofocus-inside = 'true'>
{children}
</div>
<div
className = { classes.footer }
data-autofocus-inside = 'true'>
{!back.hidden && <Button
accessibilityLabel = { t(back.translationKey ?? '') }
labelKey = { back.translationKey }
// eslint-disable-next-line react/jsx-handler-names
onClick = { back.onClick }
type = 'secondary' />}
{!cancel.hidden && <Button
accessibilityLabel = { t(cancel.translationKey ?? '') }
labelKey = { cancel.translationKey }
onClick = { onClose }
type = 'tertiary' />}
{!ok.hidden && <Button
accessibilityLabel = { t(ok.translationKey ?? '') }
disabled = { ok.disabled }
id = 'modal-dialog-ok-button'
labelKey = { ok.translationKey }
onClick = { submit } />}
</div>
</div>
</FocusLock>
</div>
className = { classes.content }
data-autofocus-inside = 'true'>
{children}
</div>
<div
className = { classes.footer }
data-autofocus-inside = 'true'>
{!back.hidden && <Button
accessibilityLabel = { t(back.translationKey ?? '') }
labelKey = { back.translationKey }
// eslint-disable-next-line react/jsx-handler-names
onClick = { back.onClick }
type = 'secondary' />}
{!cancel.hidden && <Button
accessibilityLabel = { t(cancel.translationKey ?? '') }
labelKey = { cancel.translationKey }
onClick = { onClose }
type = 'tertiary' />}
{!ok.hidden && <Button
accessibilityLabel = { t(ok.translationKey ?? '') }
disabled = { ok.disabled }
id = 'modal-dialog-ok-button'
labelKey = { ok.translationKey }
onClick = { submit } />}
</div>
</BaseDialog>
);
};

View File

@ -0,0 +1,335 @@
import React, { ComponentType, useCallback, useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useDispatch, useSelector } from 'react-redux';
import { makeStyles } from 'tss-react/mui';
import { IReduxState } from '../../../../app/types';
import { hideDialog } from '../../../dialog/actions';
import { IconArrowBack, IconCloseLarge } from '../../../icons/svg';
import { withPixelLineHeight } from '../../../styles/functions.web';
import BaseDialog, { IProps as IBaseProps } from './BaseDialog';
import Button from './Button';
import ClickableIcon from './ClickableIcon';
import ContextMenuItem from './ContextMenuItem';
const MOBILE_BREAKPOINT = 607;
const useStyles = makeStyles()(theme => {
return {
dialog: {
flexDirection: 'row',
height: '560px',
'@media (min-width: 608px) and (max-width: 712px)': {
width: '560px'
},
[`@media (max-width: ${MOBILE_BREAKPOINT}px)`]: {
width: '100%',
position: 'absolute',
top: 0,
left: 0,
bottom: 0
},
'@media (max-width: 448px)': {
height: '100%'
}
},
sidebar: {
display: 'flex',
flexDirection: 'column',
minWidth: '211px',
maxWidth: '100%',
borderRight: `1px solid ${theme.palette.ui03}`,
[`@media (max-width: ${MOBILE_BREAKPOINT}px)`]: {
width: '100%',
borderRight: 'none'
}
},
menuItemMobile: {
paddingLeft: '24px'
},
titleContainer: {
margin: 0,
padding: '24px',
paddingRight: 0,
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
[`@media (max-width: ${MOBILE_BREAKPOINT}px)`]: {
padding: '16px 24px'
}
},
title: {
...withPixelLineHeight(theme.typography.heading5),
color: `${theme.palette.text01} !important`,
margin: 0,
padding: 0
},
contentContainer: {
position: 'relative',
display: 'flex',
padding: '24px',
flexDirection: 'column',
overflow: 'hidden',
width: '100%',
[`@media (max-width: ${MOBILE_BREAKPOINT}px)`]: {
padding: '0'
}
},
buttonContainer: {
width: '100%',
boxSizing: 'border-box',
display: 'flex',
alignItems: 'center',
justifyContent: 'flex-end',
flexGrow: 0,
[`@media (max-width: ${MOBILE_BREAKPOINT}px)`]: {
justifyContent: 'space-between',
padding: '16px 24px'
}
},
backContainer: {
display: 'flex',
alignItems: 'center',
'& > button': {
marginRight: '24px'
}
},
closeIcon: {
'&:focus': {
boxShadow: 'none'
}
},
content: {
flexGrow: 1,
overflowY: 'auto',
width: '100%',
boxSizing: 'border-box',
[`@media (max-width: ${MOBILE_BREAKPOINT}px)`]: {
padding: '0 24px'
}
},
footer: {
justifyContent: 'flex-end',
'& button:last-child': {
marginLeft: '16px'
}
}
};
});
interface IObject {
[key: string]: string | string[] | boolean | number | number[] | {} | undefined;
}
export interface IDialogTab {
className?: string;
component: ComponentType<any>;
icon: Function;
labelKey: string;
name: string;
props?: IObject;
propsUpdateFunction?: (tabState: IObject, newProps: IObject) => IObject;
submit?: Function;
}
interface IProps extends IBaseProps {
defaultTab?: string;
tabs: IDialogTab[];
}
const DialogWithTabs = ({
className,
defaultTab,
titleKey,
tabs
}: IProps) => {
const { classes, cx } = useStyles();
const dispatch = useDispatch();
const { t } = useTranslation();
const [ selectedTab, setSelectedTab ] = useState<string | undefined>(defaultTab ?? tabs[0].name);
const [ tabStates, setTabStates ] = useState(tabs.map(tab => tab.props));
const clientWidth = useSelector((state: IReduxState) => state['features/base/responsive-ui'].clientWidth);
const [ isMobile, setIsMobile ] = useState(false);
useEffect(() => {
if (clientWidth <= MOBILE_BREAKPOINT) {
!isMobile && setIsMobile(true);
} else {
isMobile && setIsMobile(false);
}
}, [ clientWidth, isMobile ]);
useEffect(() => {
if (isMobile) {
setSelectedTab(undefined);
} else {
setSelectedTab(defaultTab ?? tabs[0].name);
}
}, [ isMobile ]);
const back = useCallback(() => {
setSelectedTab(undefined);
}, []);
const onClose = useCallback(() => {
dispatch(hideDialog());
}, []);
const onClick = useCallback((tabName: string) => () => {
setSelectedTab(tabName);
}, []);
const getTabProps = (tabId: number) => {
const tabConfiguration = tabs[tabId];
const currentTabState = tabStates[tabId];
if (tabConfiguration.propsUpdateFunction) {
return tabConfiguration.propsUpdateFunction(
currentTabState ?? {},
tabConfiguration.props ?? {});
}
return { ...currentTabState };
};
const onTabStateChange = useCallback((tabId: number, state: IObject) => {
const newTabStates = [ ...tabStates ];
newTabStates[tabId] = state;
setTabStates(newTabStates);
}, [ tabStates ]);
const onSubmit = useCallback(() => {
tabs.forEach(({ submit }, idx) => {
submit?.(tabStates[idx]);
});
onClose();
}, [ tabs, tabStates ]);
const selectedTabIndex = useMemo(() => {
if (selectedTab) {
return tabs.findIndex(tab => tab.name === selectedTab);
}
return null;
}, [ selectedTab ]);
const selectedTabComponent = useMemo(() => {
if (selectedTabIndex !== null) {
const TabComponent = tabs[selectedTabIndex].component;
return (
<div
className = { tabs[selectedTabIndex].className }
key = { tabs[selectedTabIndex].name }>
<TabComponent
onTabStateChange = { onTabStateChange }
tabId = { selectedTabIndex }
{ ...getTabProps(selectedTabIndex) } />
</div>
);
}
return null;
}, [ selectedTabIndex, tabStates ]);
const closeIcon = useMemo(() => (
<ClickableIcon
accessibilityLabel = { t('dialog.close') }
className = { classes.closeIcon }
icon = { IconCloseLarge }
id = 'modal-header-close-button'
onClick = { onClose } />
), [ onClose ]);
return (
<BaseDialog
className = { cx(classes.dialog, className) }
onClose = { onClose }
size = 'large'>
{(!isMobile || !selectedTab) && (
<div className = { classes.sidebar }>
<div className = { classes.titleContainer }>
<h2 className = { classes.title }>{t(titleKey ?? '')}</h2>
{isMobile && closeIcon}
</div>
{tabs.map(tab => {
const label = t(tab.labelKey);
return (
<ContextMenuItem
accessibilityLabel = { label }
className = { cx(isMobile && classes.menuItemMobile) }
icon = { tab.icon }
key = { tab.name }
onClick = { onClick(tab.name) }
selected = { tab.name === selectedTab }
text = { label } />
);
})}
</div>
)}
{(!isMobile || selectedTab) && (
<div className = { classes.contentContainer }>
<div className = { classes.buttonContainer }>
{isMobile && (
<span className = { classes.backContainer }>
<ClickableIcon
accessibilityLabel = { t('dialog.Back') }
className = { classes.closeIcon }
icon = { IconArrowBack }
id = 'modal-header-back-button'
onClick = { back } />
<h2 className = { classes.title }>
{(selectedTabIndex !== null) && t(tabs[selectedTabIndex].labelKey)}
</h2>
</span>
)}
{closeIcon}
</div>
<div className = { classes.content }>
{selectedTabComponent}
</div>
<div
className = { cx(classes.buttonContainer, classes.footer) }>
<Button
accessibilityLabel = { t('dialog.Cancel') }
id = 'modal-dialog-cancel-button'
labelKey = { 'dialog.Cancel' }
onClick = { onClose }
type = 'tertiary' />
<Button
accessibilityLabel = { t('dialog.Ok') }
id = 'modal-dialog-ok-button'
labelKey = { 'dialog.Ok' }
onClick = { onSubmit } />
</div>
</div>
)}
</BaseDialog>
);
};
export default DialogWithTabs;

View File

@ -2,6 +2,7 @@
import React from 'react';
import { getAvailableDevices } from '../../base/devices/actions.web';
import AbstractDialogTab, {
type Props as AbstractDialogTabProps
} from '../../base/dialog/components/web/AbstractDialogTab';
@ -81,12 +82,6 @@ export type Props = {
*/
hideVideoInputPreview: boolean,
/**
* An optional callback to invoke after the component has completed its
* mount logic.
*/
mountCallback?: Function,
/**
* The id of the audio input device to preview.
*/
@ -176,7 +171,7 @@ class DeviceSelection extends AbstractDialogTab<Props, State> {
this._createVideoInputTrack(this.props.selectedVideoInputId)
])
.catch(err => logger.warn('Failed to initialize preview tracks', err))
.then(() => this.props.mountCallback && this.props.mountCallback());
.then(() => getAvailableDevices());
}
/**

View File

@ -760,7 +760,7 @@ export function isStageFilmstripTopPanel(state: IReduxState, minParticipantCount
export function isStageFilmstripEnabled(state: IReduxState) {
const { filmstrip } = state['features/base/config'];
return !filmstrip?.disableStageFilmstrip && interfaceConfig.VERTICAL_FILMSTRIP;
return Boolean(!filmstrip?.disableStageFilmstrip && interfaceConfig.VERTICAL_FILMSTRIP);
}
/**

View File

@ -104,7 +104,7 @@ export type Props = AbstractDialogTabProps & WithTranslation & {
*
* @augments Component
*/
class MoreTab extends AbstractDialogTab<Props, {}> {
class MoreTab extends AbstractDialogTab<Props, any> {
/**
* Initializes a new {@code MoreTab} instance.
*

View File

@ -4,14 +4,11 @@ import { withStyles } from '@mui/styles';
import React, { Component } from 'react';
import { IReduxState } from '../../../app/types';
import { getAvailableDevices } from '../../../base/devices/actions';
// @ts-ignore
import { DialogWithTabs } from '../../../base/dialog';
import { hideDialog } from '../../../base/dialog/actions';
import { IconBell, IconCalendar, IconGear, IconModerator, IconUser, IconVolumeUp } from '../../../base/icons/svg';
import { connect } from '../../../base/redux/functions';
import { withPixelLineHeight } from '../../../base/styles/functions.web';
// @ts-ignore
import { isCalendarEnabled } from '../../../calendar-sync';
import DialogWithTabs, { IDialogTab } from '../../../base/ui/components/web/DialogWithTabs';
import { isCalendarEnabled } from '../../../calendar-sync/functions.web';
import {
DeviceSelection,
getDeviceSelectionDialogProps,
@ -49,11 +46,7 @@ interface IProps {
/**
* Information about the tabs to be rendered.
*/
_tabs: Array<{
name: string;
onMount: () => void;
submit: () => void;
}>;
_tabs: IDialogTab[];
/**
* An object containing the CSS classes.
@ -139,7 +132,9 @@ const styles = (theme: Theme) => {
'& .profile-edit': {
display: 'flex',
width: '100%'
width: '100%',
padding: '0 2px',
boxSizing: 'border-box'
},
'& .profile-edit-field': {
@ -220,18 +215,6 @@ const styles = (theme: Theme) => {
* @augments Component
*/
class SettingsDialog extends Component<IProps> {
/**
* Initializes a new {@code ConnectedSettingsDialog} instance.
*
* @param {IProps} props - The React {@code Component} props to initialize
* the new {@code ConnectedSettingsDialog} instance with.
*/
constructor(props: IProps) {
super(props);
// Bind event handlers so they are only bound once for every instance.
this._closeDialog = this._closeDialog.bind(this);
}
/**
* Implements React's {@link Component#render()}.
@ -241,46 +224,23 @@ class SettingsDialog extends Component<IProps> {
*/
render() {
const { _tabs, defaultTab, dispatch } = this.props;
const onSubmit = this._closeDialog;
const defaultTabIdx
= _tabs.findIndex(({ name }) => name === defaultTab);
const correctDefaultTab = _tabs.find(tab => tab.name === defaultTab)?.name;
const tabs = _tabs.map(tab => {
return {
...tab,
onMount: tab.onMount
// @ts-ignore
? (...args: any) => dispatch(tab.onMount(...args))
: undefined,
submit: (...args: any) => tab.submit
// @ts-ignore
&& dispatch(tab.submit(...args))
};
});
return (
<DialogWithTabs
closeDialog = { this._closeDialog }
cssClassName = 'settings-dialog'
defaultTab = {
defaultTabIdx === -1 ? undefined : defaultTabIdx
}
onSubmit = { onSubmit }
className = 'settings-dialog'
defaultTab = { correctDefaultTab }
tabs = { tabs }
titleKey = 'settings.title' />
);
}
/**
* Callback invoked to close the dialog without saving changes.
*
* @private
* @returns {void}
*/
_closeDialog() {
this.props.dispatch(hideDialog());
}
}
/**
@ -309,14 +269,13 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {
const showCalendarSettings
= configuredTabs.includes('calendar') && isCalendarEnabled(state);
const showSoundsSettings = configuredTabs.includes('sounds');
const tabs = [];
const tabs: IDialogTab[] = [];
if (showDeviceSettings) {
tabs.push({
name: SETTINGS_TABS.DEVICES,
component: DeviceSelection,
label: 'settings.devices',
onMount: getAvailableDevices,
labelKey: 'settings.devices',
props: getDeviceSelectionDialogProps(state, isDisplayedOnWelcomePage),
propsUpdateFunction: (tabState: any, newProps: any) => {
// Ensure the device selection tab gets updated when new devices
@ -332,8 +291,9 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {
selectedVideoInputId: tabState.selectedVideoInputId
};
},
styles: `settings-pane ${classes.settingsDialog} devices-pane`,
submit: (newState: any) => submitDeviceSelectionTab(newState, isDisplayedOnWelcomePage)
className: `settings-pane ${classes.settingsDialog} devices-pane`,
submit: (newState: any) => submitDeviceSelectionTab(newState, isDisplayedOnWelcomePage),
icon: IconVolumeUp
});
}
@ -341,10 +301,11 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {
tabs.push({
name: SETTINGS_TABS.PROFILE,
component: ProfileTab,
label: 'profile.title',
labelKey: 'profile.title',
props: getProfileTabProps(state),
styles: `settings-pane ${classes.settingsDialog} profile-pane`,
submit: submitProfileTab
className: `settings-pane ${classes.settingsDialog} profile-pane`,
submit: submitProfileTab,
icon: IconUser
});
}
@ -352,7 +313,7 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {
tabs.push({
name: SETTINGS_TABS.MODERATOR,
component: ModeratorTab,
label: 'settings.moderator',
labelKey: 'settings.moderator',
props: moderatorTabProps,
propsUpdateFunction: (tabState: any, newProps: any) => {
// Updates tab props, keeping users selection
@ -365,8 +326,9 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {
startReactionsMuted: tabState?.startReactionsMuted
};
},
styles: `settings-pane ${classes.settingsDialog} moderator-pane`,
submit: submitModeratorTab
className: `settings-pane ${classes.settingsDialog} moderator-pane`,
submit: submitModeratorTab,
icon: IconModerator
});
}
@ -374,8 +336,9 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {
tabs.push({
name: SETTINGS_TABS.CALENDAR,
component: CalendarTab,
label: 'settings.calendar.title',
styles: `settings-pane ${classes.settingsDialog} calendar-pane`
labelKey: 'settings.calendar.title',
className: `settings-pane ${classes.settingsDialog} calendar-pane`,
icon: IconCalendar
});
}
@ -383,18 +346,21 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {
tabs.push({
name: SETTINGS_TABS.SOUNDS,
component: SoundsTab,
label: 'settings.sounds',
labelKey: 'settings.sounds',
props: getSoundsTabProps(state),
styles: `settings-pane ${classes.settingsDialog} profile-pane`,
submit: submitSoundsTab
className: `settings-pane ${classes.settingsDialog} profile-pane`,
submit: submitSoundsTab,
icon: IconBell
});
}
if (showMoreTab) {
tabs.push({
name: SETTINGS_TABS.MORE,
// @ts-ignore
component: MoreTab,
label: 'settings.more',
labelKey: 'settings.more',
props: moreTabProps,
propsUpdateFunction: (tabState: any, newProps: any) => {
// Updates tab props, keeping users selection
@ -409,8 +375,9 @@ function _mapStateToProps(state: IReduxState, ownProps: any) {
maxStageParticipants: tabState?.maxStageParticipants
};
},
styles: `settings-pane ${classes.settingsDialog} more-pane`,
submit: submitMoreTab
className: `settings-pane ${classes.settingsDialog} more-pane`,
submit: submitMoreTab,
icon: IconGear
});
}

View File

@ -117,7 +117,7 @@ export function getMoreTabProps(stateful: IStateful) {
const state = toState(stateful);
const framerate = state['features/screen-share'].captureFrameRate ?? SS_DEFAULT_FRAME_RATE;
const language = i18next.language || DEFAULT_LANGUAGE;
const configuredTabs = interfaceConfig.SETTINGS_SECTIONS || [];
const configuredTabs: string[] = interfaceConfig.SETTINGS_SECTIONS || [];
const enabledNotifications = getNotificationsMap(stateful);
const stageFilmstripEnabled = isStageFilmstripEnabled(state);