Skip to content

Commit

Permalink
Merge pull request #2059 from navikt/dev
Browse files Browse the repository at this point in the history
[PROD][KAIZEN-0] Støtte jpg og png i saksdokument visning
  • Loading branch information
abrhanav committed Aug 25, 2023
2 parents 7ee7e0e + e5d69e0 commit 2c741e2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function DokumentVisning(props: Props) {
const url = getMockableUrl(byggDokumentVisningUrl(props.url, props.fnr));

return (
<ObjectHttpFeilHandtering type="application/pdf" url={url} width="100%" height="100%" onError={onError}>
<ObjectHttpFeilHandtering url={url} width="100%" height="100%" onError={onError}>
<ErrorStyle>
<AlertStripeAdvarsel>{errMsg}</AlertStripeAdvarsel>
</ErrorStyle>
Expand Down
9 changes: 6 additions & 3 deletions src/components/ObjectHttpFeilHandtering.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@ interface Props

export function ObjectHttpFeilHandtering({ url, onError, children, ...rest }: Props) {
const [blobUrl, setBlobUrl] = useState('');
const [contentType, setContentType] = useState('');
const [isError, setError] = useState(false);

useEffect(() => {
let objectUrl = '';
fetch(url)
.then(res => {
.then((res) => {
if (!res.ok) {
setError(true);
onError(res.status);
} else {
setContentType(res.headers.get('Content-Type') ?? 'application/pdf');
setError(false);
}
return res.blob();
})
.then(blob => {
.then((blob) => {
objectUrl = URL.createObjectURL(blob);

setBlobUrl(objectUrl);
});

Expand All @@ -42,5 +45,5 @@ export function ObjectHttpFeilHandtering({ url, onError, children, ...rest }: Pr
return <>{children}</>;
}

return <object data={blobUrl} children={children} {...rest} />;
return <object data={blobUrl} children={children} {...rest} type={contentType} />;
}

0 comments on commit 2c741e2

Please sign in to comment.