From cb468c5ceb22acccf43debf419b21ab191d47566 Mon Sep 17 00:00:00 2001 From: Lucas Charrier Date: Tue, 19 Nov 2024 17:02:20 +0100 Subject: [PATCH] chore: return first active item --- src/app/(private)/(dashboard)/PrivateLayout.tsx | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/app/(private)/(dashboard)/PrivateLayout.tsx b/src/app/(private)/(dashboard)/PrivateLayout.tsx index 76d23a56..edd7170d 100644 --- a/src/app/(private)/(dashboard)/PrivateLayout.tsx +++ b/src/app/(private)/(dashboard)/PrivateLayout.tsx @@ -132,7 +132,7 @@ export function PrivateLayout({ children }: { children: React.ReactNode }) { text: currentPage, isActive: hasPathnameThisRegex( pathname, - "^/community/[a-zA-Z]+.[a-zA-Z]+" + "^/community/[a-zA-Z]+.[a-zA-Z]+$" ), items: [ { @@ -348,7 +348,7 @@ export function PrivateLayout({ children }: { children: React.ReactNode }) { const findActiveItem = (items: ItemLink[]) => { let tree: ItemLink[] = []; - items.forEach((i) => { + for (const i of items) { let childrenTree: ItemLink[] = []; if (i.items && i.items.length) { childrenTree = findActiveItem(i.items); @@ -357,8 +357,9 @@ export function PrivateLayout({ children }: { children: React.ReactNode }) { tree = [i, ...childrenTree]; } else if (i.isActive) { tree = [i]; + break; } - }); + } return tree; };