@@ -5,12 +5,6 @@ import { useStaticQuery, graphql, Link } from 'gatsby';
55import React from 'react' ;
66import './LeftNav.scss' ;
77import book from './images/book.png' ;
8- import web from './images/box.svg' ;
9- import android from './images/android.svg' ;
10- import ios from './images/ios.svg' ;
11- import mobile from './images/mobile_line.svg' ;
12-
13- // import { caret } from './caret.svg';
148
159
1610const { v4 : uuidv4 } = require ( 'uuid' ) ;
@@ -46,7 +40,7 @@ class ListItem extends React.Component {
4640 let title ;
4741 if ( e . target . attributes . identifier ) {
4842 title = e . target . attributes . identifier . value ;
49- } else {
43+ } else if ( e . target . nextSibling . attributes . identifier ) {
5044 title = e . target . nextSibling . attributes . identifier . value ;
5145 }
5246 const { active } = this . state ;
@@ -68,22 +62,15 @@ class ListItem extends React.Component {
6862 const { currentUrl } = this . state ;
6963 return currentUrl . includes ( url ) ;
7064 }
71- // bool to return whether current list item appears in the url
72- handleLoginClick ( ) {
73- this . setState ( { isLoggedIn : true } ) ;
74- }
7565
76- handleLogoutClick ( ) {
77- this . setState ( { isLoggedIn : false } ) ;
78- }
79- child = ( url ) => {
66+ child = ( data , url ) => {
8067 const name = slugs . filter ( ( val ) => url === val . fields . slug ) ;
8168 const { title } = name [ 0 ] . frontmatter ;
82- return (
83- < li key = { `${ title } -${ uuidv4 ( ) } ` } className = { `child${ this . inUrl ( url ) ? ' currentUrl text_green' : '' } ` } >
69+ return ( url . indexOf ( "/overview/" ) === - 1 &&
70+ < li key = { `${ data . leftNavTitle || title } -${ uuidv4 ( ) } ` } className = { `child${ this . inUrl ( url ) ? ' currentUrl text_green' : '' } ` } >
8471 < div className = "activeIndicator" />
8572 < img src = { book } alt = "book" />
86- < Link to = { url } > { title } </ Link >
73+ < Link to = { url } > { data . leftNavTitle || title } </ Link >
8774 </ li >
8875 ) ;
8976 } // Renders child element. Gets name from slugs array
@@ -93,35 +80,41 @@ class ListItem extends React.Component {
9380 if ( this . inUrl ( `/${ name } /` ) ) {
9481 this . setActive ( name ) ;
9582 }
83+ // Appending overview page link to Parent node (which has arrow icon with title)
84+ // Instead of having overview as a separate link.
85+ let overviewLink = null ;
86+ Object . keys ( data ) . map ( key => {
87+ if ( data . hasOwnProperty ( 'overview' ) ) {
88+ if ( data [ 'overview' ] . url . indexOf ( `/${ name } /overview/` ) !== - 1 )
89+ overviewLink = data [ 'overview' ] . url ;
90+ }
91+ else if ( data [ key ] . hasOwnProperty ( 'overview' ) ) {
92+ if ( data [ key ] [ 'overview' ] . url . indexOf ( `/${ name } /overview/` ) !== - 1 )
93+ overviewLink = data [ key ] [ 'overview' ] . url ;
94+ }
95+ } )
9696
9797 return (
9898 < ul
9999 key = { `${ name } -${ uuidv4 ( ) } ` }
100- className = { `
101- ${ ( active . indexOf ( name ) !== - 1 ) ? 'active' : 'inactive' }
102- ${ isRoot ? ' root' : '' }
103- ` }
100+ className = { ` ${ ( active . indexOf ( name ) !== - 1 ) ? 'active' : 'inactive' } ${ isRoot ? ' root' : '' } ` }
104101 >
105102 < li className = { `parent${ this . inUrl ( `/${ name } /` ) ? ' currentUrl text_green' : '' } ` } onClick = { this . toggleActive } identifier = { name } >
106- < button type = "button" onClick = { this . toggleActive } identifier = { name } >
107- { name . replace ( / - / g, ' ' ) }
108- </ button >
109- { /*<svg className='inline float-right top-2 relative folder-icon' width="13" height="8" viewBox="0 0 13 8" fill="none" xmlns="http://www.w3.org/2000/svg">*/ }
110- { /* <path d="M12.5253 1.5H1.09298C0.882619 1.5 0.711915 1.16397 0.711915 0.75C0.711915 0.335973 0.88265 0 1.09298 0H12.5253C12.7356 0 12.9063 0.336035 12.9063 0.75C12.9063 1.16397 12.7356 1.5 12.5253 1.5Z" fill="#183E46"/>*/ }
111- { /* <path d="M12.5253 4.5H1.09298C0.882619 4.5 0.711915 4.16397 0.711915 3.75C0.711915 3.33597 0.88265 3 1.09298 3H12.5253C12.7356 3 12.9063 3.33604 12.9063 3.75C12.9063 4.16397 12.7356 4.5 12.5253 4.5Z" fill="#183E46"/>*/ }
112- { /* <path d="M1.09301 6H8.71452C8.92488 6 9.09558 6.33603 9.09558 6.75C9.09558 7.16403 8.92485 7.5 8.71452 7.5H1.09301C0.882645 7.5 0.711941 7.16397 0.711941 6.75C0.711909 6.33597 0.882645 6 1.09301 6Z" fill="#183E46"/>*/ }
113- { /*</svg>*/ }
114103 < svg onClick = { this . toggleActive } identifier = { name } className = { `inline float_left relative folder-icon parent_caret${ this . isActive ( name ) ? ' active_parent_caret' : '' } ` } xmlns = "http://www.w3.org/2000/svg" fill = "none" height = "24"
115104 viewBox = "0 0 24 24" width = "24" >
116- < path clip-rule = "evenodd"
105+ < path clipRule = "evenodd"
117106 d = "m16.5303 8.96967c.2929.29289.2929.76777 0 1.06063l-4 4c-.2929.2929-.7677.2929-1.0606 0l-4.00003-4c-.29289-.29286-.29289-.76774 0-1.06063s.76777-.29289 1.06066 0l3.46967 3.46963 3.4697-3.46963c.2929-.29289.7677-.29289 1.0606 0z"
118- fill = "#333333" fill-rule = "evenodd" >
107+ fill = "#333333" fillRule = "evenodd" >
119108
120109 </ path >
121110 </ svg >
122111 < svg onClick = { this . toggleActive } identifier = { name } className = { `-mr-3 inline caret${ this . isActive ( name ) ? ' active-caret' : '' } ` } xmlns = "http://www.w3.org/2000/svg" fill = "none" height = "24" viewBox = "0 0 24 24" width = "24" > < path clipRule = "evenodd" d = "m16.5303 8.96967c.2929.29289.2929.76777 0 1.06063l-4 4c-.2929.2929-.7677.2929-1.0606 0l-4.00003-4c-.29289-.29286-.29289-.76774 0-1.06063s.76777-.29289 1.06066 0l3.46967 3.46963 3.4697-3.46963c.2929-.29289.7677-.29289 1.0606 0z" fill = "#333333" fillRule = "evenodd" /> </ svg >
112+ { overviewLink && ( < Link to = { overviewLink } onClick = { this . toggleActive } identifier = { name } > { data . leftNavTitle || name . replace ( / - / g, ' ' ) } </ Link > ) }
113+ { ! overviewLink && ( < button type = "button" onClick = { this . toggleActive } identifier = { name } >
114+ { data . leftNavTitle || name . replace ( / - / g, ' ' ) }
115+ </ button > ) }
123116 </ li >
124- < ListItem data = { JSON . stringify ( data ) } />
117+ < ListItem data = { JSON . stringify ( data ) } identifier = { name } />
125118 </ ul >
126119 ) ;
127120 } // renders parent element that has children
@@ -130,15 +123,15 @@ class ListItem extends React.Component {
130123 const { data } = this . state ;
131124 const parsedData = JSON . parse ( data ) ;
132125 const keys = Object . keys ( JSON . parse ( data ) ) . map ( ( val ) => val ) ;
133-
134126 return (
135127 < >
136-
137128 { keys . map ( ( val ) => {
138- if ( parsedData [ val ] . url ) {
139- return this . child ( parsedData [ val ] . url ) ;
129+ if ( val !== 'leftNavTitle' && val !== "old" ) {
130+ if ( parsedData [ val ] . url ) {
131+ return this . child ( parsedData [ val ] , parsedData [ val ] . url ) ;
132+ }
133+ return this . parent ( parsedData [ val ] , val ) ;
140134 }
141- return this . parent ( parsedData [ val ] , val ) ;
142135 } ) }
143136 </ >
144137 ) ;
@@ -164,13 +157,12 @@ const LeftNav = () => {
164157 }
165158 }` ) ;
166159 slugs = data . allMarkdownRemark . nodes ;
167-
168160 return (
169161 < >
170- < div className = "leftNav bg-gray-50 px-14 pt-5" >
171- < ListItem data = { data . leftNavLinks . value } isRoot />
172- </ div >
173- </ >
162+ < div className = "leftNav bg-gray-50 px-14 pt-5" >
163+ < ListItem data = { data . leftNavLinks . value } isRoot />
164+ </ div >
165+ </ >
174166 ) ;
175167} ;
176168
0 commit comments