Skip to content

Refactor Header component to use shareHandler utility#21

Merged
AccessiT3ch merged 3 commits intofeature/phase1.4-web-api-error-handlingfrom
copilot/sub-pr-20
Feb 1, 2026
Merged

Refactor Header component to use shareHandler utility#21
AccessiT3ch merged 3 commits intofeature/phase1.4-web-api-error-handlingfrom
copilot/sub-pr-20

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 1, 2026

The Header component duplicated error handling logic that already exists in the shareHandler utility function, creating maintenance burden and violating DRY principles.

Changes

  • Replaced inline error handling (feature detection, try-catch, error categorization) with shareHandler call using callbacks
  • Preserved alert-based user feedback for clipboard copy and error cases (Header lacks visual status display unlike Share component)
  • Reduced Share button handler from 45 lines to 17 lines

Before

onClick={async () => {
  try {
    if (!navigator.share && (!navigator.clipboard || !navigator.clipboard.writeText)) {
      throw new Error("Share and Clipboard APIs are not supported");
    }
    if (navigator.share) {
      await navigator.share({ title, url });
      // ...
    } else {
      await navigator.clipboard.writeText(url);
      // ...
    }
  } catch (error) {
    if (error.name === "AbortError") { /* ... */ }
    if (error.name === "NotAllowedError") { /* ... */ }
    // ...
  }
}}

After

onClick={async () => {
  await shareHandler({
    shareUrl: window.location.href,
    shareTitle: document.title,
    onSuccess: (message) => {
      setShareStatus({ type: "success", message });
      if (message.includes("clipboard")) alert(message);
      setTimeout(() => setShareStatus({ type: null, message: "" }), 3000);
    },
    onError: (message) => {
      setShareStatus({ type: "error", message });
      alert(message.includes("Permission denied") ? message : `Share failed: ${message}`);
      setTimeout(() => setShareStatus({ type: null, message: "" }), 5000);
    },
  });
}}

This follows the same pattern as Share.jsx (lines 12-36) and centralizes error handling in the utility function.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits February 1, 2026 08:05
Co-authored-by: AccessiT3ch <95449364+AccessiT3ch@users.noreply.github.com>
Co-authored-by: AccessiT3ch <95449364+AccessiT3ch@users.noreply.github.com>
Copilot AI changed the title [WIP] Update comprehensive error handling for web APIs Refactor Header component to use shareHandler utility Feb 1, 2026
Copilot AI requested a review from AccessiT3ch February 1, 2026 08:07
@AccessiT3ch AccessiT3ch marked this pull request as ready for review February 1, 2026 08:09
@AccessiT3ch AccessiT3ch merged commit c35ea50 into feature/phase1.4-web-api-error-handling Feb 1, 2026
1 check passed
@AccessiT3ch AccessiT3ch deleted the copilot/sub-pr-20 branch February 1, 2026 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants