From 1e7a044a5fea9095125cac5c8b04e5db658e95d6 Mon Sep 17 00:00:00 2001
From: Haakon Gunleiksrud <haakogun@stud.ntnu.no>
Date: Wed, 22 Sep 2021 09:43:47 +0200
Subject: [PATCH] feat/add preview of image in workout if image file

---
 frontend/www/scripts/workout.js | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/frontend/www/scripts/workout.js b/frontend/www/scripts/workout.js
index 94eddb77..2e85e119 100644
--- a/frontend/www/scripts/workout.js
+++ b/frontend/www/scripts/workout.js
@@ -42,6 +42,15 @@ async function retrieveWorkout(id) {
             a.text = pathArray[pathArray.length - 1];
             a.className = "me-2";
             filesDiv.appendChild(a);
+
+            let isImage = ["jpg", "png", "gif", "jpeg"].includes(a.text.split(".")[1]);
+
+            if(isImage){ 
+                let img = document.createElement("img");
+                img.src = file.file;
+                img.width = "500";
+                filesDiv.appendChild(img);
+            }
         }
 
         // create exercises
-- 
GitLab