Recordings were just a thin named pointer over an already-captured session's events, so the whole separate feature (recordings table, API routes, pages, UI) is gone: any completed session can now be named and replayed directly. Replaying no longer creates a session or duplicates events of its own - it just bumps the source session's playCount/lastPlayedAt. Also renames play_sessions/playSession(s) to sessions/session(s) throughout the schema, queries, API routes, and UI for consistency, and updates the README to match the new flow. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||
|
||
export interface SessionsSummary {
|
||
count: number;
|
||
totalDurationMs: number;
|
||
avgDurationMs: number;
|
||
totalReplays: number;
|
||
durationPerDevice: { deviceId: number; displayName: string | null; bleName: string; totalActiveMs: number }[];
|
||
}
|
||
|
||
function formatHours(ms: number): string {
|
||
return `${(ms / 3_600_000).toFixed(1)}h`;
|
||
}
|
||
|
||
export function SessionsSummaryCards({ summary }: { summary: SessionsSummary }) {
|
||
return (
|
||
<div className="flex flex-col gap-4">
|
||
<div className="grid gap-4 sm:grid-cols-3">
|
||
<Card className="bp-glass">
|
||
<CardHeader>
|
||
<CardTitle className="text-sm text-muted-foreground">Completed sessions</CardTitle>
|
||
</CardHeader>
|
||
<CardContent className="bp-readout text-3xl">{summary.count}</CardContent>
|
||
</Card>
|
||
<Card className="bp-glass">
|
||
<CardHeader>
|
||
<CardTitle className="text-sm text-muted-foreground">Total time</CardTitle>
|
||
</CardHeader>
|
||
<CardContent className="bp-readout text-3xl">{formatHours(summary.totalDurationMs)}</CardContent>
|
||
</Card>
|
||
<Card className="bp-glass">
|
||
<CardHeader>
|
||
<CardTitle className="text-sm text-muted-foreground">Avg session length</CardTitle>
|
||
</CardHeader>
|
||
<CardContent className="bp-readout text-3xl">
|
||
{Math.round(summary.avgDurationMs / 60_000)}m
|
||
</CardContent>
|
||
</Card>
|
||
</div>
|
||
<Card className="bp-glass">
|
||
<CardContent className="py-3 text-sm text-muted-foreground">Replayed {summary.totalReplays}×</CardContent>
|
||
</Card>
|
||
{summary.durationPerDevice.length > 0 && (
|
||
<Card className="bp-glass">
|
||
<CardHeader>
|
||
<CardTitle className="text-base">Duration per device</CardTitle>
|
||
</CardHeader>
|
||
<CardContent className="flex flex-col gap-2">
|
||
{summary.durationPerDevice.map((d) => (
|
||
<div key={d.deviceId} className="flex items-center justify-between text-sm">
|
||
<span>{d.displayName ?? d.bleName}</span>
|
||
<span className="text-muted-foreground">{formatHours(d.totalActiveMs)}</span>
|
||
</div>
|
||
))}
|
||
</CardContent>
|
||
</Card>
|
||
)}
|
||
</div>
|
||
);
|
||
}
|