Implement dashboard composition (task 20)
- Add default_dashboard_layout jsonb to users + migration 0007 - Create _core/manifest.tsx with core.activity placeholder widget - Register core manifest alongside calendar/lists/notes - Update all three module manifests with real async server-component widget renders (upcoming events, month view, list items, notes) - Add src/lib/dashboard.ts: computeDefaultLayout greedy packer + parseDashboardLayout Zod validator - Build src/app/page.tsx: 12-col CSS Grid, static smColSpan lookup, per-widget Suspense for parallel loading, generic widget.render() dispatch — no widgetId branches - Add tests/e2e/dashboard.spec.ts; all 4 E2E specs pass Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
d7069d14a2
commit
b4dde92757
@@ -1,9 +1,95 @@
|
||||
import type { ModuleManifest } from "../_core/module";
|
||||
import type { ModuleManifest, WidgetContext } from "../_core/module";
|
||||
import { z } from "zod";
|
||||
import { listCalendars, searchCalendars, searchEvents } from "./server/queries";
|
||||
import { listCalendars, listEvents, searchCalendars, searchEvents } from "./server/queries";
|
||||
|
||||
const calendarIdsSchema = z.union([z.literal("all"), z.array(z.string().uuid())]);
|
||||
|
||||
const upcomingConfigSchema = z.object({
|
||||
calendarIds: calendarIdsSchema,
|
||||
days: z.number().int().min(1).max(30),
|
||||
});
|
||||
|
||||
const monthConfigSchema = z.object({ calendarIds: calendarIdsSchema });
|
||||
|
||||
async function UpcomingEventsWidget({
|
||||
config,
|
||||
}: {
|
||||
config: unknown;
|
||||
ctx: WidgetContext;
|
||||
}) {
|
||||
const parsed = upcomingConfigSchema.parse(config);
|
||||
const now = new Date();
|
||||
const end = new Date(now.getTime() + parsed.days * 24 * 60 * 60 * 1000);
|
||||
const events = await listEvents({ from: now, to: end, calendarIds: parsed.calendarIds });
|
||||
|
||||
if (events.length === 0) {
|
||||
return (
|
||||
<p className="text-sm text-muted-foreground">
|
||||
No events in the next {parsed.days} day{parsed.days !== 1 ? "s" : ""}
|
||||
</p>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<ul className="space-y-2">
|
||||
{events.slice(0, 8).map((event) => {
|
||||
const start = new Date(event.startAt);
|
||||
const label = event.allDay
|
||||
? start.toLocaleDateString(undefined, { month: "short", day: "numeric" })
|
||||
: start.toLocaleString(undefined, {
|
||||
month: "short",
|
||||
day: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "2-digit",
|
||||
});
|
||||
return (
|
||||
<li key={event.id} className="flex items-start gap-2 text-sm">
|
||||
<span className="mt-0.5 shrink-0 text-xs text-muted-foreground">{label}</span>
|
||||
<span className="font-medium leading-snug">{event.title}</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
async function MonthWidget({ config }: { config: unknown; ctx: WidgetContext }) {
|
||||
const parsed = monthConfigSchema.parse(config);
|
||||
const now = new Date();
|
||||
const monthStart = new Date(now.getFullYear(), now.getMonth(), 1);
|
||||
const monthEnd = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59);
|
||||
const events = await listEvents({ from: monthStart, to: monthEnd, calendarIds: parsed.calendarIds });
|
||||
|
||||
const monthName = now.toLocaleDateString(undefined, { month: "long", year: "numeric" });
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
<p className="text-xs font-medium text-muted-foreground">{monthName}</p>
|
||||
{events.length === 0 ? (
|
||||
<p className="text-sm text-muted-foreground">No events this month</p>
|
||||
) : (
|
||||
<ul className="space-y-1">
|
||||
{events.slice(0, 10).map((event) => {
|
||||
const eventStart = new Date(event.startAt);
|
||||
const day = eventStart.getDate();
|
||||
return (
|
||||
<li key={event.id} className="flex items-center gap-2 text-sm">
|
||||
<span className="w-5 shrink-0 text-center text-xs font-semibold text-muted-foreground">
|
||||
{day}
|
||||
</span>
|
||||
<span className="truncate">{event.title}</span>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
{events.length > 10 && (
|
||||
<li className="text-xs text-muted-foreground">+{events.length - 10} more</li>
|
||||
)}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const manifest: ModuleManifest = {
|
||||
id: "calendar",
|
||||
name: "Calendar",
|
||||
@@ -34,10 +120,7 @@ const manifest: ModuleManifest = {
|
||||
defaultSize: { w: 4, h: 3 },
|
||||
minSize: { w: 3, h: 2 },
|
||||
defaultPriority: 10,
|
||||
configSchema: z.object({
|
||||
calendarIds: calendarIdsSchema,
|
||||
days: z.number().int().min(1).max(30),
|
||||
}),
|
||||
configSchema: upcomingConfigSchema,
|
||||
defaultConfig: { calendarIds: "all", days: 3 },
|
||||
resolveConfigOptions: async () => ({
|
||||
calendars: (await listCalendars()).map((calendar) => ({
|
||||
@@ -46,7 +129,7 @@ const manifest: ModuleManifest = {
|
||||
visibility: calendar.visibility,
|
||||
})),
|
||||
}),
|
||||
render: () => <div className="text-sm text-muted-foreground">Upcoming events</div>,
|
||||
render: (props) => <UpcomingEventsWidget {...props} />,
|
||||
},
|
||||
{
|
||||
id: "calendar.month",
|
||||
@@ -56,7 +139,7 @@ const manifest: ModuleManifest = {
|
||||
defaultSize: { w: 6, h: 5 },
|
||||
minSize: { w: 4, h: 4 },
|
||||
defaultPriority: 20,
|
||||
configSchema: z.object({ calendarIds: calendarIdsSchema }),
|
||||
configSchema: monthConfigSchema,
|
||||
defaultConfig: { calendarIds: "all" },
|
||||
resolveConfigOptions: async () => ({
|
||||
calendars: (await listCalendars()).map((calendar) => ({
|
||||
@@ -65,7 +148,7 @@ const manifest: ModuleManifest = {
|
||||
visibility: calendar.visibility,
|
||||
})),
|
||||
}),
|
||||
render: () => <div className="text-sm text-muted-foreground">Month calendar</div>,
|
||||
render: (props) => <MonthWidget {...props} />,
|
||||
},
|
||||
],
|
||||
quickAdds: [
|
||||
|
||||
Reference in New Issue
Block a user