Move checks panel copy timer into handler (#3394)

This commit is contained in:
Neil
2026-05-29 17:50:42 -07:00
committed by GitHub
parent 27ed6ccee5
commit f18d01ec75
@@ -1,6 +1,6 @@
/* eslint-disable max-lines -- Why: co-locating all checks-panel sub-components (checks list,
conflict sections, threaded PR comments) keeps the shared icon/color maps in one place. */
import React, { useCallback, useEffect, useState } from 'react'
import React, { useCallback, useEffect, useRef, useState } from 'react'
import {
CircleCheck,
CircleX,
@@ -356,23 +356,28 @@ export function ChecksList({
function CopyButton({ text }: { text: string }): React.JSX.Element {
const [copied, setCopied] = useState(false)
const copiedResetTimerRef = useRef<number | null>(null)
useEffect(() => {
if (!copied) {
return
const clearCopiedResetTimer = useCallback((): void => {
if (copiedResetTimerRef.current !== null) {
window.clearTimeout(copiedResetTimerRef.current)
copiedResetTimerRef.current = null
}
const timeout = window.setTimeout(() => setCopied(false), 1500)
return () => window.clearTimeout(timeout)
}, [copied])
}, [])
const handleCopy = useCallback(
(e: React.MouseEvent) => {
e.stopPropagation()
void window.api.ui.writeClipboardText(text).then(() => {
clearCopiedResetTimer()
setCopied(true)
copiedResetTimerRef.current = window.setTimeout(() => {
copiedResetTimerRef.current = null
setCopied(false)
}, 1500)
})
},
[text]
[clearCopiedResetTimer, text]
)
return (