From 5d0c2222dabba54292d0a344b949578c561a86d9 Mon Sep 17 00:00:00 2001 From: Gus Vanpoucke <159711661+gusvanpoucke@users.noreply.github.com> Date: Sun, 19 May 2024 16:09:29 +0200 Subject: [PATCH] project pagina werkt terug als er geen opdrachtsbestand is --- .../pages/assignmentPage/AssignmentPage.tsx | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/frontend/frontend/src/pages/assignmentPage/AssignmentPage.tsx b/frontend/frontend/src/pages/assignmentPage/AssignmentPage.tsx index 5102d5a8..92a9fb05 100644 --- a/frontend/frontend/src/pages/assignmentPage/AssignmentPage.tsx +++ b/frontend/frontend/src/pages/assignmentPage/AssignmentPage.tsx @@ -100,28 +100,30 @@ export function AssignmentPage() { `/projecten/${assignmentId}/` ) const newAssignment: Project = assignmentResponse.data - newAssignment.filename = - assignmentResponse.data.opgave_bestand.replace( - /^.*[\\/]/, - '' - ) - newAssignment.opgave_bestand = await instance - .get(`/projecten/${assignmentId}/opgave_bestand/`, { - responseType: 'blob', - }) - .then((res) => { - let filename = 'indiening.zip' - if (newAssignment.filename) { - filename = newAssignment.filename - } - const blob = new Blob([res.data], { - type: res.headers['content-type'], + if (assignmentResponse.data.opgave_bestand) { + newAssignment.filename = + assignmentResponse.data.opgave_bestand.replace( + /^.*[\\/]/, + '' + ) + newAssignment.opgave_bestand = await instance + .get(`/projecten/${assignmentId}/opgave_bestand/`, { + responseType: 'blob', }) - const file: File = new File([blob], filename, { - type: res.headers['content-type'], + .then((res) => { + let filename = 'indiening.zip' + if (newAssignment.filename) { + filename = newAssignment.filename + } + const blob = new Blob([res.data], { + type: res.headers['content-type'], + }) + const file: File = new File([blob], filename, { + type: res.headers['content-type'], + }) + return file }) - return file - }) + } setAssignment(newAssignment) if (user) { if (user.is_lesgever) { @@ -854,7 +856,7 @@ export function AssignmentPage() {