Skip to content

Commit

Permalink
some refactoring to sidebar; fixed unclickable welcome page; renamed …
Browse files Browse the repository at this point in the history
…cloud rest api section pages to be in order (there was a gap)
  • Loading branch information
Kirill Bolotsky committed Aug 17, 2020
1 parent 0c395d8 commit 584f94c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 28 deletions.
4 changes: 1 addition & 3 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,8 @@ async function createDocPages({ graphql, actions, reporter }) {
slug ||
compose(
noTrailingSlash,
dedupePath,

removeGuidesAndRedirectWelcome,
dedupePath,
unorderify,
slugify,
)(path),
Expand Down Expand Up @@ -147,7 +146,6 @@ async function createDocPages({ graphql, actions, reporter }) {
compose(
noTrailingSlash,
dedupePath,

removeGuides,
unorderify,
slugify,
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/doc-layout/doc-layout.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ h2.sidebar-section-title {
}
}

.sidebarNodeWithChildren > a {
.sidebar-node-with-children > a {
&.sidebar-node-title_active {
&:after {
content: '';
Expand Down
60 changes: 36 additions & 24 deletions src/layouts/doc-layout/doc-layout.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ const SidebarNode = (props) => {
const {
node: { name, meta, children },
} = props;

const isLink = meta?.path;
const [isActive, setIsActive] = useState(false);

useEffect(() => {
Expand All @@ -143,29 +141,43 @@ const SidebarNode = (props) => {

const hasSubMenu = !_.isEmpty(children);

const nodes = {
externalLink: () => (
<a className={styles.sidebarNodeTitle} href={meta.redirect}>
{meta.title}
</a>
),
internalLink: () => (
<Link
className={`${styles.sidebarNodeTitle} ${
isActive ? styles.sidebarNodeTitle_active : ''
}`}
to={meta.path}
>
{meta.title}
</Link>
),
text: () => (
<Heading className={styles.sidebarNodeTitle} tag={'h3'} size={'sm'}>
{name}
</Heading>
),
};

const nodeType = () => {
if (meta.redirect) {
return 'externalLink';
}
if (meta.path) {
return 'internalLink';
}
return 'text';
};

return (
<div className={hasSubMenu ? styles.sidebarNodeWithChildren : ''}>
{isLink ? (
meta.redirect ? (
<a className={`${styles.sidebarNodeTitle}`} href={meta.redirect}>
{meta.title}
</a>
) : (
<Link
className={`${styles.sidebarNodeTitle} ${
isActive ? styles.sidebarNodeTitle_active : ''
}`}
to={meta.path}
>
{meta.title}
</Link>
)
) : (
<Heading className={styles.sidebarNodeTitle} tag={'h3'} size={'sm'}>
{name}
</Heading>
)}
{children && isActive && (
<div className={hasSubMenu ? styles.sidebarNodeWithChildren : undefined}>
{nodes[nodeType()]()}
{!!Object.keys(children).length && isActive && (
<div className={styles.sidebarNodeChildren}>
{childrenToList(children).map((node) => (
<SidebarNode node={node} key={node.name} />
Expand Down

0 comments on commit 584f94c

Please sign in to comment.