From 48a6a16f1aa546f6bbdf80efbc5e72aa783acf4b Mon Sep 17 00:00:00 2001
From: Fuwn <contact@fuwn.me>
Date: Sun, 24 Dec 2023 23:48:06 -0800
Subject: refactor(error): move closest path to module

---
 src/routes/+error.svelte | 38 ++++++++++++--------------------------
 1 file changed, 12 insertions(+), 26 deletions(-)

(limited to 'src/routes/+error.svelte')

diff --git a/src/routes/+error.svelte b/src/routes/+error.svelte
index a5cd1dee..584d4ec0 100644
--- a/src/routes/+error.svelte
+++ b/src/routes/+error.svelte
@@ -1,32 +1,18 @@
 <script lang="ts">
 	import { browser } from '$app/environment';
-	import levenshtein from 'fast-levenshtein';
+	import { closest } from '$lib/Error/path';
 
-	$: suggestion = (() => {
-		let closest = '';
-		let lowestDistance = Infinity;
-
-		[
-			'birthdays',
-			'completed',
-			'schedule',
-			'settings',
-			'tools',
-			'updates',
-			'user',
-			'wrapped',
-			'...'
-		].forEach((path) => {
-			let distance = levenshtein.get(browser ? window.location.pathname : '...', path);
-
-			if (distance < lowestDistance) {
-				lowestDistance = distance;
-				closest = path;
-			}
-		});
-
-		return closest;
-	})();
+	$: suggestion = closest(browser ? window.location.pathname : '...', [
+		'birthdays',
+		'completed',
+		'schedule',
+		'settings',
+		'tools',
+		'updates',
+		'user',
+		'wrapped',
+		'...'
+	]);
 </script>
 
 <p>Page not found.</p>
-- 
cgit v1.2.3

