Skip to content

Commit

Permalink
Show nicer error if pdf fails to load
Browse files Browse the repository at this point in the history
  • Loading branch information
miko committed Nov 19, 2024
1 parent 820e2f5 commit 69dd625
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 2 additions & 0 deletions static/app-strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2965,6 +2965,8 @@
"Default action when clicking a playlist.": "Default action when clicking a playlist.",
"Default playlist action": "Default playlist action",
"Optionally the email change can be requested using \"Submit Feedback\" button below.": "Optionally the email change can be requested using \"Submit Feedback\" button below.",
"Failed to load": "Failed to load",
"This file failed to load. Some browser extension may be blocking it. If the issue persists, please reach out to [email protected]": "This file failed to load. Some browser extension may be blocking it. If the issue persists, please reach out to [email protected]",

"--end--": "--end--"
}
27 changes: 25 additions & 2 deletions ui/component/IframeReact/view.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// @flow
import React from 'react';
import Card from 'component/common/card';

type Props = {
fullHeight: boolean,
Expand All @@ -10,11 +11,20 @@ type Props = {
export default function I18nMessage(props: Props) {
const { src, title } = props;

// const iframeRef = useRef();
const [failedToLoadSrc, setFailedToLoadSrc] = React.useState(false);
// const iframeRef = React.useRef();

// const [iframeHeight, setIframeHeight] = useState('80vh');

function onLoad() {
const checkIfSrcCanBeLoaded = async () => {
const response = await fetch(src);
if (response.status !== 200) {
setFailedToLoadSrc(true);
}
};
checkIfSrcCanBeLoaded();

/*
iframe domain restrictions prevent naive design :-(
Expand All @@ -30,6 +40,19 @@ export default function I18nMessage(props: Props) {
return (
// style={{height: iframeHeight}}
// ref={iframeRef}
<iframe src={src} title={title} onLoad={onLoad} sandbox={!IS_WEB} />
!failedToLoadSrc ? (
<iframe src={src} title={title} onLoad={onLoad} sandbox={!IS_WEB} />
) : (
<Card
title={__('Failed to load')}
subtitle={
<p>
{__(
'This file failed to load. Some browser extension may be blocking it. If the issue persists, please reach out to [email protected]'
)}
</p>
}
/>
)
);
}

0 comments on commit 69dd625

Please sign in to comment.