fix: open pdf in new tab on mobile devices

This commit is contained in:
Akuoko Daniel Jnr 2021-02-15 09:04:02 +00:00
parent 03bb1eb5f1
commit d2aa415f9d
No known key found for this signature in database
GPG Key ID: 1C95803CACD3E9DC
2 changed files with 33 additions and 11 deletions

View File

@ -55,25 +55,44 @@ const typeMap = {
};
export default class SlateMediaObject extends React.Component {
openLink = (url) => {
let { isMobile } = this.props;
if (isMobile) {
window.open(url, "_blank");
}
};
componentDidMount() {
const url = this.props.data.url;
this.openLink(url);
}
render() {
const url = this.props.data.url;
const type = this.props.data.type ? this.props.data.type : "LEGACY_NO_TYPE";
const playType = typeMap[type] ? typeMap[type] : type;
let { isMobile } = this.props;
let element = <div css={STYLES_FAILURE}>No Preview</div>;
if (type.startsWith("application/pdf")) {
return (
<object
css={STYLES_OBJECT}
style={{ width: "calc(100% - 64px)" }}
data={url}
type={type}
key={url}
onClick={(e) => {
e.stopPropagation();
}}
/>
<>
{!isMobile && (
<object
css={STYLES_OBJECT}
style={{ width: "calc(100% - 64px)" }}
data={url}
type={type}
key={url}
onClick={(e) => {
e.stopPropagation();
}}
/>
)}
</>
);
}

View File

@ -260,7 +260,10 @@ export class GlobalCarousel extends React.Component {
} else if (this.props.carouselType === "DATA") {
data.url = Strings.getCIDGatewayURL(data.cid);
}
let slide = <SlateMediaObject data={data} />;
let { mobile } = this.props;
let slide = <SlateMediaObject data={data} isMobile={mobile} />;
return (
<div css={STYLES_ROOT}>
<Alert