2022-11-02 22:54:57 +08:00
|
|
|
import React from 'react';
|
2023-03-10 19:30:46 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2022-11-02 22:54:57 +08:00
|
|
|
import { defineMessages } from 'react-intl';
|
|
|
|
import { safeMatch } from '/imports/utils/string-utils';
|
2024-01-19 21:44:27 +08:00
|
|
|
import { isUrlValid } from '/imports/ui/components/external-video-player/service';
|
2022-11-02 22:54:57 +08:00
|
|
|
import BBBMenu from '/imports/ui/components/common/menu/component';
|
|
|
|
import Styled from './styles';
|
|
|
|
|
|
|
|
const intlMessages = defineMessages({
|
|
|
|
externalVideo: {
|
|
|
|
id: 'app.smartMediaShare.externalVideo',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2024-01-19 21:44:27 +08:00
|
|
|
const createAction = (url, startWatching) => {
|
|
|
|
const hasHttps = url?.startsWith('https://');
|
2023-07-24 08:03:22 +08:00
|
|
|
const finalUrl = hasHttps ? url : `https://${url}`;
|
2024-01-19 21:44:27 +08:00
|
|
|
const label = hasHttps ? url?.replace('https://', '') : url;
|
2023-07-24 08:03:22 +08:00
|
|
|
|
|
|
|
if (isUrlValid(finalUrl)) {
|
|
|
|
return {
|
|
|
|
label,
|
|
|
|
onClick: () => startWatching(finalUrl),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-11-02 22:54:57 +08:00
|
|
|
export const SmartMediaShare = (props) => {
|
|
|
|
const {
|
2024-01-19 21:44:27 +08:00
|
|
|
currentSlide, intl, isMobile, isRTL, startWatching,
|
2022-11-02 22:54:57 +08:00
|
|
|
} = props;
|
2023-07-24 08:03:22 +08:00
|
|
|
const linkPatt = /(https?:\/\/.*?)(?=\s|$)/g;
|
2023-01-17 01:13:22 +08:00
|
|
|
const externalLinks = safeMatch(linkPatt, currentSlide?.content?.replace(/[\r\n]/g, ' '), false);
|
2022-11-02 22:54:57 +08:00
|
|
|
if (!externalLinks) return null;
|
|
|
|
|
|
|
|
const actions = [];
|
2023-07-24 08:03:22 +08:00
|
|
|
|
|
|
|
externalLinks?.forEach((l) => {
|
2024-01-19 21:44:27 +08:00
|
|
|
const action = createAction(l, startWatching);
|
2023-07-24 08:03:22 +08:00
|
|
|
if (action) actions.push(action);
|
2022-11-02 22:54:57 +08:00
|
|
|
});
|
|
|
|
|
2022-11-03 21:43:06 +08:00
|
|
|
if (actions?.length === 0) return null;
|
|
|
|
|
2022-11-02 22:54:57 +08:00
|
|
|
const customStyles = { top: '-1rem' };
|
|
|
|
|
|
|
|
return (
|
|
|
|
<BBBMenu
|
|
|
|
customStyles={!isMobile ? customStyles : null}
|
|
|
|
trigger={(
|
|
|
|
<Styled.QuickVideoButton
|
|
|
|
role="button"
|
|
|
|
label={intl.formatMessage(intlMessages.externalVideo)}
|
2023-07-26 02:05:00 +08:00
|
|
|
color="primary"
|
2022-11-02 22:54:57 +08:00
|
|
|
circle
|
|
|
|
icon="external-video"
|
|
|
|
size="md"
|
|
|
|
onClick={() => null}
|
|
|
|
hideLabel
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
actions={actions}
|
|
|
|
opts={{
|
|
|
|
id: 'external-video-dropdown-menu',
|
|
|
|
keepMounted: true,
|
|
|
|
transitionDuration: 0,
|
|
|
|
elevation: 3,
|
2023-05-10 09:31:48 +08:00
|
|
|
getcontentanchorel: null,
|
2022-11-02 22:54:57 +08:00
|
|
|
fullwidth: 'true',
|
|
|
|
anchorOrigin: { vertical: 'top', horizontal: isRTL ? 'right' : 'left' },
|
|
|
|
transformOrigin: { vertical: 'bottom', horizontal: isRTL ? 'right' : 'left' },
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default SmartMediaShare;
|
2023-03-10 19:30:46 +08:00
|
|
|
|
|
|
|
SmartMediaShare.propTypes = {
|
|
|
|
currentSlide: PropTypes.shape({
|
|
|
|
content: PropTypes.string.isRequired,
|
|
|
|
}),
|
|
|
|
intl: PropTypes.shape({
|
|
|
|
formatMessage: PropTypes.func.isRequired,
|
|
|
|
}).isRequired,
|
|
|
|
isMobile: PropTypes.bool.isRequired,
|
|
|
|
isRTL: PropTypes.bool.isRequired,
|
|
|
|
};
|
|
|
|
|
|
|
|
SmartMediaShare.defaultProps = {
|
|
|
|
currentSlide: undefined,
|
|
|
|
};
|