1
1
import React from 'react'
2
2
import PropTypes from 'prop-types'
3
- import { graphql } from 'react-apollo'
3
+ import { graphql , withApollo , compose } from 'react-apollo'
4
4
import gql from 'graphql-tag'
5
5
import Skeleton from 'react-loading-skeleton'
6
6
import { NavLink } from 'react-router-dom'
7
7
import classNames from 'classnames'
8
+ import { ApolloClient } from 'apollo-client'
8
9
9
10
import { slugify , withHyphens } from '../lib/helpers'
11
+ import { SECTION_BY_ID_QUERY } from './Section'
10
12
11
13
const LoadingSkeleton = ( ) => (
12
14
< div >
@@ -17,7 +19,7 @@ const LoadingSkeleton = () => (
17
19
</ div >
18
20
)
19
21
20
- const TableOfContents = ( { chapters, loading } ) => (
22
+ const TableOfContents = ( { chapters, loading, client } ) => (
21
23
< nav className = "TableOfContents" >
22
24
{ loading ? (
23
25
< LoadingSkeleton />
@@ -41,6 +43,14 @@ const TableOfContents = ({ chapters, loading }) => (
41
43
const rootPath = location . pathname . split ( '/' ) [ 1 ]
42
44
return rootPath . includes ( withHyphens ( chapter . title ) )
43
45
} }
46
+ onMouseOver = { ( ) => {
47
+ client . query ( {
48
+ query : SECTION_BY_ID_QUERY ,
49
+ variables : {
50
+ id : chapter . sections [ 0 ] . id
51
+ }
52
+ } )
53
+ } }
44
54
>
45
55
{ chapterIsNumbered && (
46
56
< span className = "TableOfContents-chapter-number" >
@@ -60,6 +70,14 @@ const TableOfContents = ({ chapters, loading }) => (
60
70
} }
61
71
className = "TableOfContents-section-link"
62
72
activeClassName = "active"
73
+ onMouseOver = { ( ) => {
74
+ client . query ( {
75
+ query : SECTION_BY_ID_QUERY ,
76
+ variables : {
77
+ id : section . id
78
+ }
79
+ } )
80
+ } }
63
81
>
64
82
{ section . title }
65
83
</ NavLink >
@@ -95,7 +113,8 @@ TableOfContents.propTypes = {
95
113
) . isRequired
96
114
} ) . isRequired
97
115
) ,
98
- loading : PropTypes . bool . isRequired
116
+ loading : PropTypes . bool . isRequired ,
117
+ client : PropTypes . instanceOf ( ApolloClient ) . isRequired
99
118
}
100
119
101
120
const CHAPTER_QUERY = gql `
@@ -120,4 +139,7 @@ const withData = graphql(CHAPTER_QUERY, {
120
139
} )
121
140
} )
122
141
123
- export default withData ( TableOfContents )
142
+ export default compose (
143
+ withData ,
144
+ withApollo
145
+ ) ( TableOfContents )
0 commit comments