11import React , { useState } from "react"
22
33import { useI18next } from "gatsby-plugin-react-i18next"
4- import { useQuery , gql } from "@apollo/client"
4+ import { gql } from "@apollo/client"
55
66import {
77 Avatar ,
@@ -12,7 +12,6 @@ import {
1212 ListItem ,
1313 ModalBody ,
1414 ModalHeader ,
15- Show ,
1615 Skeleton as ChakraSkeleton ,
1716 SkeletonCircle as ChakraSkeletonCircle ,
1817 Text ,
@@ -31,7 +30,7 @@ import Modal from "./Modal"
3130import Translation from "./Translation"
3231import Button from "./Button"
3332
34- interface Author {
33+ export interface Author {
3534 name : string
3635 email : string
3736 avatarUrl : string
@@ -41,7 +40,7 @@ interface Author {
4140 }
4241}
4342
44- interface Commit {
43+ export interface Commit {
4544 author : Author
4645 committedDate : string
4746}
@@ -121,48 +120,28 @@ const Contributor = ({ contributor }: { contributor: Author }) => {
121120export interface IProps extends FlexProps {
122121 relativePath : string
123122 editPath ?: string
123+ contributors : Array < Author >
124+ lastContributor : any
125+ loading : Boolean
126+ error : any
127+ lastEdit : string
124128}
125129
126130const FileContributors : React . FC < IProps > = ( {
127131 relativePath,
128132 editPath,
133+ contributors,
134+ lastContributor,
135+ loading,
136+ error,
137+ lastEdit,
129138 ...props
130139} ) => {
131140 const [ isModalOpen , setModalOpen ] = useState ( false )
132141 const { language } = useI18next ( )
133142
134- const { loading, error, data } = useQuery ( COMMIT_HISTORY , {
135- variables : { relativePath } ,
136- } )
137-
138143 if ( error ) return null
139144
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-
166145 return (
167146 < >
168147 < Modal isOpen = { isModalOpen } setIsOpen = { setModalOpen } >
@@ -174,12 +153,16 @@ const FileContributors: React.FC<IProps> = ({
174153
175154 < ModalBody >
176155 < 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 }
183166 </ ModalBody >
184167 </ Modal >
185168
@@ -211,7 +194,7 @@ const FileContributors: React.FC<IProps> = ({
211194 </ Link >
212195 ) }
213196 { ! lastContributor . user && < span > { lastContributor . name } </ span > } ,{ " " }
214- { getLocaleTimestamp ( language as Lang , lastCommit . committedDate ) }
197+ { getLocaleTimestamp ( language as Lang , lastEdit ) }
215198 </ Text >
216199 </ Skeleton >
217200 </ Flex >
@@ -235,24 +218,25 @@ const FileContributors: React.FC<IProps> = ({
235218 < Translation id = "see-contributors" />
236219 </ Button >
237220 </ Skeleton >
238-
239221 { 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 >
256240 ) }
257241 </ VStack >
258242 </ Flex >
0 commit comments