import Link from "next/link"; import { Settings } from "lucide-react"; import { desc, eq } from "drizzle-orm"; import { getRegistry } from "@/modules/_core/registry"; import type { DashboardMeta } from "@/app/d/actions"; import { notifications } from "@/modules/_core/schema"; import { db } from "@/lib/db"; import { auth } from "@/lib/auth"; import { DashboardSwitcher } from "./dashboard-switcher"; import { DashboardTab } from "./dashboard-tab"; import { NotificationBell } from "./notification-bell"; async function getNotifications(userId: string) { const rows = await db .select() .from(notifications) .where(eq(notifications.userId, userId)) .orderBy(desc(notifications.createdAt)) .limit(20); const unread = rows.filter((n) => !n.readAt).length; return { rows, unread }; } export async function AppNav({ dashboards = [] }: { dashboards?: DashboardMeta[] }) { const { modules } = getRegistry(); const navItems = modules.flatMap((m) => (m.nav ? [m.nav] : [])); const session = await auth(); const userId = session?.user?.id; const { rows: notifRows, unread } = userId ? await getNotifications(userId) : { rows: [], unread: 0 }; return (
{dashboards.length > 0 && (
{dashboards.map((d) => ( ))}
)}
); }