Feat #1255: update copy button status by displaying popup and setting…#1259
Feat #1255: update copy button status by displaying popup and setting…#1259bytecii merged 4 commits intoeigent-ai:mainfrom
Conversation
|
Hi, @Wendong-Fan , Could you please review the PR? |
thanks @dataCenter430 for the contribution! Could you add a short video or snapshot for your PR like how #1258 did? Thanks! |
|
Hi @Wendong-Fan I’m very excited about Eigent-ai and would love to continue contributing to the project. I truly appreciate any feedback you can share on how I can improve this PR or align better with the repository’s standards. Looking forward to your thoughts, thank you again! |
|
Hi @Wendong-Fan |
thanks @dataCenter430 for the contribution! Could @bytecii and @nitpicker55555 help reviewing this? |
hey @dataCenter430 , we have supported Ubuntu/linux version, you can download from https://github.com/eigent-ai/eigent/actions/runs/22019072282, but we haven't do comprehensive test on this system, feel free to check and provide any feedback, thanks in advance! |
@Wendong-Fan thank you for your consideration. |
| setCopied(true); | ||
| setTimeout(() => setCopied(false), COPIED_RESET_MS); | ||
| } catch { | ||
| toast.error('Failed to copy to clipboard'); |
There was a problem hiding this comment.
| toast.error('Failed to copy to clipboard'); | |
| toast.error(t('setting.copy-failed')); |
There was a problem hiding this comment.
to the en.json?
{
"setting": {
"copied-to-clipboard": "Copied to clipboard",
"copy-failed": "Failed to copy to clipboard"
}
}
There was a problem hiding this comment.
hi, @bytecii greate catch, thank you for calling this out.
okay, it seems like a best practice, thx
| await navigator.clipboard.writeText(content); | ||
| toast.success(t('setting.copied-to-clipboard')); | ||
| setCopied(true); | ||
| setTimeout(() => setCopied(false), COPIED_RESET_MS); |
There was a problem hiding this comment.
It's possible that the UI can unmount and set copied to a unmounted component right?
There was a problem hiding this comment.
You’re right, that can happen in the current implementation: if the card unmounts within the COPIED_RESET_MS window, the setTimeout callback would still try to call setCopied(false) on an unmounted component.
I’ll update this to store the timeout id in a ref and clear it in a useEffect cleanup so we don’t call setCopied after unmount.
Changes Made
Imported Check, useCallback, useState, useTranslation, and toast
Added copied state and async handleCopy with try/catch
On success: show toast "Copied to clipboard", set copied to true, reset after 2 seconds
On failure: show error toast
Copy icon switches to a green check icon for 2 seconds after a successful copy
Same copy feedback behavior and UI as above
Same copy feedback behavior and UI as above
Behavior
Toast: toast.success(t('setting.copied-to-clipboard')) on successful copy (using existing i18n key)
Icon: copy icon → green check icon for 2 seconds after copy
Error: toast.error('Failed to copy to clipboard') on clipboard failure
Uses async navigator.clipboard.writeText with proper error handling
Closes #1255