Skip to content

Refactor duplicated date formatting and breadcrumb navigation code - #120

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

marcelo-m7 merged 4 commits into
devfrom
copilot/refactor-duplicated-code

Conversation

Copilot AI commented Nov 1, 2025 •

Copy link
Copy Markdown
Contributor

Identified and eliminated ~256 lines of duplicated code related to date formatting and breadcrumb navigation across multiple page components.

Changes

useLocalizedDateFormatter Hook

Created a reusable hook consolidating date formatting logic previously duplicated across 5 files:

  • Locale-aware formatting with automatic fallback to en-US
  • Configurable null/undefined handling via nullFallback option
  • Date validation to catch invalid date strings early
  • Separated date parsing from formatting error handling to avoid redundant operations

Before:

const normalizedLocale = useMemo(() => getNormalizedLocale(i18n.language), [i18n.language]);
const fallbackDateFormatter = useMemo(() => new Intl.DateTimeFormat('en-US', { dateStyle: 'medium' }), []);
const dateFormatter = useMemo(() => {
  try {
    return new Intl.DateTimeFormat(normalizedLocale, { dateStyle: 'medium' });
  } catch (error) {
    console.error('Unsupported locale for blog date formatting', error);
    return new Intl.DateTimeFormat('en-US', { dateStyle: 'medium' });
  }
}, [normalizedLocale]);

After:

const { formatDate } = useLocalizedDateFormatter({
  dateOptions: { dateStyle: 'medium' }
});

Applied to: Projects.tsx, Blog.tsx, Dashboard.tsx, blog/[slug].tsx, CommentsSection.tsx

PageBreadcrumb Component

Extracted breadcrumb navigation structure duplicated across 4 pages:

  • Standardized home → page navigation pattern
  • Supports optional intermediate breadcrumb items
  • Consistent styling and i18n integration

Applied to: Blog.tsx, Contact.tsx, Projects.tsx, Solutions.tsx

Original prompt

Find and refactor duplicated code


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits November 1, 2025 20:13
…adcrumb component

Co-authored-by: marcelo-m7 <117441129+marcelo-m7@users.noreply.github.com>
…configurable options

Co-authored-by: marcelo-m7 <117441129+marcelo-m7@users.noreply.github.com>
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 and breadcrumb navigation code Nov 1, 2025
Copilot AI requested a review from marcelo-m7 November 1, 2025 20:19
@marcelo-m7
marcelo-m7 marked this pull request as ready for review November 1, 2025 20:26

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/pages/Blog.tsx
@@ -1,10 +1,11 @@
import { useState, useMemo, useCallback } from 'react';
import { useState, useMemo } from 'react';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Restore useCallback import in Blog page

The top-level React import drops useCallback, but handlePageChange still calls useCallback later in this file. This will cause a compile/runtime failure (useCallback is not defined) when building the blog page. Re‑add useCallback to the import list so the pagination handler continues to work.

Useful? React with 👍 / 👎.

@marcelo-m7
marcelo-m7 merged commit e2af7f9 into dev Nov 1, 2025
1 of 4 checks passed
@marcelo-m7
marcelo-m7 deleted the copilot/refactor-duplicated-code branch November 1, 2025 20:43
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