From 064d5f8b4d74508d2b045389ae3393a2742b5286 Mon Sep 17 00:00:00 2001
From: kamtschatka <simon.schatka@gmx.at>
Date: Sun, 15 Sep 2024 02:56:40 +0200
Subject: feature(web): Alphabetical sorting for lists. Fixes #315 (#351)

* [Feature Request] Alphabetical sorting for lists #315
sorting lists alphabetical

* [Feature Request] Alphabetical sorting for lists #315
added sorting also for sublists
---
 .../dashboard/lists/CollapsibleBookmarkLists.tsx   | 44 ++++++++++++----------
 1 file changed, 24 insertions(+), 20 deletions(-)

(limited to 'apps/web/components/dashboard/lists/CollapsibleBookmarkLists.tsx')

diff --git a/apps/web/components/dashboard/lists/CollapsibleBookmarkLists.tsx b/apps/web/components/dashboard/lists/CollapsibleBookmarkLists.tsx
index da1b7408..77a67f5f 100644
--- a/apps/web/components/dashboard/lists/CollapsibleBookmarkLists.tsx
+++ b/apps/web/components/dashboard/lists/CollapsibleBookmarkLists.tsx
@@ -53,16 +53,18 @@ function ListItem({
         open,
       })}
       <CollapsibleContent>
-        {node.children.map((l) => (
-          <ListItem
-            isOpenFunc={isOpenFunc}
-            key={l.item.id}
-            node={l}
-            render={render}
-            level={level + 1}
-            className={className}
-          />
-        ))}
+        {node.children
+          .sort((a, b) => a.item.name.localeCompare(b.item.name))
+          .map((l) => (
+            <ListItem
+              isOpenFunc={isOpenFunc}
+              key={l.item.id}
+              node={l}
+              render={render}
+              level={level + 1}
+              className={className}
+            />
+          ))}
       </CollapsibleContent>
     </Collapsible>
   );
@@ -96,16 +98,18 @@ export function CollapsibleBookmarkLists({
 
   return (
     <div>
-      {Object.values(root).map((l) => (
-        <ListItem
-          key={l.item.id}
-          node={l}
-          render={render}
-          level={0}
-          className={className}
-          isOpenFunc={isOpenFunc ?? (() => false)}
-        />
-      ))}
+      {Object.values(root)
+        .sort((a, b) => a.item.name.localeCompare(b.item.name))
+        .map((l) => (
+          <ListItem
+            key={l.item.id}
+            node={l}
+            render={render}
+            level={0}
+            className={className}
+            isOpenFunc={isOpenFunc ?? (() => false)}
+          />
+        ))}
     </div>
   );
 }
-- 
cgit v1.2.3-70-g09d2

