Skip to content

Refactor duplicated date formatting, normalization, and breadcrumb code - #122

Merged
marcelo-m7 merged 4 commits into
mainfrom
copilot/refactor-duplicated-code-another-one
Nov 1, 2025
Merged

marcelo-m7 merged 4 commits into
mainfrom
copilot/refactor-duplicated-code-another-one

Conversation

Copilot AI commented Nov 1, 2025 •

Copy link
Copy Markdown
Contributor

Identified and extracted three patterns of code duplication across the codebase: date formatting logic, data normalization functions, and breadcrumb components.

Changes

Date Formatting (lib/i18n.ts)

  • Added createDateFormatter() and formatDate() utilities with locale fallback handling
  • Refactored 5 files: Blog, Projects, Dashboard, blog/[slug], CommentsSection
  • Eliminated ~70 lines of duplicated formatter initialization and error handling
// Before: repeated in every file
const normalizedLocale = getNormalizedLocale(i18n.language);
const dateFormatter = useMemo(() => {
  try {
    return new Intl.DateTimeFormat(normalizedLocale, { dateStyle: 'medium' });
  } catch (error) {
    return new Intl.DateTimeFormat('en-US', { dateStyle: 'medium' });
  }
}, [normalizedLocale]);

// After: single utility call
const dateFormatter = useMemo(
  () => createDateFormatter(i18n.language, { dateStyle: 'medium' }),
  [i18n.language]
);

Data Normalization (lib/utils.ts)

  • Added normalizeToStringArray() and normalizeToTypedArray<T>() for parsing JSON/arrays from Supabase
  • Refactored Contact (project types) and About (stats) pages
  • Reduced ~60 lines of type-checking and parsing logic

Breadcrumb Component (components/PageBreadcrumb.tsx)

  • Extracted reusable breadcrumb component supporting optional intermediate items
  • Applied to 6 pages: Contact, Blog, Solutions, Projects, and detail pages
  • Removed ~150 lines of repeated breadcrumb markup
// Before: 20+ lines per page
<div className="max-w-7xl mx-auto px-4 pt-4">
  <Breadcrumb>
    <BreadcrumbList>
      <BreadcrumbItem>
        <BreadcrumbLink asChild>
          <Link to="/">{t('navigation.home')}</Link>
        </BreadcrumbLink>
      </BreadcrumbItem>
      {/* ... more boilerplate */}
    </BreadcrumbList>
  </Breadcrumb>
</div>

// After: single line
<PageBreadcrumb currentPage={t('navigation.blog')} />

Impact

  • Net reduction: 99 lines (-388 duplicated, +289 utilities)
  • Centralized maintenance for date formatting, normalization, and breadcrumbs
  • Type-safe generic utilities improve DX
Original prompt

Find and refactor duplicated code


✨ 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 self-assigned this Nov 1, 2025
Copilot AI and others added 3 commits November 1, 2025 20:12
- Create reusable date formatting utilities in lib/i18n.ts
- Create data normalization utilities in lib/utils.ts
- Update Blog.tsx, Projects.tsx, Dashboard.tsx, blog/[slug].tsx, and CommentsSection.tsx to use new date formatting utilities
- Update Contact.tsx and About.tsx to use new normalization utilities
- Reduce code duplication across 7 files

Co-authored-by: marcelo-m7 <117441129+marcelo-m7@users.noreply.github.com>
- Add PageBreadcrumb component to reduce breadcrumb duplication
- Update Contact.tsx, Blog.tsx, Solutions.tsx, Projects.tsx to use PageBreadcrumb
- Update blog/[slug].tsx and solutions/[slug].tsx to use PageBreadcrumb with intermediate items
- Remove ~150 lines of duplicated breadcrumb code across 6 pages

Co-authored-by: marcelo-m7 <117441129+marcelo-m7@users.noreply.github.com>
- Remove unused index parameter from map callback in PageBreadcrumb component

Co-authored-by: marcelo-m7 <117441129+marcelo-m7@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor duplicated code for improved maintainability Refactor duplicated date formatting, normalization, and breadcrumb code Nov 1, 2025
Copilot AI requested a review from marcelo-m7 November 1, 2025 20:20
@marcelo-m7
marcelo-m7 marked this pull request as ready for review November 1, 2025 20:21
@monynha-online

monynha-online Bot commented Nov 1, 2025 •

Copy link
Copy Markdown

The preview deployment is ready. 🟢

Open Preview | Open Build Logs

Last updated at: 2025-11-01 20:41:50 CET

@marcelo-m7
marcelo-m7 merged commit 63e877a into main Nov 1, 2025
3 of 4 checks passed
@marcelo-m7
marcelo-m7 deleted the copilot/refactor-duplicated-code-another-one branch November 1, 2025 20:56
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