Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions apps/web/src/components/PlanSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { memo, useState, useCallback } from "react";
import { memo, useState, useCallback, useRef, useEffect } from "react";
import { Badge } from "./ui/badge";
import { Button } from "./ui/button";
import { ScrollArea } from "./ui/scroll-area";
Expand Down Expand Up @@ -66,6 +66,7 @@ const PlanSidebar = memo(function PlanSidebar({
const [proposedPlanExpanded, setProposedPlanExpanded] = useState(false);
const [isSavingToWorkspace, setIsSavingToWorkspace] = useState(false);
const [copied, setCopied] = useState(false);
const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);

const planMarkdown = activeProposedPlan?.planMarkdown ?? null;
const displayedPlanMarkdown = planMarkdown ? stripDisplayedPlanMarkdown(planMarkdown) : null;
Expand All @@ -74,8 +75,15 @@ const PlanSidebar = memo(function PlanSidebar({
const handleCopyPlan = useCallback(() => {
if (!planMarkdown) return;
void navigator.clipboard.writeText(planMarkdown);
if (copiedTimerRef.current != null) {
clearTimeout(copiedTimerRef.current);
}

setCopied(true);
setTimeout(() => setCopied(false), 2000);
copiedTimerRef.current = setTimeout(() => {
setCopied(false);
copiedTimerRef.current = null;
}, 2000);
}, [planMarkdown]);

const handleDownload = useCallback(() => {
Expand Down Expand Up @@ -120,6 +128,14 @@ const PlanSidebar = memo(function PlanSidebar({
{/* Header */}
<div className="flex h-12 shrink-0 items-center justify-between border-b border-border/60 px-3">
<div className="flex items-center gap-2">
// Cleanup timeout on unmount
useEffect(() => {
return () => {
if (copiedTimerRef.current \!= null) {
clearTimeout(copiedTimerRef.current);
}
};
}, []);
<Badge
variant="secondary"
className="rounded-md bg-blue-500/10 px-1.5 py-0 text-[10px] font-semibold tracking-wide text-blue-400 uppercase"
Expand Down
Loading