1
1
import React , { useState } from "react"
2
2
3
3
import { useI18next } from "gatsby-plugin-react-i18next"
4
- import { useQuery , gql } from "@apollo/client"
4
+ import { gql } from "@apollo/client"
5
5
6
6
import {
7
7
Avatar ,
@@ -12,7 +12,6 @@ import {
12
12
ListItem ,
13
13
ModalBody ,
14
14
ModalHeader ,
15
- Show ,
16
15
Skeleton as ChakraSkeleton ,
17
16
SkeletonCircle as ChakraSkeletonCircle ,
18
17
Text ,
@@ -31,7 +30,7 @@ import Modal from "./Modal"
31
30
import Translation from "./Translation"
32
31
import Button from "./Button"
33
32
34
- interface Author {
33
+ export interface Author {
35
34
name : string
36
35
email : string
37
36
avatarUrl : string
@@ -41,7 +40,7 @@ interface Author {
41
40
}
42
41
}
43
42
44
- interface Commit {
43
+ export interface Commit {
45
44
author : Author
46
45
committedDate : string
47
46
}
@@ -121,48 +120,28 @@ const Contributor = ({ contributor }: { contributor: Author }) => {
121
120
export interface IProps extends FlexProps {
122
121
relativePath : string
123
122
editPath ?: string
123
+ contributors : Array < Author >
124
+ lastContributor : any
125
+ loading : Boolean
126
+ error : any
127
+ lastEdit : string
124
128
}
125
129
126
130
const FileContributors : React . FC < IProps > = ( {
127
131
relativePath,
128
132
editPath,
133
+ contributors,
134
+ lastContributor,
135
+ loading,
136
+ error,
137
+ lastEdit,
129
138
...props
130
139
} ) => {
131
140
const [ isModalOpen , setModalOpen ] = useState ( false )
132
141
const { language } = useI18next ( )
133
142
134
- const { loading, error, data } = useQuery ( COMMIT_HISTORY , {
135
- variables : { relativePath } ,
136
- } )
137
-
138
143
if ( error ) return null
139
144
140
- const commits : Array < Commit > =
141
- data ?. repository ?. ref ?. target ?. history ?. edges ?. map ( ( commit ) => commit . node )
142
-
143
- const lastCommit = commits ?. [ 0 ] || { }
144
- const lastContributor = lastCommit ?. author || { }
145
- const uniqueContributors =
146
- commits ?. reduce (
147
- ( res : Array < Author > , cur : Commit ) => {
148
- if ( cur . author . user === null ) {
149
- return res
150
- }
151
- for ( const contributor of res ) {
152
- const hasAuthorInfo = ! ! contributor . user && ! ! cur . author . user
153
- if (
154
- hasAuthorInfo &&
155
- contributor . user . login === cur . author . user . login
156
- ) {
157
- return res
158
- }
159
- }
160
- res . push ( cur . author )
161
- return res
162
- } ,
163
- [ lastContributor ]
164
- ) || [ ]
165
-
166
145
return (
167
146
< >
168
147
< Modal isOpen = { isModalOpen } setIsOpen = { setModalOpen } >
@@ -174,12 +153,16 @@ const FileContributors: React.FC<IProps> = ({
174
153
175
154
< ModalBody >
176
155
< Translation id = "contributors-thanks" />
177
-
178
- < ContributorList >
179
- { uniqueContributors . map ( ( contributor ) => (
180
- < Contributor contributor = { contributor } key = { contributor . email } />
181
- ) ) }
182
- </ ContributorList >
156
+ { contributors ? (
157
+ < ContributorList >
158
+ { contributors . map ( ( contributor ) => (
159
+ < Contributor
160
+ contributor = { contributor }
161
+ key = { contributor . email }
162
+ />
163
+ ) ) }
164
+ </ ContributorList >
165
+ ) : null }
183
166
</ ModalBody >
184
167
</ Modal >
185
168
@@ -211,7 +194,7 @@ const FileContributors: React.FC<IProps> = ({
211
194
</ Link >
212
195
) }
213
196
{ ! lastContributor . user && < span > { lastContributor . name } </ span > } ,{ " " }
214
- { getLocaleTimestamp ( language as Lang , lastCommit . committedDate ) }
197
+ { getLocaleTimestamp ( language as Lang , lastEdit ) }
215
198
</ Text >
216
199
</ Skeleton >
217
200
</ Flex >
@@ -235,24 +218,25 @@ const FileContributors: React.FC<IProps> = ({
235
218
< Translation id = "see-contributors" />
236
219
</ Button >
237
220
</ Skeleton >
238
-
239
221
{ editPath && (
240
- < Show below = "l" >
241
- { /* TODO: switch `l` to `lg` after UI migration and use `hideBelow` prop */ }
242
- < ButtonLink to = { editPath } hideArrow variant = "outline" >
243
- < Flex
244
- h = "100%"
245
- alignItems = "center"
246
- justifyContent = "center"
247
- gap = { 2 }
248
- >
249
- < Icon as = { FaGithub } fontSize = "2xl" />
250
- < span >
251
- < Translation id = "edit-page" />
252
- </ span >
253
- </ Flex >
254
- </ ButtonLink >
255
- </ Show >
222
+ < ButtonLink
223
+ to = { editPath }
224
+ hideArrow
225
+ variant = "outline"
226
+ hideBelow = "lg"
227
+ >
228
+ < Flex
229
+ h = "100%"
230
+ alignItems = "center"
231
+ justifyContent = "center"
232
+ gap = { 2 }
233
+ >
234
+ < Icon as = { FaGithub } fontSize = "2xl" />
235
+ < span >
236
+ < Translation id = "edit-page" />
237
+ </ span >
238
+ </ Flex >
239
+ </ ButtonLink >
256
240
) }
257
241
</ VStack >
258
242
</ Flex >
0 commit comments