Skip to content

Commit 77cd90d

Browse files
committed
feat: *Contributors components to accept contributors array
1 parent 43b4443 commit 77cd90d

File tree

2 files changed

+51
-92
lines changed

2 files changed

+51
-92
lines changed

src/components/FileContributors.tsx

Lines changed: 44 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ import {
88
ListItem,
99
ModalBody,
1010
ModalHeader,
11-
SkeletonText,
1211
UnorderedList,
1312
useBreakpointValue,
1413
VStack,
1514
} from "@chakra-ui/react"
1615

17-
import type { Author, Lang } from "@/lib/types"
16+
import type { GitHubContributor, Lang } from "@/lib/types"
1817

1918
import { Button } from "@/components/Buttons"
2019
import InlineLink from "@/components/Link"
@@ -25,56 +24,36 @@ import Translation from "@/components/Translation"
2524
import { trackCustomEvent } from "@/lib/utils/matomo"
2625
import { getLocaleTimestamp } from "@/lib/utils/time"
2726

28-
// TODO: skeletons are not part of the DS, so these should be replaced once we
29-
// implement the new designs. Thats the reason we haven't define these styles in
30-
// the theme config file
31-
const skeletonColorProps = {
32-
startColor: "lightBorder",
33-
endColor: "searchBackgroundEmpty",
34-
}
35-
36-
const Skeleton = (props) => <SkeletonText {...skeletonColorProps} {...props} />
37-
38-
const ContributorList = ({ children }: { children: React.ReactNode }) => {
39-
return (
40-
<UnorderedList maxH="2xs" m={0} mt={6} overflowY="scroll">
41-
{children}
42-
</UnorderedList>
43-
)
44-
}
45-
46-
const Contributor = ({ contributor }: { contributor: Author }) => {
47-
return (
48-
<ListItem p={2} display="flex" alignItems="center">
49-
<Avatar
50-
height="40px"
51-
width="40px"
52-
src={contributor.avatarUrl}
53-
name={contributor.name}
54-
me={2}
55-
/>
56-
{contributor.user && (
57-
<InlineLink href={contributor.user.url}>
58-
@{contributor.user.login}
59-
</InlineLink>
60-
)}
61-
{!contributor.user && <span>{contributor.name}</span>}
62-
</ListItem>
63-
)
64-
}
27+
const ContributorList = ({ children }: { children: React.ReactNode }) => (
28+
<UnorderedList maxH="2xs" m={0} mt={6} overflowY="scroll">
29+
{children}
30+
</UnorderedList>
31+
)
32+
33+
type ContributorProps = { contributor: GitHubContributor }
34+
const Contributor = ({ contributor }: ContributorProps) => (
35+
<ListItem p={2} display="flex" alignItems="center">
36+
<Avatar
37+
height="40px"
38+
width="40px"
39+
src={contributor.avatar_url}
40+
name={contributor.login}
41+
me={2}
42+
/>
43+
<InlineLink href={"https://github.com/" + contributor.login}>
44+
@{contributor.login}
45+
</InlineLink>
46+
</ListItem>
47+
)
6548

6649
export type FileContributorsProps = FlexProps & {
6750
editPath?: string
68-
contributors: Author[]
69-
loading: boolean
70-
error?: boolean
51+
contributors: GitHubContributor[]
7152
lastEdit: string
7253
}
7354

7455
const FileContributors = ({
7556
contributors,
76-
loading,
77-
error,
7857
lastEdit,
7958
...props
8059
}: FileContributorsProps) => {
@@ -83,18 +62,14 @@ const FileContributors = ({
8362

8463
const isDesktop = useBreakpointValue({ base: false, md: true })
8564

86-
if (error) return null
87-
const lastContributor: Author = contributors.length
65+
const lastContributor: GitHubContributor = contributors.length
8866
? contributors[0]
89-
: {
90-
name: "",
91-
email: "",
92-
avatarUrl: "",
93-
user: {
94-
login: "",
95-
url: "",
96-
},
97-
}
67+
: ({
68+
avatar_url: "",
69+
login: "",
70+
html_url: "",
71+
date: Date.now().toString(),
72+
} as GitHubContributor)
9873

9974
return (
10075
<>
@@ -107,18 +82,12 @@ const FileContributors = ({
10782

10883
<ModalBody>
10984
<Translation id="contributors-thanks" />
110-
<Skeleton noOfLines="4" mt="4" isLoaded={!loading}>
111-
{contributors ? (
112-
<ContributorList>
113-
{contributors.map((contributor) => (
114-
<Contributor
115-
contributor={contributor}
116-
key={contributor.email}
117-
/>
118-
))}
119-
</ContributorList>
120-
) : null}
121-
</Skeleton>
85+
86+
<ContributorList>
87+
{contributors.map((contributor) => (
88+
<Contributor contributor={contributor} key={contributor.login} />
89+
))}
90+
</ContributorList>
12291
</ModalBody>
12392
</Modal>
12493

@@ -136,20 +105,19 @@ const FileContributors = ({
136105
<Avatar
137106
height="40px"
138107
width="40px"
139-
src={lastContributor.avatarUrl}
140-
name={lastContributor.name}
108+
src={lastContributor.avatar_url}
109+
name={lastContributor.login}
141110
me={2}
142111
/>
143112

144113
<Text m={0} color="text200">
145114
<Translation id="last-edit" />:{" "}
146-
{lastContributor.user?.url && (
147-
<InlineLink href={lastContributor.user.url}>
148-
@{lastContributor.user.login}
149-
</InlineLink>
150-
)}
151-
{!lastContributor.user && <span>{lastContributor.name}</span>},{" "}
152-
{getLocaleTimestamp(locale as Lang, lastEdit)}
115+
<InlineLink
116+
href={"https://github.com/" + lastContributor.login}
117+
>
118+
@{lastContributor.login}
119+
</InlineLink>
120+
, {getLocaleTimestamp(locale as Lang, lastEdit)}
153121
</Text>
154122
</>
155123
)}

src/components/GitHubContributors.tsx

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

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

5-
import { useClientSideGitHubContributors } from "@/hooks/useClientSideGitHubContributors"
5+
import FileContributors from "@/components/FileContributors"
66

77
export type GitHubContributors = FlexProps & {
8-
relativePath: string
98
editPath?: string
109
lastUpdatedDate: string
10+
contributors: GitHubContributor[]
1111
}
1212

1313
const GitHubContributors = ({
14-
relativePath,
1514
lastUpdatedDate,
16-
}: GitHubContributors) => {
17-
const state = useClientSideGitHubContributors(relativePath)
18-
19-
return (
20-
<FileContributors
21-
error={"error" in state}
22-
loading={state.loading as boolean}
23-
contributors={"data" in state ? state.data : []}
24-
lastEdit={lastUpdatedDate}
25-
/>
26-
)
27-
}
15+
contributors,
16+
}: GitHubContributors) => (
17+
<FileContributors contributors={contributors} lastEdit={lastUpdatedDate} />
18+
)
2819

2920
export default GitHubContributors

0 commit comments

Comments
 (0)