From 6c951e168ccfe9e263b073c15abb391240ec04f7 Mon Sep 17 00:00:00 2001
From: Thomas Schneider <thomas@fsmpi.rwth-aachen.de>
Date: Mon, 16 Sep 2024 19:12:03 +0200
Subject: [PATCH] frontend: Make index previews clickable as well

---
 frontend/src/main.ts | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 35a4447..ee70333 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -19,20 +19,23 @@ window.addEventListener("load", () => {
 	for (const op of document.querySelectorAll('.option .preview')) {
 		console.debug(op);
 		const input_id = (op as HTMLElement).dataset.for;
-		if (!input_id) {
-			console.error("Missing data-for attribute for", op);
-			continue;
-		}
-		const input = document.getElementById(input_id);
-		if (!input || input === null) {
-			console.error("Unable to find input for", op);
-			continue;
-		}
+		let handler: (_: Event) => void;
+		if (input_id) {
+			const input = document.getElementById(input_id);
+			if (!input || input === null) {
+				console.error("Unable to find input for", op);
+				continue;
+			}
 
-		const handler = (_: Event) => {
-			console.log("clicked");
-			(input as HTMLInputElement).checked = true;
-		};
+			handler = (_: Event) => {
+				(input as HTMLInputElement).checked = true;
+			}
+		} else {
+			const p = (op as HTMLElement).parentNode;
+			handler = (_: Event) => {
+				window.location.href = (p as HTMLAnchorElement).href;
+			}
+		}
 		op.addEventListener('click', handler);
 		(op as HTMLIFrameElement).contentDocument?.addEventListener('click', handler);
 	}
-- 
GitLab