fix: clear issue copy timer between clicks

This commit is contained in:
Dotta 2026-03-17 13:22:38 -05:00
parent 3ffa94ab52
commit 1c7a8246b5

View file

@ -210,6 +210,7 @@ export function IssueDetail() {
});
const [attachmentError, setAttachmentError] = useState<string | null>(null);
const [attachmentDragActive, setAttachmentDragActive] = useState(false);
const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
const fileInputRef = useRef<HTMLInputElement | null>(null);
const lastMarkedReadIssueIdRef = useRef<string | null>(null);
@ -590,6 +591,14 @@ export function IssueDetail() {
return () => closePanel();
}, [issue]); // eslint-disable-line react-hooks/exhaustive-deps
useEffect(() => {
return () => {
if (copiedTimerRef.current !== null) {
clearTimeout(copiedTimerRef.current);
}
};
}, []);
const copyIssueToClipboard = async () => {
if (!issue) return;
const decodeEntities = (text: string) => {
@ -603,7 +612,13 @@ export function IssueDetail() {
await navigator.clipboard.writeText(md);
setCopied(true);
pushToast({ title: "Copied to clipboard", tone: "success" });
setTimeout(() => setCopied(false), 2000);
if (copiedTimerRef.current !== null) {
clearTimeout(copiedTimerRef.current);
}
copiedTimerRef.current = setTimeout(() => {
setCopied(false);
copiedTimerRef.current = null;
}, 2000);
};
if (isLoading) return <p className="text-sm text-muted-foreground">Loading...</p>;