2022-02-23 01:41:16 +08:00
|
|
|
import React, { useState } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2023-11-28 19:14:22 +08:00
|
|
|
import { LAYOUT_TYPE, CAMERADOCK_POSITION, HIDDEN_LAYOUTS } from '/imports/ui/components/layout/enums';
|
2022-02-23 01:41:16 +08:00
|
|
|
import SettingsService from '/imports/ui/components/settings/service';
|
2022-03-15 22:54:33 +08:00
|
|
|
import deviceInfo from '/imports/utils/deviceInfo';
|
2022-03-10 05:28:12 +08:00
|
|
|
import Button from '/imports/ui/components/common/button/component';
|
2022-03-15 22:54:33 +08:00
|
|
|
import Styled from './styles';
|
2022-02-23 01:41:16 +08:00
|
|
|
|
|
|
|
const LayoutModalComponent = (props) => {
|
|
|
|
const {
|
|
|
|
intl,
|
2023-03-22 01:55:43 +08:00
|
|
|
setIsOpen,
|
2023-03-04 05:59:47 +08:00
|
|
|
isModerator,
|
2022-02-23 01:41:16 +08:00
|
|
|
isPresenter,
|
|
|
|
application,
|
|
|
|
updateSettings,
|
2023-04-12 23:51:23 +08:00
|
|
|
onRequestClose,
|
|
|
|
isOpen,
|
2022-02-23 01:41:16 +08:00
|
|
|
} = props;
|
|
|
|
|
|
|
|
const [selectedLayout, setSelectedLayout] = useState(application.selectedLayout);
|
|
|
|
|
|
|
|
const BASE_NAME = Meteor.settings.public.app.basename;
|
2022-03-15 22:54:33 +08:00
|
|
|
|
2023-03-31 04:00:41 +08:00
|
|
|
const LAYOUTS_PATH = `${BASE_NAME}/resources/images/layouts/`;
|
2022-02-23 01:41:16 +08:00
|
|
|
const isKeepPushingLayoutEnabled = SettingsService.isKeepPushingLayoutEnabled();
|
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
title: {
|
|
|
|
id: 'app.layout.modal.title',
|
|
|
|
description: 'Modal title',
|
|
|
|
},
|
2023-07-07 20:53:58 +08:00
|
|
|
update: {
|
|
|
|
id: 'app.layout.modal.update',
|
2022-02-23 01:41:16 +08:00
|
|
|
description: 'Modal confirm button',
|
|
|
|
},
|
2023-07-07 20:53:58 +08:00
|
|
|
updateAll: {
|
|
|
|
id: 'app.layout.modal.updateAll',
|
|
|
|
description: 'Modal updateAll button',
|
2022-02-23 01:41:16 +08:00
|
|
|
},
|
|
|
|
layoutLabel: {
|
|
|
|
id: 'app.layout.modal.layoutLabel',
|
|
|
|
description: 'Layout label',
|
|
|
|
},
|
|
|
|
layoutToastLabel: {
|
|
|
|
id: 'app.layout.modal.layoutToastLabel',
|
|
|
|
description: 'Layout toast label',
|
|
|
|
},
|
|
|
|
customLayout: {
|
|
|
|
id: 'app.layout.style.custom',
|
|
|
|
description: 'label for custom layout style',
|
|
|
|
},
|
|
|
|
smartLayout: {
|
|
|
|
id: 'app.layout.style.smart',
|
|
|
|
description: 'label for smart layout style',
|
|
|
|
},
|
|
|
|
presentationFocusLayout: {
|
|
|
|
id: 'app.layout.style.presentationFocus',
|
|
|
|
description: 'label for presentationFocus layout style',
|
|
|
|
},
|
|
|
|
videoFocusLayout: {
|
|
|
|
id: 'app.layout.style.videoFocus',
|
|
|
|
description: 'label for videoFocus layout style',
|
|
|
|
},
|
2022-09-29 21:20:38 +08:00
|
|
|
layoutSingular: {
|
|
|
|
id: 'app.layout.modal.layoutSingular',
|
|
|
|
description: 'label for singular layout',
|
|
|
|
},
|
2022-09-29 22:46:49 +08:00
|
|
|
layoutBtnDesc: {
|
|
|
|
id: 'app.layout.modal.layoutBtnDesc',
|
|
|
|
description: 'label for singular layout',
|
|
|
|
},
|
2022-02-23 01:41:16 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
const handleSwitchLayout = (e) => {
|
|
|
|
setSelectedLayout(e);
|
|
|
|
};
|
|
|
|
|
2023-07-07 20:53:58 +08:00
|
|
|
const handleUpdateLayout = (updateAll) => {
|
2022-02-23 01:41:16 +08:00
|
|
|
const obj = {
|
|
|
|
application:
|
2023-11-24 15:07:41 +08:00
|
|
|
{ ...application, selectedLayout, pushLayout: updateAll },
|
2022-02-23 01:41:16 +08:00
|
|
|
};
|
2023-03-30 02:38:55 +08:00
|
|
|
updateSettings(obj, intlMessages.layoutToastLabel);
|
2023-03-22 01:55:43 +08:00
|
|
|
setIsOpen(false);
|
2022-02-23 01:41:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const renderPushLayoutsOptions = () => {
|
2023-03-04 05:59:47 +08:00
|
|
|
if (!isModerator && !isPresenter) {
|
2022-02-23 01:41:16 +08:00
|
|
|
return null;
|
|
|
|
}
|
2022-04-26 03:57:11 +08:00
|
|
|
|
2022-05-28 05:11:42 +08:00
|
|
|
if (isKeepPushingLayoutEnabled) {
|
2022-02-23 01:41:16 +08:00
|
|
|
return (
|
2023-07-07 20:53:58 +08:00
|
|
|
<Styled.BottomButton
|
|
|
|
label={intl.formatMessage(intlMessages.updateAll)}
|
|
|
|
onClick={() => handleUpdateLayout(true)}
|
|
|
|
color="secondary"
|
2023-07-11 03:28:00 +08:00
|
|
|
data-test="updateEveryoneLayoutBtn"
|
2023-07-07 20:53:58 +08:00
|
|
|
/>
|
2022-02-23 01:41:16 +08:00
|
|
|
);
|
|
|
|
}
|
2022-03-09 00:48:48 +08:00
|
|
|
return null;
|
2022-02-23 01:41:16 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const renderLayoutButtons = () => (
|
2022-03-15 22:54:33 +08:00
|
|
|
<Styled.ButtonsContainer>
|
|
|
|
{Object.values(LAYOUT_TYPE)
|
2023-11-28 19:14:22 +08:00
|
|
|
.filter((layout) => !HIDDEN_LAYOUTS.includes(layout))
|
2022-02-23 01:41:16 +08:00
|
|
|
.map((layout) => (
|
2022-03-15 22:54:33 +08:00
|
|
|
<Styled.ButtonLayoutContainer key={layout}>
|
|
|
|
<Styled.LayoutBtn
|
2022-02-23 01:41:16 +08:00
|
|
|
label=""
|
2022-09-29 22:46:49 +08:00
|
|
|
customIcon={(
|
|
|
|
<Styled.IconSvg
|
|
|
|
src={`${LAYOUTS_PATH}${layout}.svg`}
|
|
|
|
alt={`${layout} ${intl.formatMessage(intlMessages.layoutSingular)}`}
|
|
|
|
/>
|
2023-11-24 15:07:41 +08:00
|
|
|
)}
|
2023-06-27 23:47:59 +08:00
|
|
|
onClick={() => {
|
|
|
|
handleSwitchLayout(layout);
|
|
|
|
if (layout === LAYOUT_TYPE.CUSTOM_LAYOUT && application.selectedLayout !== layout) {
|
|
|
|
document.getElementById('layout')?.setAttribute('data-cam-position', CAMERADOCK_POSITION.CONTENT_TOP);
|
|
|
|
}
|
|
|
|
}}
|
2022-03-15 22:54:33 +08:00
|
|
|
active={(layout === selectedLayout).toString()}
|
2022-09-29 22:46:49 +08:00
|
|
|
aria-describedby="layout-btn-desc"
|
2023-01-24 01:31:01 +08:00
|
|
|
data-test={`${layout}Layout`}
|
2022-02-23 01:41:16 +08:00
|
|
|
/>
|
2023-07-06 22:00:44 +08:00
|
|
|
<Styled.LabelLayoutNames aria-hidden>{intl.formatMessage(intlMessages[`${layout}Layout`])}</Styled.LabelLayoutNames>
|
2022-03-15 22:54:33 +08:00
|
|
|
</Styled.ButtonLayoutContainer>
|
2022-02-23 01:41:16 +08:00
|
|
|
))}
|
2022-03-15 22:54:33 +08:00
|
|
|
</Styled.ButtonsContainer>
|
2022-02-23 01:41:16 +08:00
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
2022-03-15 22:54:33 +08:00
|
|
|
<Styled.LayoutModal
|
|
|
|
contentLabel={intl.formatMessage(intlMessages.title)}
|
|
|
|
shouldShowCloseButton
|
|
|
|
shouldCloseOnOverlayClick
|
|
|
|
isPhone={deviceInfo.isPhone}
|
|
|
|
data-test="layoutChangeModal"
|
2023-03-22 01:55:43 +08:00
|
|
|
onRequestClose={() => setIsOpen(false)}
|
2022-11-11 02:09:21 +08:00
|
|
|
title={intl.formatMessage(intlMessages.title)}
|
2023-04-12 23:51:23 +08:00
|
|
|
{...{
|
|
|
|
isOpen,
|
|
|
|
onRequestClose,
|
|
|
|
}}
|
2022-02-23 01:41:16 +08:00
|
|
|
>
|
2022-03-15 22:54:33 +08:00
|
|
|
<Styled.Content>
|
|
|
|
<Styled.BodyContainer>
|
2022-02-23 01:41:16 +08:00
|
|
|
{renderLayoutButtons()}
|
2022-03-15 22:54:33 +08:00
|
|
|
</Styled.BodyContainer>
|
|
|
|
</Styled.Content>
|
|
|
|
<Styled.ButtonBottomContainer>
|
2023-07-07 20:53:58 +08:00
|
|
|
{renderPushLayoutsOptions()}
|
2022-03-15 22:54:33 +08:00
|
|
|
<Button
|
|
|
|
color="primary"
|
2023-07-07 20:53:58 +08:00
|
|
|
label={intl.formatMessage(intlMessages.update)}
|
|
|
|
onClick={() => handleUpdateLayout(false)}
|
2023-07-11 03:28:00 +08:00
|
|
|
data-test="updateLayoutBtn"
|
2022-03-15 22:54:33 +08:00
|
|
|
/>
|
|
|
|
</Styled.ButtonBottomContainer>
|
2022-09-29 22:46:49 +08:00
|
|
|
<div style={{ display: 'none' }} id="layout-btn-desc">{intl.formatMessage(intlMessages.layoutBtnDesc)}</div>
|
2022-03-15 22:54:33 +08:00
|
|
|
</Styled.LayoutModal>
|
2022-02-23 01:41:16 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
2023-03-04 05:59:47 +08:00
|
|
|
isModerator: PropTypes.bool.isRequired,
|
2022-02-23 01:41:16 +08:00
|
|
|
isPresenter: PropTypes.bool.isRequired,
|
|
|
|
showToggleLabel: PropTypes.bool.isRequired,
|
|
|
|
application: PropTypes.shape({
|
|
|
|
selectedLayout: PropTypes.string.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
updateSettings: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
LayoutModalComponent.propTypes = propTypes;
|
|
|
|
|
2023-03-22 01:55:43 +08:00
|
|
|
export default injectIntl(LayoutModalComponent);
|