Skip to content

Commit 92f64cd

Browse files
committed
Wrap tabs at project pages with 'a' tag. (fixes #2)
1 parent d334056 commit 92f64cd

2 files changed

Lines changed: 14 additions & 15 deletions

File tree

molecules/TabSwitch.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import NextLink from 'next/link'
12
import React, { useState } from 'react'
2-
import { Flex, Center, Box } from '@chakra-ui/react'
3+
import { Flex, Center, Box, Link } from '@chakra-ui/react'
34

45
const itemStyles = {
56
p: '12px',
@@ -19,9 +20,14 @@ const itemActiveStyles = {
1920
borderColor: 'secondary.300',
2021
}
2122

22-
export const Tab = ({ children, active, ...rest }) => (
23-
<Center {...itemStyles} {...(active ? itemActiveStyles : {})} {...rest}>{children}</Center>
24-
)
23+
export const Tab = ({ children, active, href, ...rest }) => {
24+
const el = (<Center {...itemStyles} {...(active ? itemActiveStyles : {})} {...rest}>{children}</Center>)
25+
return href ? (
26+
<NextLink href={href} passHref>
27+
<Link style={{textDecoration: "none"}}>{el}</Link>
28+
</NextLink>
29+
) : el
30+
}
2531

2632
const TabContainer = ({ children, ...rest }) => (
2733
<Box {...containerStyles} {...rest}>{children}</Box>

pages/[project].js

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,6 @@ export default function Project({ error, project, tab }) {
180180
return <ErrorPage statusCode={error.status} />
181181
}
182182

183-
const onChangeTab = tab => {
184-
router.push({
185-
pathname: '/[project]',
186-
query: { project: name, tab }
187-
}, tab === 'readme' ? `/${encodeURIComponent(name)}` : null, { scroll: false })
188-
}
189-
190183
return (
191184
<DefaultLayout title={`${name} | Quickdocs`} description={description}>
192185
<SimpleGrid columns={[1, 1, 1, 10]} rowGap={5} columnGap={10} templateRows="min-content minmax(0, auto)">
@@ -200,9 +193,9 @@ export default function Project({ error, project, tab }) {
200193
<ProjectMetadataSection upstreamUrl={upstream_url} authors={authors} maintainers={maintainers} licenses={licenses} />
201194
</GridItem>
202195
<GridItem colSpan={[1, 1, 1, 7]}>
203-
<TabSwitch tab={tab} onChange={onChangeTab}>
204-
<Tab name="readme">README</Tab>
205-
<Tab name="systems">Provided Systems</Tab>
196+
<TabSwitch tab={tab}>
197+
<Tab name="readme" href={`/${encodeURIComponent(name)}`}>README</Tab>
198+
<Tab name="systems" href={`/${encodeURIComponent(name)}?tab=systems`}>Provided Systems</Tab>
206199
</TabSwitch>
207200
<Box py="15px">
208201
{tab === 'readme'
@@ -218,7 +211,7 @@ export default function Project({ error, project, tab }) {
218211
<Wrap>
219212
{depends_on.map(name => (
220213
<WrapItem key={`dependencies_${name}`}>
221-
<NextLink href={`/${encodeURIComponent(name)}`}>
214+
<NextLink href={`/${encodeURIComponent(name)}`} passHref>
222215
<Link fontWeight="bold" color="gray.700">{name}</Link>
223216
</NextLink>
224217
</WrapItem>

0 commit comments

Comments
 (0)