Skip to content

Commit d1f640c

Browse files
committed
refactor: FileContributor type
1 parent 77cd90d commit d1f640c

File tree

6 files changed

+19
-24
lines changed

6 files changed

+19
-24
lines changed

src/components/CrowdinContributors.tsx

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Author, CrowdinContributor } from "@/lib/types"
1+
import type { CrowdinContributor, FileContributor } from "@/lib/types"
22

33
import FileContributors from "@/components/FileContributors"
44

@@ -11,22 +11,17 @@ const CrowdinContributors = ({
1111
lastUpdatedDate,
1212
contributors,
1313
}: CrowdinContributorsProps) => {
14-
const mappedContributors: Author[] = contributors.map(
15-
({ id, username, avatarUrl }) => ({
16-
name: username,
17-
email: id.toString(),
18-
avatarUrl: avatarUrl,
19-
user: {
20-
login: username,
21-
url: `https://crowdin.com/profile/${username}`,
22-
},
14+
const mappedContributors: FileContributor[] = contributors.map(
15+
({ username, avatarUrl }) => ({
16+
login: username,
17+
avatar_url: avatarUrl,
18+
html_url: `https://crowdin.com/profile/${username}`,
19+
date: lastUpdatedDate,
2320
})
2421
)
2522

2623
return (
2724
<FileContributors
28-
error={mappedContributors.length === 0} // TODO: Confirm GH error handling
29-
loading={!mappedContributors.length}
3025
contributors={mappedContributors}
3126
lastEdit={lastUpdatedDate}
3227
/>

src/components/FileContributors.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
VStack,
1414
} from "@chakra-ui/react"
1515

16-
import type { GitHubContributor, Lang } from "@/lib/types"
16+
import type { FileContributor, Lang } from "@/lib/types"
1717

1818
import { Button } from "@/components/Buttons"
1919
import InlineLink from "@/components/Link"
@@ -30,7 +30,7 @@ const ContributorList = ({ children }: { children: React.ReactNode }) => (
3030
</UnorderedList>
3131
)
3232

33-
type ContributorProps = { contributor: GitHubContributor }
33+
type ContributorProps = { contributor: FileContributor }
3434
const Contributor = ({ contributor }: ContributorProps) => (
3535
<ListItem p={2} display="flex" alignItems="center">
3636
<Avatar
@@ -48,7 +48,7 @@ const Contributor = ({ contributor }: ContributorProps) => (
4848

4949
export type FileContributorsProps = FlexProps & {
5050
editPath?: string
51-
contributors: GitHubContributor[]
51+
contributors: FileContributor[]
5252
lastEdit: string
5353
}
5454

@@ -62,14 +62,14 @@ const FileContributors = ({
6262

6363
const isDesktop = useBreakpointValue({ base: false, md: true })
6464

65-
const lastContributor: GitHubContributor = contributors.length
65+
const lastContributor: FileContributor = contributors.length
6666
? contributors[0]
6767
: ({
6868
avatar_url: "",
6969
login: "",
7070
html_url: "",
7171
date: Date.now().toString(),
72-
} as GitHubContributor)
72+
} as FileContributor)
7373

7474
return (
7575
<>

src/components/GitHubContributors.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import type { FlexProps } from "@chakra-ui/react"
22

3-
import type { GitHubContributor } from "@/lib/types"
3+
import type { FileContributor } from "@/lib/types"
44

55
import FileContributors from "@/components/FileContributors"
66

77
export type GitHubContributors = FlexProps & {
88
editPath?: string
99
lastUpdatedDate: string
10-
contributors: GitHubContributor[]
10+
contributors: FileContributor[]
1111
}
1212

1313
const GitHubContributors = ({

src/lib/api/fetchGitHistory.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "fs"
22
import { join } from "path"
33

4-
import type { GitHubContributor } from "@/lib/types"
4+
import type { FileContributor } from "@/lib/types"
55

66
import {
77
COMMIT_HISTORY_JSON,
@@ -66,7 +66,7 @@ export const fetchAndSaveGitHistory = async (mdDir: string) => {
6666
const { login, avatar_url, html_url } = contribution.author
6767
const { date } = contribution.commit.author
6868
return { login, avatar_url, html_url, date }
69-
}) as GitHubContributor[]
69+
}) as FileContributor[]
7070

7171
// Remove duplicates from same login
7272
const uniqueContributors = contributors.filter(

src/lib/interfaces.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import type { StaticImageData } from "next/image"
33
import type {
44
CrowdinContributor,
55
Frontmatter,
6-
GitHubContributor,
6+
FileContributor,
77
Lang,
88
Layout,
99
ToCItem,
@@ -108,7 +108,7 @@ export interface MdPageContent {
108108
lastUpdatedDate?: string
109109
contentNotTranslated: boolean
110110
crowdinContributors: CrowdinContributor[]
111-
contributors: GitHubContributor[]
111+
contributors: FileContributor[]
112112
}
113113

114114
// Local environment framework

src/lib/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ export type Author = {
370370
}
371371
}
372372

373-
export type GitHubContributor = {
373+
export type FileContributor = {
374374
login: string
375375
avatar_url: string
376376
html_url: string

0 commit comments

Comments
 (0)