Skip to content

Commit adb2e32

Browse files
committed
refactor: use IssueMetadata across components to reduce duplication
1 parent 4b93f3e commit adb2e32

File tree

2 files changed

+53
-30
lines changed

2 files changed

+53
-30
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { faCalendar, faFolderOpen } from '@fortawesome/free-solid-svg-icons';
2+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3+
import { useRouter } from 'next/navigation';
4+
import React from 'react';
5+
import type { Issue } from 'types/issue';
6+
import { formatDate } from 'utils/dateFormatter';
7+
import { TruncatedText } from 'components/TruncatedText';
8+
9+
// Props interface
10+
interface IssueMetadataProps {
11+
issue: Issue;
12+
}
13+
14+
/**
15+
* Reusable component to display issue metadata (created date and repository link)
16+
*/
17+
export const IssueMetadata: React.FC<IssueMetadataProps> = ({ issue }) => {
18+
const router = useRouter();
19+
20+
return (
21+
<div className="mt-2 flex flex-wrap items-center text-sm text-gray-600 dark:text-gray-400">
22+
{/* Created Date */}
23+
<div className="mr-4 flex items-center">
24+
<FontAwesomeIcon icon={faCalendar} className="mr-2 h-4 w-4" />
25+
<span>{formatDate(issue.createdAt)}</span>
26+
</div>
27+
28+
{/* Repository Link */}
29+
{issue.repositoryName && (
30+
<div className="flex flex-1 items-center overflow-hidden">
31+
<FontAwesomeIcon icon={faFolderOpen} className="mr-2 h-5 w-4" />
32+
<button
33+
className="cursor-pointer overflow-hidden text-ellipsis whitespace-nowrap text-gray-600 hover:underline dark:text-gray-400"
34+
onClick={() =>
35+
router.push(
36+
`/organizations/${issue.organizationName}/repositories/${issue.repositoryName}`
37+
)
38+
}
39+
>
40+
<TruncatedText text={issue.repositoryName} />
41+
</button>
42+
</div>
43+
)}
44+
</div>
45+
);
46+
};
47+
48+
export default IssueMetadata;
Lines changed: 5 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,31 @@
1-
import { faCalendar, faFolderOpen, faCircleExclamation } from '@fortawesome/free-solid-svg-icons'
1+
import { faCircleExclamation } from '@fortawesome/free-solid-svg-icons'
22
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
3-
import { useRouter } from 'next/navigation'
43
import React from 'react'
54
import type { Issue } from 'types/issue'
6-
import { formatDate } from 'utils/dateFormatter'
75
import AnchorTitle from 'components/AnchorTitle'
86
import ItemCardList from 'components/ItemCardList'
9-
import { TruncatedText } from 'components/TruncatedText'
7+
import { IssueMetadata } from 'components/IssueMetadata' // ← new reusable component
108

119
interface RecentIssuesProps {
1210
data: Issue[]
1311
showAvatar?: boolean
1412
}
1513

1614
const RecentIssues: React.FC<RecentIssuesProps> = ({ data, showAvatar = true }) => {
17-
const router = useRouter()
18-
1915
return (
2016
<ItemCardList
2117
title={
2218
<div className="flex items-center gap-2">
2319
<AnchorTitle title="Recent Issues" className="flex items-center leading-none" />
20+
<FontAwesomeIcon icon={faCircleExclamation} className="h-5 w-5 text-red-500" />
2421
</div>
2522
}
2623
data={data}
2724
showAvatar={showAvatar}
2825
icon={faCircleExclamation}
29-
renderDetails={(item) => (
30-
<div className="mt-2 flex flex-wrap items-center text-sm text-gray-600 dark:text-gray-400">
31-
<div className="mr-4 flex items-center">
32-
<FontAwesomeIcon icon={faCalendar} className="mr-2 h-4 w-4" />
33-
<span>{formatDate(item.createdAt)}</span>
34-
</div>
35-
{item?.repositoryName && (
36-
<div className="flex flex-1 items-center overflow-hidden">
37-
<FontAwesomeIcon icon={faFolderOpen} className="mr-2 h-5 w-4" />
38-
<button
39-
className="cursor-pointer overflow-hidden text-ellipsis whitespace-nowrap text-gray-600 hover:underline dark:text-gray-400"
40-
onClick={() =>
41-
router.push(
42-
`/organizations/${item.organizationName}/repositories/${item.repositoryName}`
43-
)
44-
}
45-
>
46-
<TruncatedText text={item.repositoryName} />
47-
</button>
48-
</div>
49-
)}
50-
</div>
51-
)}
26+
renderDetails={(item) => <IssueMetadata issue={item} />}
5227
/>
5328
)
5429
}
5530

56-
export default RecentIssues
31+
export default RecentIssues

0 commit comments

Comments
 (0)