2020-08-02 09:00:04 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Constants from "~/common/constants";
|
2020-11-11 04:44:21 +03:00
|
|
|
import * as Validations from "~/common/validations";
|
2021-02-15 12:34:49 +03:00
|
|
|
import * as Events from "~/common/custom-events";
|
2020-08-02 09:00:04 +03:00
|
|
|
|
2020-11-17 15:53:15 +03:00
|
|
|
import UnityFrame from "~/components/core/UnityFrame";
|
2021-02-16 21:03:59 +03:00
|
|
|
import MarkdownFrame from "~/components/core/MarkdownFrame";
|
2020-11-17 15:53:15 +03:00
|
|
|
|
2020-11-30 08:24:22 +03:00
|
|
|
import { css } from "@emotion/react";
|
2020-08-02 09:00:04 +03:00
|
|
|
|
|
|
|
const STYLES_FAILURE = css`
|
|
|
|
background-color: ${Constants.system.pitchBlack};
|
|
|
|
color: ${Constants.system.white};
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
font-size: 88px;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
width: 100%;
|
|
|
|
min-height: 10%;
|
|
|
|
height: 100%;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_OBJECT = css`
|
|
|
|
display: block;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
width: 100%;
|
|
|
|
min-height: 10%;
|
|
|
|
height: 100%;
|
2020-08-02 10:29:24 +03:00
|
|
|
user-select: none;
|
2020-08-02 09:00:04 +03:00
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_ASSET = css`
|
2020-08-02 10:29:24 +03:00
|
|
|
user-select: none;
|
2020-08-02 09:00:04 +03:00
|
|
|
width: 100%;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
min-height: 10%;
|
|
|
|
height: 100%;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
position: relative;
|
|
|
|
`;
|
|
|
|
|
|
|
|
const STYLES_IMAGE = css`
|
2020-08-02 10:29:24 +03:00
|
|
|
user-select: none;
|
2020-08-02 09:00:04 +03:00
|
|
|
display: block;
|
|
|
|
max-width: 100%;
|
|
|
|
max-height: 100%;
|
|
|
|
`;
|
|
|
|
|
2020-09-16 12:16:46 +03:00
|
|
|
const typeMap = {
|
|
|
|
"video/quicktime": "video/mp4",
|
|
|
|
};
|
|
|
|
|
2020-08-20 23:33:08 +03:00
|
|
|
export default class SlateMediaObject extends React.Component {
|
2021-02-15 12:04:02 +03:00
|
|
|
openLink = (url) => {
|
2021-02-15 13:08:49 +03:00
|
|
|
let { isMobile, data } = this.props;
|
|
|
|
const isPDF = data.type && data.type.startsWith("application/pdf");
|
2021-02-15 12:04:02 +03:00
|
|
|
|
2021-02-15 13:08:49 +03:00
|
|
|
if (isPDF && isMobile) {
|
2021-02-15 12:04:02 +03:00
|
|
|
window.open(url, "_blank");
|
2021-02-15 12:34:49 +03:00
|
|
|
Events.dispatchCustomEvent({ name: "slate-global-close-carousel", detail: {} });
|
|
|
|
|
|
|
|
return;
|
2021-02-15 12:04:02 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const url = this.props.data.url;
|
|
|
|
this.openLink(url);
|
|
|
|
}
|
|
|
|
|
2020-08-02 09:00:04 +03:00
|
|
|
render() {
|
2020-11-28 04:19:30 +03:00
|
|
|
const url = this.props.data.url;
|
2020-08-02 09:41:18 +03:00
|
|
|
const type = this.props.data.type ? this.props.data.type : "LEGACY_NO_TYPE";
|
2020-09-16 12:16:46 +03:00
|
|
|
const playType = typeMap[type] ? typeMap[type] : type;
|
2020-12-08 21:04:35 +03:00
|
|
|
|
2021-02-15 12:04:02 +03:00
|
|
|
let { isMobile } = this.props;
|
|
|
|
|
2020-08-21 10:07:39 +03:00
|
|
|
let element = <div css={STYLES_FAILURE}>No Preview</div>;
|
2020-11-17 21:22:13 +03:00
|
|
|
|
2020-08-02 09:41:18 +03:00
|
|
|
if (type.startsWith("application/pdf")) {
|
2021-01-15 00:03:21 +03:00
|
|
|
return (
|
2021-02-15 12:04:02 +03:00
|
|
|
<>
|
|
|
|
{!isMobile && (
|
|
|
|
<object
|
|
|
|
css={STYLES_OBJECT}
|
|
|
|
style={{ width: "calc(100% - 64px)" }}
|
|
|
|
data={url}
|
|
|
|
type={type}
|
|
|
|
key={url}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
</>
|
2021-01-15 00:03:21 +03:00
|
|
|
);
|
2020-08-02 09:00:04 +03:00
|
|
|
}
|
|
|
|
|
2020-08-02 10:29:24 +03:00
|
|
|
if (type.startsWith("video/")) {
|
2021-02-01 19:02:49 +03:00
|
|
|
const autoPlay = this.props?.data?.settings?.autoPlay || false;
|
2020-09-16 12:16:46 +03:00
|
|
|
return (
|
2021-01-15 00:03:21 +03:00
|
|
|
<video
|
|
|
|
playsInline
|
|
|
|
controls
|
2021-02-01 19:02:49 +03:00
|
|
|
autoPlay={autoPlay}
|
2021-01-15 00:03:21 +03:00
|
|
|
name="media"
|
|
|
|
type={playType}
|
|
|
|
css={STYLES_OBJECT}
|
|
|
|
key={url}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
>
|
2020-09-16 12:16:46 +03:00
|
|
|
<source src={url} type={playType} />
|
2021-02-26 18:20:41 +03:00
|
|
|
{/** Note(Amine): fallback if video type isn't supported (example .mov) */}
|
|
|
|
<source src={url} type="video/mp4" />
|
2020-08-02 10:29:24 +03:00
|
|
|
</video>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-04 06:15:24 +03:00
|
|
|
if (type.startsWith("audio/")) {
|
2020-09-16 12:16:46 +03:00
|
|
|
return (
|
2020-08-04 06:15:24 +03:00
|
|
|
<div css={STYLES_ASSET}>
|
2021-01-15 00:03:21 +03:00
|
|
|
<audio
|
|
|
|
controls
|
|
|
|
name="media"
|
|
|
|
key={url}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
>
|
2020-09-16 12:16:46 +03:00
|
|
|
<source src={url} type={playType} />
|
2020-08-04 06:15:24 +03:00
|
|
|
</audio>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-03-18 17:39:02 +03:00
|
|
|
if (this.props.data.name.endsWith(".md") || type.startsWith("text/plain")) {
|
2021-02-18 20:39:44 +03:00
|
|
|
return <MarkdownFrame date={this.props.data.date} url={this.props.data.url} />;
|
2021-02-15 20:23:56 +03:00
|
|
|
}
|
|
|
|
|
2020-11-11 04:44:21 +03:00
|
|
|
if (Validations.isPreviewableImage(type)) {
|
2020-09-16 12:16:46 +03:00
|
|
|
return (
|
2020-08-02 09:00:04 +03:00
|
|
|
<div css={STYLES_ASSET}>
|
2021-01-15 00:03:21 +03:00
|
|
|
<img
|
|
|
|
css={STYLES_IMAGE}
|
|
|
|
src={url}
|
|
|
|
onClick={(e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
}}
|
|
|
|
/>
|
2020-08-02 09:00:04 +03:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-11-18 07:34:37 +03:00
|
|
|
// TODO(jim): We will need to revisit this later.
|
|
|
|
if (type.startsWith("application/unity")) {
|
2020-12-08 21:04:35 +03:00
|
|
|
const unityGameConfig = this.props.data.unityGameConfig;
|
|
|
|
const unityGameLoader = this.props.data.unityGameLoader;
|
|
|
|
|
2020-12-08 14:00:15 +03:00
|
|
|
return (
|
2021-01-11 00:19:54 +03:00
|
|
|
<UnityFrame
|
|
|
|
url={url}
|
|
|
|
unityGameConfig={unityGameConfig}
|
|
|
|
unityGameLoader={unityGameLoader}
|
|
|
|
key={url}
|
|
|
|
/>
|
2020-12-08 14:00:15 +03:00
|
|
|
);
|
2020-11-17 15:53:15 +03:00
|
|
|
}
|
|
|
|
|
2020-08-21 10:07:39 +03:00
|
|
|
return element;
|
2020-08-02 09:00:04 +03:00
|
|
|
}
|
|
|
|
}
|