From d24de405e35220a37d399677df97cb8c0660cbb5 Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Sun, 21 Apr 2024 06:30:39 -0700
Subject: fix(BadgePreview): high-resolution image load on navigate

---
 src/lib/User/BadgeWall/BadgePreview.svelte | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

(limited to 'src/lib/User/BadgeWall/BadgePreview.svelte')

diff --git a/src/lib/User/BadgeWall/BadgePreview.svelte b/src/lib/User/BadgeWall/BadgePreview.svelte
index 97ff46ec..042d8b8c 100644
--- a/src/lib/User/BadgeWall/BadgePreview.svelte
+++ b/src/lib/User/BadgeWall/BadgePreview.svelte
@@ -38,7 +38,7 @@
 		$mouse = { x: 0, y: 0 };
 	};
 
-	onMount(() => {
+	$: {
 		if (selectedBadge && selectedBadge.image) {
 			const image = new Image();
 
@@ -47,6 +47,18 @@
 				badgeReference.src = image.src;
 			};
 		}
+	}
+
+	onMount(() => {
+		const handleClickOutside = (event: any) => {
+			if (event.target.classList.contains('popup')) selectedBadge = undefined;
+		};
+
+		document.addEventListener('click', handleClickOutside);
+
+		return () => {
+			document.removeEventListener('click', handleClickOutside);
+		};
 	});
 </script>
 
-- 
cgit v1.2.3

