'use client'; import React, { Suspense, useEffect, useState } from 'react'; import dynamic from 'next/dynamic'; import { useDashboardStore } from '@/lib/stores/use-dashboard-store'; import { WidgetErrorBoundary } from '@/components/widget-error-boundary'; import { Button } from '@/components/ui/button'; import { Settings2, LayoutGrid } from 'lucide-react'; import { useRouter, useSearchParams } from 'next/navigation'; // Lazy load react-grid-layout (client-only, ~45KB) const ResponsiveGridLayout = dynamic( () => import('@/components/dashboard/responsive-grid-layout'), { ssr: false, loading: () => (
{Array.from({ length: 8 }).map((_, i) => (
))}
), } ); // Lazy load individual widgets const TodayTasksWidget = dynamic(() => import('@/components/dashboard/widgets/today-tasks-widget').then((m) => m.TodayTasksWidget), { ssr: false, loading: () => }); const HabitChecklistWidget = dynamic(() => import('@/components/dashboard/widgets/habit-checklist-widget').then((m) => m.HabitChecklistWidget), { ssr: false, loading: () => }); const WeeklyStatsWidget = dynamic(() => import('@/components/dashboard/widgets/weekly-stats-widget').then((m) => m.WeeklyStatsWidget), { ssr: false, loading: () => }); const ProjectProgressWidget = dynamic(() => import('@/components/dashboard/widgets/project-progress-widget').then((m) => m.ProjectProgressWidget), { ssr: false, loading: () => }); const UpcomingCalendarWidget = dynamic(() => import('@/components/dashboard/widgets/upcoming-calendar-widget').then((m) => m.UpcomingCalendarWidget), { ssr: false, loading: () => }); const RecentNotesWidget = dynamic(() => import('@/components/dashboard/widgets/recent-notes-widget').then((m) => m.RecentNotesWidget), { ssr: false, loading: () => }); const ActivityFeedWidget = dynamic(() => import('@/components/dashboard/widgets/activity-feed-widget').then((m) => m.ActivityFeedWidget), { ssr: false, loading: () => }); const QuickCaptureWidget = dynamic(() => import('@/components/dashboard/widgets/quick-capture-widget').then((m) => m.QuickCaptureWidget), { ssr: false, loading: () => }); function WidgetSkeleton() { return (
); } const widgetComponents: Record = { 'today-tasks': TodayTasksWidget, 'habit-checklist': HabitChecklistWidget, 'weekly-stats': WeeklyStatsWidget, 'project-progress': ProjectProgressWidget, 'upcoming-calendar': UpcomingCalendarWidget, 'recent-notes': RecentNotesWidget, 'activity-feed': ActivityFeedWidget, 'quick-capture': QuickCaptureWidget, }; const widgetLabels: Record = { 'today-tasks': "Today's Tasks", 'habit-checklist': 'Habit Checklist', 'weekly-stats': 'Weekly Stats', 'project-progress': 'Project Progress', 'upcoming-calendar': 'Upcoming Calendar', 'recent-notes': 'Recent Notes', 'activity-feed': 'Activity Feed', 'quick-capture': 'Quick Capture', }; function DashboardPage() { const { widgets, setWidgets, addWidget, removeWidget } = useDashboardStore(); const [layoutAnnouncement, setLayoutAnnouncement] = React.useState(''); const [editMode, setEditMode] = React.useState(false); const [showConfig, setShowConfig] = React.useState(false); const router = useRouter(); const searchParams = useSearchParams(); const domainFilter = searchParams.get('domain'); const layout = widgets.map((w) => ({ i: w.id, x: w.x, y: w.y, w: w.w, h: w.h, })); function handleLayoutChange(newLayout: ReadonlyArray<{ i: string; x: number; y: number; w: number; h: number }>) { const updated = widgets.map((w) => { const layoutItem = newLayout.find((l) => l.i === w.id); if (layoutItem) { return { ...w, x: layoutItem.x, y: layoutItem.y, w: layoutItem.w, h: layoutItem.h }; } return w; }); setWidgets(updated); } const availableWidgets = Object.keys(widgetComponents).filter((id) => !widgets.find((w) => w.id === id)); function addNewWidget(widgetId: string) { addWidget({ id: widgetId, type: widgetLabels[widgetId] || widgetId, x: 0, y: widgets.length, w: 4, h: 3, visible: true, }); } return (

Dashboard

Your day, at a glance.{domainFilter ? " (Filtered: " + domainFilter + ")" : ""}

{/* Widget configuration panel */} {showConfig && (

Add Widgets

{availableWidgets.length === 0 ? (

All widgets are already on your dashboard.

) : ( availableWidgets.map((id) => ( )) )}

Active Widgets

{widgets.map((w) => (
{widgetLabels[w.id] || w.type}
))}
)}

{layoutAnnouncement}

{widgets.map((widget) => { const WidgetComponent = widgetComponents[widget.id]; if (!WidgetComponent) return null; return (
}>
); })}
); } export default function DashboardPageWrapper() { return ( Loading dashboard...
}> ); }