mirror of
https://github.com/stablyai/orca.git
synced 2026-09-28 08:02:43 +00:00
Move checks panel copy timer into handler (#3394)
This commit is contained in:
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user