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>
78 lines
2.4 KiB
TypeScript
78 lines
2.4 KiB
TypeScript
"use client";
|
|
|
|
import { useState } from "react";
|
|
import {
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogTitle,
|
|
} from "@/components/ui/dialog";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Label } from "@/components/ui/label";
|
|
import { toast } from "sonner";
|
|
|
|
interface NameSessionDialogProps {
|
|
sessionId: number | null;
|
|
onClose: () => void;
|
|
onSaved: () => void;
|
|
}
|
|
|
|
export function NameSessionDialog({ sessionId, onClose, onSaved }: NameSessionDialogProps) {
|
|
const [name, setName] = useState("");
|
|
const [description, setDescription] = useState("");
|
|
const [saving, setSaving] = useState(false);
|
|
|
|
async function handleSave() {
|
|
if (!sessionId || name.trim().length === 0) return;
|
|
setSaving(true);
|
|
const res = await fetch(`/api/sessions/${sessionId}`, {
|
|
method: "PATCH",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify({ name: name.trim(), description }),
|
|
});
|
|
setSaving(false);
|
|
if (res.ok) {
|
|
toast.success("Session named");
|
|
onSaved();
|
|
} else {
|
|
toast.error("Could not name session");
|
|
}
|
|
}
|
|
|
|
return (
|
|
<Dialog open={sessionId !== null} onOpenChange={(open) => !open && onClose()}>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>Name this session</DialogTitle>
|
|
<DialogDescription>Give it a name so you can find and replay it later.</DialogDescription>
|
|
</DialogHeader>
|
|
<div className="flex flex-col gap-3">
|
|
<div className="flex flex-col gap-1.5">
|
|
<Label htmlFor="session-name">Name</Label>
|
|
<Input id="session-name" value={name} onChange={(e) => setName(e.target.value)} autoFocus />
|
|
</div>
|
|
<div className="flex flex-col gap-1.5">
|
|
<Label htmlFor="session-description">Description (optional)</Label>
|
|
<Input
|
|
id="session-description"
|
|
value={description}
|
|
onChange={(e) => setDescription(e.target.value)}
|
|
/>
|
|
</div>
|
|
</div>
|
|
<DialogFooter>
|
|
<Button variant="ghost" onClick={onClose}>
|
|
Skip
|
|
</Button>
|
|
<Button onClick={handleSave} disabled={saving || name.trim().length === 0}>
|
|
{saving ? "Saving..." : "Save name"}
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|