From 07b0a159cc4bb79af482d6d034c1f1510d532402 Mon Sep 17 00:00:00 2001 From: abrha Date: Fri, 25 Aug 2023 09:52:58 +0200 Subject: [PATCH] =?UTF-8?q?[KAIZEN-0]=20St=C3=B8tte=20jpg=20og=20png=20i?= =?UTF-8?q?=20saksdokument=20visning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../saksoversikt/dokumentvisning/SaksDokumentVisning.tsx | 2 +- src/components/ObjectHttpFeilHandtering.tsx | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/app/personside/infotabs/saksoversikt/dokumentvisning/SaksDokumentVisning.tsx b/src/app/personside/infotabs/saksoversikt/dokumentvisning/SaksDokumentVisning.tsx index dfbdb7975..136c1f7f7 100644 --- a/src/app/personside/infotabs/saksoversikt/dokumentvisning/SaksDokumentVisning.tsx +++ b/src/app/personside/infotabs/saksoversikt/dokumentvisning/SaksDokumentVisning.tsx @@ -44,7 +44,7 @@ function DokumentVisning(props: Props) { const url = getMockableUrl(byggDokumentVisningUrl(props.url, props.fnr)); return ( - + {errMsg} diff --git a/src/components/ObjectHttpFeilHandtering.tsx b/src/components/ObjectHttpFeilHandtering.tsx index bebd1822f..aedf47cbf 100644 --- a/src/components/ObjectHttpFeilHandtering.tsx +++ b/src/components/ObjectHttpFeilHandtering.tsx @@ -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); }); @@ -42,5 +45,5 @@ export function ObjectHttpFeilHandtering({ url, onError, children, ...rest }: Pr return <>{children}; } - return ; + return ; }