From d2494e66d575fcd8ccd2da5306104d71897f8f07 Mon Sep 17 00:00:00 2001 From: Sam Becker Date: Tue, 25 Feb 2025 23:31:19 -0600 Subject: [PATCH] Refactor admin subnav --- app/admin/configuration/page.tsx | 2 +- app/admin/insights/page.tsx | 2 +- src/admin/AdminInfoNav.tsx | 64 ++++++++++++++++++++++++++++++++ src/admin/AdminInfoPage.tsx | 49 ++---------------------- src/admin/AdminNavClient.tsx | 12 ++++-- 5 files changed, 77 insertions(+), 52 deletions(-) create mode 100644 src/admin/AdminInfoNav.tsx diff --git a/app/admin/configuration/page.tsx b/app/admin/configuration/page.tsx index 6e6435c7..c3eb3ea7 100644 --- a/app/admin/configuration/page.tsx +++ b/app/admin/configuration/page.tsx @@ -3,7 +3,7 @@ import AdminInfoPage from '@/admin/AdminInfoPage'; export default function AdminAppConfigurationPage() { return ( - + ); diff --git a/app/admin/insights/page.tsx b/app/admin/insights/page.tsx index eed08769..93b624da 100644 --- a/app/admin/insights/page.tsx +++ b/app/admin/insights/page.tsx @@ -2,7 +2,7 @@ import AdminAppInsights from '@/admin/insights/AdminAppInsights'; import AdminInfoPage from '@/admin/AdminInfoPage'; export default async function AdminInsightsPage() { - return + return ; } diff --git a/src/admin/AdminInfoNav.tsx b/src/admin/AdminInfoNav.tsx new file mode 100644 index 00000000..b1718eb6 --- /dev/null +++ b/src/admin/AdminInfoNav.tsx @@ -0,0 +1,64 @@ +'use client'; + +import { PATH_ADMIN_CONFIGURATION, PATH_ADMIN_INSIGHTS } from '@/app/paths'; +import LinkWithStatus from '@/components/LinkWithStatus'; +import ResponsiveText from '@/components/primitives/ResponsiveText'; +import clsx from 'clsx/lite'; +import ClearCacheButton from '@/admin/ClearCacheButton'; +import { usePathname } from 'next/navigation'; + +const ADMIN_INFO_PAGES = [{ + titleShort: 'Insights', + path: PATH_ADMIN_INSIGHTS, +}, { + title: 'Configuration', + titleShort: 'Config', + path: PATH_ADMIN_CONFIGURATION, +}]; + +export default function AdminInfoPage({ + includeInsights, +}: { + includeInsights: boolean +}) { + const pathname = usePathname(); + + const pages = ADMIN_INFO_PAGES + .filter(({ titleShort }) => ( + titleShort !== 'Insights' || + includeInsights + )); + + const hasMultiplePages = pages.length > 1; + + return ( +
+
+ {pages + .map(({ title, titleShort, path }) => + + + {title ?? titleShort} + + )} +
+ +
+ ); +} diff --git a/src/admin/AdminInfoPage.tsx b/src/admin/AdminInfoPage.tsx index 94ef0538..dc6d9091 100644 --- a/src/admin/AdminInfoPage.tsx +++ b/src/admin/AdminInfoPage.tsx @@ -1,61 +1,18 @@ -import { PATH_ADMIN_CONFIGURATION, PATH_ADMIN_INSIGHTS } from '@/app/paths'; import Container from '@/components/Container'; -import LinkWithStatus from '@/components/LinkWithStatus'; -import ResponsiveText from '@/components/primitives/ResponsiveText'; import SiteGrid from '@/components/SiteGrid'; -import clsx from 'clsx/lite'; import { ReactNode } from 'react'; -import ClearCacheButton from '@/admin/ClearCacheButton'; - -const ADMIN_INFO_PAGES = [{ - titleShort: 'Insights', - path: PATH_ADMIN_INSIGHTS, -}, -{ - title: 'Configuration', - titleShort: 'Config', - path: PATH_ADMIN_CONFIGURATION, -}]; export default function AdminInfoPage({ - page, children, }: { - page: (typeof ADMIN_INFO_PAGES)[number]['titleShort'] children: ReactNode }) { return ( -
-
- {ADMIN_INFO_PAGES.map(({ title, titleShort, path }) => - - - {title ?? titleShort} - - )} -
- -
- - {children} - - } + + {children} + } /> ); } diff --git a/src/admin/AdminNavClient.tsx b/src/admin/AdminNavClient.tsx index 7255cb10..9dd61e66 100644 --- a/src/admin/AdminNavClient.tsx +++ b/src/admin/AdminNavClient.tsx @@ -6,6 +6,7 @@ import Note from '@/components/Note'; import SiteGrid from '@/components/SiteGrid'; import Spinner from '@/components/Spinner'; import { + PATH_ADMIN_CONFIGURATION, PATH_ADMIN_INSIGHTS, checkPathPrefix, isPathAdminInfo, @@ -18,6 +19,7 @@ import { usePathname } from 'next/navigation'; import { useEffect, useMemo, useState } from 'react'; import { FaRegClock } from 'react-icons/fa'; import AdminAppInfoIcon from './AdminAppInfoIcon'; +import AdminInfoNav from './AdminInfoNav'; // Updates considered recent if they occurred in past 5 minutes const areTimesRecent = (dates: Date[]) => dates @@ -26,9 +28,7 @@ const areTimesRecent = (dates: Date[]) => dates export default function AdminNavClient({ items, mostRecentPhotoUpdateTime, - // TODO: use this with new component - // eslint-disable-next-line @typescript-eslint/no-unused-vars - includeInsights, + includeInsights = true, }: { items: { label: string, @@ -91,7 +91,9 @@ export default function AdminNavClient({ )} } + {isPathAdminInfo(pathname) && + } } />