Skip to content

Commit b2a242d

Browse files
committed
Explicitly define the return of menu
1 parent ef1f781 commit b2a242d

File tree

4 files changed

+59
-6
lines changed

4 files changed

+59
-6
lines changed

theme/src/components/Sidebar.tsx

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export interface SidebarProps {
1212
}
1313

1414
export const Sidebar = ({ location, current }: SidebarProps) => {
15+
// The GraphQL query is limited by hard coded recursion.
1516
const {
1617
menu: { data: data },
1718
site: {
@@ -21,7 +22,56 @@ export const Sidebar = ({ location, current }: SidebarProps) => {
2122
graphql`
2223
query MenuQuery {
2324
menu(id: { eq: "menu" }) {
24-
data
25+
data {
26+
id
27+
label
28+
info {
29+
id
30+
url
31+
order
32+
title
33+
}
34+
items {
35+
id
36+
label
37+
info {
38+
id
39+
url
40+
order
41+
title
42+
}
43+
items {
44+
id
45+
label
46+
info {
47+
id
48+
url
49+
order
50+
title
51+
}
52+
items {
53+
id
54+
label
55+
info {
56+
id
57+
url
58+
order
59+
title
60+
}
61+
items {
62+
id
63+
label
64+
info {
65+
id
66+
url
67+
order
68+
title
69+
}
70+
}
71+
}
72+
}
73+
}
74+
}
2575
}
2676
site {
2777
siteMetadata {

theme/src/components/Tree.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ export const Tree = ({
8181
items={[]}
8282
/>
8383
)}
84-
{data.items.map((item, index) => (
84+
{(data.items || []).map((item, index) => (
8585
<TreeNode
8686
key={`${item.label}-${item.info && item.info.url}`}
8787
navigate={navigate}

theme/src/components/TreeNode.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {
22
Collapse,
3-
Icons,
43
List,
54
ListItem,
65
ListItemText,
@@ -13,6 +12,8 @@ import React from 'react'
1312
import { Info, Item } from '../types'
1413
import { firstUrl } from '../util/tree'
1514
import { useLayout } from '@committed/layout'
15+
import KeyboardArrowDownIcon from '@material-ui/icons/KeyboardArrowDown'
16+
import KeyboardArrowRightIcon from '@material-ui/icons/KeyboardArrowRight'
1617

1718
export interface TreeNodeProps extends Item {
1819
isActive: (id: string) => boolean
@@ -34,9 +35,9 @@ export const TreeNode = React.memo(
3435
level,
3536
label,
3637
info,
37-
items,
3838
...rest
3939
}: TreeNodeProps) => {
40+
const items = rest.items || []
4041
const theme = useTheme<Theme>()
4142
const { navVariant, setOpen } = useLayout()
4243
const url = firstUrl({ id, label, items, info })
@@ -76,9 +77,9 @@ export const TreeNode = React.memo(
7677
aria-label={isCollapsed ? 'expand' : 'collapse'}
7778
>
7879
{!isCollapsed ? (
79-
<Icons.KeyboardArrowDown />
80+
<KeyboardArrowDownIcon />
8081
) : (
81-
<Icons.KeyboardArrowRight />
82+
<KeyboardArrowRightIcon />
8283
)}
8384
</IconButton>
8485
</ListItemSecondaryAction>

theme/src/types/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ export interface Info {
3131
export interface Item extends Node {
3232
id: string
3333
label: string
34+
info?: Info
35+
items: Item[]
3436
}
3537

3638
export interface Link {

0 commit comments

Comments
 (0)