mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-16 04:18:05 +00:00
fix(ui): only show "Copied" feedback when clipboard write succeeds
PR-Agent re-review flagged that `copyText()` swallowed clipboard errors but the row's `setJustCopied(true)` always fired regardless, so users in insecure contexts (or with denied clipboard permission) saw a fake success indicator while nothing was actually copied. Make `copyText()` return a boolean and gate the "Copied" UI state on it. When the clipboard write fails, the button stays in its idle state and the user can retry rather than being misled. Refs #1138, #1151
This commit is contained in:
@@ -31,11 +31,14 @@ function formatHms(timestamp: string): string {
|
||||
});
|
||||
}
|
||||
|
||||
async function copyText(text: string): Promise<void> {
|
||||
async function copyText(text: string): Promise<boolean> {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
return true;
|
||||
} catch {
|
||||
// best-effort; clipboard may be unavailable in non-secure contexts
|
||||
// Insecure context or clipboard permission denied. Caller should NOT
|
||||
// claim success in the UI when this returns false.
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +68,8 @@ function LogsRowImpl({
|
||||
const handleCopyRequestId = async (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
if (!entry.requestId) return;
|
||||
await copyText(entry.requestId);
|
||||
const ok = await copyText(entry.requestId);
|
||||
if (!ok) return;
|
||||
setJustCopied(true);
|
||||
window.setTimeout(() => setJustCopied(false), 1200);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user