Repository navigation
feat(ui): consistent copy-to-clipboard feedback across the app - #3648
Open
officialasishkumar wants to merge 1 commit into
Open
officialasishkumar wants to merge 1 commit into
officialasishkumar wants to merge 1 commit into
Conversation
Nine copy actions each had their own clipboard code and their own idea of feedback: some swapped the label to "Copied!", some to "Copied", one to "✓ Copied!", some showed a checkmark and some only text. Failures were handled differently too. The badge, resume and webhook-secret buttons only logged to the console or stayed silent, and the weekly AI summary left a rejected promise unhandled. None of the reset timers were cleared on unmount, and clicking twice reset the label early because the first timer still fired. Add one shared implementation and move every copy action onto it: - useCopyToClipboard (src/hooks) writes through the Clipboard API and falls back to a hidden textarea where the API is missing (non-secure origins, older browsers), giving focus back to the button afterwards. copy() resolves to true or false so each caller shows its own error. It keeps a single "copied" key with an optional per-item key for lists (goals, resume sections), restarts the 2 s timer on a repeat copy, and clears it on unmount. - CopyFeedback (src/components/ui) renders the button contents: a copy icon that pops into a checkmark (motion-safe, so reduced motion turns it off) with an optional "Copied!" label in the success colour. Icon-only and accent-filled buttons have props for their layout. - Profile link, duel link, goal share link, settings profile URL, streak stats, weekly AI summary, badge markdown, webhook secret, resume text and resume sections all use the pair. Failures that were silent now show an error toast, and existing success toasts are unchanged. Tests cover the clipboard fallback and its failure modes, the copied window and its reset, per-key state, restarting the timer, cleanup on unmount, and the CopyFeedback states. docs/architecture.md points new copy actions at the hook and component. Closes Priyanshu-byte-coder#1937
officialasishkumar
requested a review
from Priyanshu-byte-coder
as a code owner
November 19, 2026 21:47
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the reusable copy-to-clipboard behaviour from #1937 and moves every copy action in the app onto it. Each copy button now shows the same feedback: a checkmark that pops in and a "Copied!" label for 2 seconds. Failures that were silent now show an error. Before this, nine places had their own clipboard code with different labels ("Copied!", "Copied", "✓ Copied!", icon-only), and some only logged to the console on failure or did nothing at all.
Closes #1937
Type of Change
What Changed
src/hooks/useCopyToClipboard.ts(new)copyToClipboard(text)uses the Clipboard API where it exists. It falls back to a hidden textarea andexecCommand("copy")where the API is missing (plain-HTTP/LAN previews, older browsers), then gives focus back to the button.useCopyToClipboard()returnscopy(text, key?), which resolves totrue/falseso each caller keeps its own error message, andisCopied(key?).keylets a list mark only the clicked item (goals, resume sections). Copying again restarts the 2 s timer instead of being cut short by the old one, and the timer is cleared on unmount.src/components/ui/copy-feedback.tsx(new):CopyFeedbackrenders the button contents. A copy icon turns into a checkmark with a short pop animation (motion-safe, so it's off for reduced motion), with an optional label in--success. Props cover icon-only buttons, icon sizes, and buttons on an accent fill that keep their own text colour.tailwind.config.ts: thecopy-popkeyframe and animation.CopyLinkButton, used for the profile link and the duel link.GoalTracker: goal share link.useStreakTracker/StreakTracker: streak stats.WeeklySummaryCard: AI summary. This one also fixes an unhandled promise rejection when the copy failed.BadgeSection: badge markdown.WebhookManager: new webhook secret.ExportPanel/ResumePreview: resume text and sections.test/useCopyToClipboard.test.tsxcovers the Clipboard API path, the fallback (selected value, cleanup, focus restore), the rejected and unsupported cases, the copied window and its reset, per-key state, restarting the timer, a custom delay, and cleanup on unmount and after an unmount mid-copy.test/components/CopyFeedback.test.tsxcovers the icon/label states and the props.docs/architecture.md: a short paragraph pointing new copy actions at the hook and component.How to Test
pnpm vitest run test/useCopyToClipboard.test.tsx test/components/CopyFeedback.test.tsx test/StreakTracker.test.tsnavigator.clipboardis undefined, and copy again.Expected result: Each button shows the checkmark and "Copied!" (icon-only buttons show just the checkmark) for 2 seconds, measured from the latest click. Only the clicked goal or section is marked. Copying still works over plain HTTP, and when copying fails an error toast appears instead of nothing.
Screenshots / Recordings
Every changed button now looks like this: a copy icon next to the existing label at rest, and a checkmark with "Copied!" in the theme's success colour for two seconds after a click.
Checklist
console.log, debug code, or commented-out blocksnpm run lintpasses locallynpm run type-check)Accessibility (UI changes only)
--successtheme colour, as the summary card already did)aria-hidden, existing labels are kept, and failures are announced through the toast)Additional Context
mainand covers everyclipboard.writeTextcall. After this change,useCopyToClipboard.tsis the only file that touches the clipboard.tsc --noEmit, ESLint and Prettier on the changed files. I also checked that Tailwind emitsmotion-safe:animate-copy-pop.maxDiffPixelRatioof 0.15.