Make the session description always visible and inline-editable
New SessionDescriptionEditor renders even when empty (with an "Add a description..." placeholder) and autosaves on typing - same debounced, no-Save-button pattern as the title and device name editors. Unlike the name field, an empty description is a valid saved state. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WzyfRyA7h5rs5SCAahLAWd
This commit is contained in:
@@ -6,6 +6,7 @@ import { Button } from "@/components/ui/button";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { SessionTimelineChart } from "@/components/sessions/SessionTimelineChart";
|
||||
import { SessionTitleEditor } from "@/components/sessions/SessionTitleEditor";
|
||||
import { SessionDescriptionEditor } from "@/components/sessions/SessionDescriptionEditor";
|
||||
import { STATUS_VARIANT } from "@/components/sessions/SessionsTable";
|
||||
import { getSessionDetail, getSessionName } from "@/lib/db/queries/sessions";
|
||||
import { getSessionTimeline } from "@/lib/db/queries/stats";
|
||||
@@ -52,9 +53,7 @@ export default async function SessionDetailPage({ params }: { params: Promise<{
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{detail.session.description && (
|
||||
<p className="mt-1 text-sm text-muted-foreground">{detail.session.description}</p>
|
||||
)}
|
||||
<SessionDescriptionEditor sessionId={detail.session.id} initialDescription={detail.session.description} />
|
||||
</div>
|
||||
<div className="flex shrink-0 items-center gap-3">
|
||||
<Badge variant={STATUS_VARIANT[detail.session.status]}>{detail.session.status}</Badge>
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { Check, Loader2 } from "lucide-react";
|
||||
import { toast } from "sonner";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const AUTOSAVE_DELAY_MS = 600;
|
||||
|
||||
export function SessionDescriptionEditor({
|
||||
sessionId,
|
||||
initialDescription,
|
||||
}: {
|
||||
sessionId: number;
|
||||
initialDescription: string | null;
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const initial = initialDescription ?? "";
|
||||
const [value, setValue] = useState(initial);
|
||||
const [status, setStatus] = useState<"idle" | "saving" | "saved">("idle");
|
||||
const lastSaved = useRef(initial);
|
||||
|
||||
useEffect(() => {
|
||||
// Unlike the session name, an empty description is a valid, saveable
|
||||
// state (it just means "no description"), so no non-empty guard here.
|
||||
if (value === lastSaved.current) return;
|
||||
|
||||
setStatus("saving");
|
||||
const timer = setTimeout(async () => {
|
||||
const res = await fetch(`/api/sessions/${sessionId}`, {
|
||||
method: "PATCH",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ description: value }),
|
||||
});
|
||||
if (res.ok) {
|
||||
lastSaved.current = value;
|
||||
setStatus("saved");
|
||||
router.refresh();
|
||||
} else {
|
||||
setStatus("idle");
|
||||
toast.error("Could not save description");
|
||||
}
|
||||
}, AUTOSAVE_DELAY_MS);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [value, sessionId, router]);
|
||||
|
||||
useEffect(() => {
|
||||
if (status !== "saved") return;
|
||||
const timer = setTimeout(() => setStatus("idle"), 1500);
|
||||
return () => clearTimeout(timer);
|
||||
}, [status]);
|
||||
|
||||
return (
|
||||
<div className="mt-1 flex items-start gap-2">
|
||||
<textarea
|
||||
value={value}
|
||||
onChange={(e) => setValue(e.target.value)}
|
||||
placeholder="Add a description..."
|
||||
aria-label="Session description"
|
||||
rows={1}
|
||||
className="min-w-0 max-w-full flex-1 resize-none border-b-2 border-transparent bg-transparent text-sm text-muted-foreground outline-none transition-colors placeholder:text-muted-foreground/60 hover:border-b-border focus:border-b-primary focus:text-foreground [field-sizing:content]"
|
||||
/>
|
||||
<div className="relative mt-0.5 flex size-4 shrink-0 items-center justify-center">
|
||||
<Loader2
|
||||
className={cn(
|
||||
"absolute size-4 animate-spin text-muted-foreground transition-opacity",
|
||||
status === "saving" ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
/>
|
||||
<Check
|
||||
className={cn(
|
||||
"absolute size-4 text-primary transition-opacity",
|
||||
status === "saved" ? "opacity-100" : "opacity-0",
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user