2020-08-02 09:00:04 +03:00
|
|
|
import * as React from "react";
|
|
|
|
import * as Constants from "~/common/constants";
|
|
|
|
|
|
|
|
import { css } from "@emotion/react";
|
|
|
|
|
|
|
|
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%;
|
|
|
|
`;
|
|
|
|
|
|
|
|
export default class MediaObject extends React.Component {
|
|
|
|
render() {
|
|
|
|
const name = `${this.props.data.name}`;
|
2020-08-10 13:10:44 +03:00
|
|
|
const url = this.props.data.url ? this.props.data.url : `https://hub.textile.io${this.props.data.ipfs}`;
|
2020-08-02 09:41:18 +03:00
|
|
|
const type = this.props.data.type ? this.props.data.type : "LEGACY_NO_TYPE";
|
2020-08-02 09:00:04 +03:00
|
|
|
|
2020-08-02 09:41:18 +03:00
|
|
|
if (type.startsWith("application/pdf")) {
|
|
|
|
return <object css={STYLES_OBJECT} data={url} type={type} />;
|
2020-08-02 09:00:04 +03:00
|
|
|
}
|
|
|
|
|
2020-08-10 13:10:44 +03:00
|
|
|
if (type.startsWith("application/epub")) {
|
|
|
|
return <div css={STYLES_FAILURE}>No Preview</div>;
|
|
|
|
}
|
|
|
|
|
2020-08-02 10:29:24 +03:00
|
|
|
if (type.startsWith("video/")) {
|
|
|
|
return (
|
|
|
|
<video autoPlay controls name="media" css={STYLES_OBJECT}>
|
|
|
|
<source src={url} type={type} />
|
|
|
|
</video>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-04 06:15:24 +03:00
|
|
|
if (type.startsWith("audio/")) {
|
|
|
|
return (
|
|
|
|
<div css={STYLES_ASSET}>
|
|
|
|
<audio autoPlay controls name="media">
|
|
|
|
<source src={url} type={type} />
|
|
|
|
</audio>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-10 13:10:44 +03:00
|
|
|
if (type.startsWith("image/")) {
|
2020-08-02 09:41:18 +03:00
|
|
|
return (
|
2020-08-02 09:00:04 +03:00
|
|
|
<div css={STYLES_ASSET}>
|
|
|
|
<img css={STYLES_IMAGE} src={url} />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-02 09:41:18 +03:00
|
|
|
return <div css={STYLES_FAILURE}>No Preview</div>;
|
2020-08-02 09:00:04 +03:00
|
|
|
}
|
|
|
|
}
|