Skip to content

Commit 67e2dfb

Browse files
committed
Consolidate some related components to single files
1 parent 6afcd7a commit 67e2dfb

File tree

7 files changed

+227
-268
lines changed

7 files changed

+227
-268
lines changed

src/components/__tests__/contributors.test.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

src/components/contributors.js

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/components/header.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from 'react'
22
import {Box} from '@primer/react'
33
import styled from 'styled-components'
4-
import MobileSearch from './mobile-search'
4+
import * as Search from './search'
55
import NavDrawer from './nav-drawer'
6-
import Search from './search'
76
import Link from './link'
87
import useSearch from '../hooks/use-search'
98
import {HEADER_HEIGHT, HEADER_BAR} from '../constants'
@@ -63,7 +62,7 @@ function Header() {
6362
{siteMetadata.title}
6463
</Link>
6564
<Box sx={{display: ['none', null, null, 'block'], ml: 4}}>
66-
<Search {...search} />
65+
<Search.Desktop {...search} />
6766
</Box>
6867
</Box>
6968
<Box sx={{display: 'flex'}}>
@@ -75,7 +74,7 @@ function Header() {
7574
))}
7675
</Box>
7776
<Box sx={{display: ['flex', null, null, 'none']}}>
78-
<MobileSearch {...search} />
77+
<Search.Mobile {...search} />
7978
<NavDrawer />
8079
</Box>
8180
</Box>

src/components/mobile-search.js

Lines changed: 0 additions & 166 deletions
This file was deleted.

src/components/page-footer.js

Lines changed: 58 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,65 @@
11
import React from 'react'
2-
import {Box, Octicon} from '@primer/react'
2+
import {Box, Octicon, Avatar, Text, Tooltip} from '@primer/react'
33
import {PencilIcon} from '@primer/octicons-react'
44
import Link from './link'
5-
import Contributors from './contributors'
65
import usePage from '../hooks/use-page'
76

8-
function PageFooter() {
7+
const months = [
8+
'January',
9+
'February',
10+
'March',
11+
'April',
12+
'May',
13+
'June',
14+
'July',
15+
'August',
16+
'September',
17+
'October',
18+
'November',
19+
'December',
20+
]
21+
22+
const format = d => `${months[d.getMonth()]} ${d.getDate()}, ${d.getFullYear()}`
23+
24+
const pluralize = (word, count) => `${word}${count === 1 ? '' : 's'}`
25+
26+
const Contributors = ({contributors = [], latestCommit}) => {
27+
if (!contributors.length) {
28+
return null
29+
}
30+
31+
return (
32+
<div>
33+
<Box sx={{display: 'flex', alignItems: 'center'}}>
34+
<Text sx={{mr: 2}}>
35+
{contributors.length} {pluralize('contributor', contributors.length)}
36+
</Text>
37+
{contributors.map(login => (
38+
<Tooltip key={login} aria-label={login}>
39+
<Link href={`https://github.com/${login}`} sx={{lineHeight: 'condensedUltra', mr: 2}}>
40+
<Avatar src={`https://github.com/${login}.png?size=40`} alt={login} />
41+
</Link>
42+
</Tooltip>
43+
))}
44+
</Box>
45+
{latestCommit ? (
46+
<Text sx={{fontSize: 1, color: 'fg.muted', mt: 1}}>
47+
Last edited by <Link href={`https://github.com/${latestCommit.login}`}>{latestCommit.login}</Link> on{' '}
48+
<Link href={latestCommit.url}>{format(new Date(latestCommit.date))}</Link>
49+
</Text>
50+
) : null}
51+
</div>
52+
)
53+
}
54+
55+
const PageFooter = () => {
956
const {editUrl, latestCommit, contributors = []} = usePage().pageContext
10-
return editUrl || contributors.length ? (
57+
58+
if (!editUrl && !contributors.length) {
59+
return null
60+
}
61+
62+
return (
1163
<Box
1264
sx={{
1365
borderWidth: 0,
@@ -26,10 +78,10 @@ function PageFooter() {
2678
Edit this page on GitHub
2779
</Link>
2880
) : null}
29-
{contributors.length ? <Contributors contributors={contributors} latestCommit={latestCommit} /> : null}
81+
<Contributors contributors={contributors} latestCommit={latestCommit} />
3082
</Box>
3183
</Box>
32-
) : null
84+
)
3385
}
3486

3587
export default PageFooter

0 commit comments

Comments
 (0)