|
21 | 21 | import React, { useEffect, useState } from 'react' |
22 | 22 | import { Drawer, DrawerBody, DrawerHeader } from 'browser-components/drawer' |
23 | 23 | import styled from 'styled-components' |
24 | | -import { GuideChapter, isGuideChapter } from 'browser/documentation' |
25 | | -import docs from '../../documentation' |
26 | | -import Docs from '../Docs/Docs' |
| 24 | +import Directives from 'browser-components/Directives' |
| 25 | +import { CarouselButton } from 'browser-components/buttons' |
| 26 | +import { |
| 27 | + SlidePreviousIcon, |
| 28 | + SlideNextIcon |
| 29 | +} from 'browser-components/icons/Icons' |
| 30 | +import { useRef } from 'react' |
| 31 | +import { connect } from 'react-redux' |
| 32 | +import { getGuide } from 'shared/modules/guides/guidesDuck' |
| 33 | +import { GlobalState } from 'shared/globalState' |
| 34 | +import { Guide } from '../../../shared/modules/guides/guidesDuck' |
27 | 35 |
|
28 | 36 | const StyledCarousel = styled.div` |
29 | 37 | padding-bottom: 20px; |
@@ -162,65 +170,34 @@ const StyledUl = styled.ul` |
162 | 170 | const WideDrawer = styled(Drawer)` |
163 | 171 | width: 500px; |
164 | 172 | position: relative; |
165 | | - background-color: ${props => props.theme.primaryBackground}; |
| 173 | + background-color: ${props => props.theme.secondaryBackground}; |
166 | 174 | ` |
167 | 175 |
|
168 | | -const sidebarGuides: GuideChapter[] = [ |
169 | | - 'allGuides', |
170 | | - 'intro', |
171 | | - 'concepts', |
172 | | - 'cypher', |
173 | | - 'movies', |
174 | | - 'northwind' |
175 | | -] |
176 | | - |
177 | 176 | const GuideContent = styled.div` |
178 | 177 | padding-bottom: 40px; |
179 | 178 | ` |
| 179 | +const defaultGuide: Guide = { guideName: 'intro', initialSlide: 0, slides: [] } |
180 | 180 |
|
181 | | -function GuideDrawer(): JSX.Element { |
182 | | - const [selectedGuide, setSelectedGuide] = useState<GuideChapter>('allGuides') |
183 | | - function onSelectChange(e: React.FormEvent<HTMLSelectElement>) { |
184 | | - e.preventDefault() |
185 | | - if (!isGuideChapter(e.currentTarget.value)) { |
186 | | - throw Error('invalid select target') |
187 | | - } |
188 | | - setSelectedGuide(e.currentTarget.value) |
189 | | - } |
190 | | - |
| 181 | +type GuideDrawerProps = { guide: Guide | null } |
| 182 | +// default är switchern |
| 183 | +function GuideDrawer({ guide }: GuideDrawerProps): JSX.Element { |
| 184 | + const guideOrDefault = guide ?? defaultGuide |
191 | 185 | return ( |
192 | 186 | <WideDrawer id="guide-drawer"> |
193 | 187 | <DrawerHeader>Neo4j Browser Guides</DrawerHeader> |
194 | 188 | <DrawerBody> |
195 | | - <select |
196 | | - style={{ color: 'black' }} |
197 | | - value={selectedGuide} |
198 | | - onChange={onSelectChange} |
199 | | - > |
200 | | - {sidebarGuides.map(guideName => ( |
201 | | - <option key={guideName} value={guideName}> |
202 | | - {guideName} |
203 | | - </option> |
204 | | - ))} |
205 | | - </select> |
206 | 189 | <GuideContent> |
207 | | - <Carousel slides={docs.play.chapters[selectedGuide].slides} /> |
| 190 | + <Carousel slides={guideOrDefault.slides} /> |
208 | 191 | </GuideContent> |
209 | 192 | </DrawerBody> |
210 | 193 | </WideDrawer> |
211 | 194 | ) |
212 | 195 | } |
213 | | -export default GuideDrawer |
214 | | - |
215 | | -import Directives from 'browser-components/Directives' |
216 | | -import { CarouselButton } from 'browser-components/buttons' |
217 | | -import { |
218 | | - SlidePreviousIcon, |
219 | | - SlideNextIcon |
220 | | -} from 'browser-components/icons/Icons' |
221 | | -import { useRef } from 'react' |
| 196 | +const mapStateToProps = (state: GlobalState) => ({ guide: getGuide(state) }) |
| 197 | +export default connect(mapStateToProps)(GuideDrawer) |
222 | 198 |
|
223 | 199 | type CarouselProps = { slides?: JSX.Element[]; initialSlide?: number } |
| 200 | +// TODO handle there only being one slide |
224 | 201 | function Carousel({ |
225 | 202 | slides = [], |
226 | 203 | initialSlide = 0 |
|
0 commit comments