From b43f562e2e5b8476c6480f62ed8fbf6ccfe67520 Mon Sep 17 00:00:00 2001
From: Daniele Sabre <daniele.sabre@gmail.com>
Date: Fri, 10 Nov 2023 10:42:09 +0100
Subject: [PATCH] simplified function list

---
 src/components/Sidebar.vue | 32 ++++++++++----------------------
 src/router/index.js        | 18 ++++++++++++++----
 src/utils/functionsList.js | 15 ---------------
 3 files changed, 24 insertions(+), 41 deletions(-)
 delete mode 100644 src/utils/functionsList.js

diff --git a/src/components/Sidebar.vue b/src/components/Sidebar.vue
index 90035d7..ec24b7e 100644
--- a/src/components/Sidebar.vue
+++ b/src/components/Sidebar.vue
@@ -1,23 +1,21 @@
 <script setup>
 import {RouterLink} from 'vue-router';
 import {ref, watch} from 'vue';
-import functionsList from '@/utils/functionsList';
+import {routes} from '../router';
 
-const functions = ref([]);
-const functionsFilter = ref([]);
+const getFunctions = () => routes.filter((r) => r.path.startsWith('/f/'));
+const functions = ref(getFunctions());
+const functionsFilter = ref(getFunctions());
 const search = ref('');
 const getClonedObject = (object) => JSON.parse(JSON.stringify(object));
 
-functionsList.forEach((fName) => {
-    functions.value.push({name: fName, path: `/f/${fName}`});
-    functionsFilter.value.push({name: fName, path: `/f/${fName}`});
-});
-
 watch(search, () => {
     if (search.value.trim() === '') {
         functionsFilter.value = getClonedObject(functions.value);
     } else {
-        functionsFilter.value = getClonedObject(functions.value.filter((f) => f.name.trim().toLowerCase().includes(search.value.trim().toLowerCase())));
+        functionsFilter.value = getClonedObject(
+            functions.value.filter((f) => f.name.trim().toLowerCase().includes(search.value.trim().toLowerCase()))
+        );
     }
 });
 </script>
@@ -115,9 +113,7 @@ watch(search, () => {
                 </li>
             </ul>
         </div>
-        <div
-            class="absolute bottom-0 left-0 justify-center p-4 w-full z-20"
-        >
+        <div class="absolute bottom-0 left-0 justify-center p-4 w-full z-20">
             <a
                 href="https://github.com/dsabre"
                 target="_blank"
@@ -125,17 +121,9 @@ watch(search, () => {
             >
                 <span class="sr-only">Show GitHub profile</span>
                 <div class="flex items-center space-x-3">
-                    <img
-                        src="https://github.com/dsabre.png"
-                        class="w-8 h-8 rounded-full"
-                        alt="Bonnie avatar"
-                    />
+                    <img src="https://github.com/dsabre.png" class="w-8 h-8 rounded-full" alt="Bonnie avatar" />
                     <div class="text-left">
-                        <div
-                            class="font-semibold leading-none text-gray-900 dark:text-white mb-0.5"
-                        >
-                            Daniele Sabre
-                        </div>
+                        <div class="font-semibold leading-none text-gray-900 dark:text-white mb-0.5">Daniele Sabre</div>
                     </div>
                 </div>
             </a>
diff --git a/src/router/index.js b/src/router/index.js
index 345c5a4..d59f190 100644
--- a/src/router/index.js
+++ b/src/router/index.js
@@ -1,5 +1,4 @@
 import {createRouter, createWebHistory} from 'vue-router';
-import functionsList from '@/utils/functionsList';
 
 export const routes = [
     // {
@@ -8,10 +7,21 @@ export const routes = [
     //     component: () => import('../views/HomeView.vue')
     // }
 ];
+const addRoute = (fName) =>
+    routes.push({path: `/f/${fName}`, name: fName, component: () => import(`../views/functions/${fName}.vue`)});
 
-functionsList.forEach((fName) =>
-    routes.push({path: `/f/${fName}`, name: fName, component: () => import(`../views/functions/${fName}.vue`)})
-);
+addRoute('ucfirst');
+addRoute('ifNaN');
+addRoute('getElementHeight');
+addRoute('getFormData');
+addRoute('padLeft');
+addRoute('downloadFile');
+addRoute('makeId');
+addRoute('getClonedObject');
+addRoute('stripTags');
+
+// sort routes alphabetically
+routes.sort((a, b) => a.name.localeCompare(b.name));
 
 // set first function as homepage
 routes.push({path: '/', name: 'home', component: routes[0].component});
diff --git a/src/utils/functionsList.js b/src/utils/functionsList.js
deleted file mode 100644
index 6e6ddbb..0000000
--- a/src/utils/functionsList.js
+++ /dev/null
@@ -1,15 +0,0 @@
-const functionsList = [
-    'ucfirst',
-    'ifNaN',
-    'getElementHeight',
-    'getFormData',
-    'padLeft',
-    'downloadFile',
-    'makeId',
-    'getClonedObject',
-    'stripTags'
-];
-
-functionsList.sort();
-
-export default functionsList;
\ No newline at end of file