From 0623298d0d554979b6b151bafce9d0dff621c776 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toni=20Matkovi=C4=87?= Date: Tue, 5 Nov 2019 11:30:57 +0100 Subject: [PATCH] Basic implementation finished --- demo/index.tsx | 26 +++++++--------- .../ContentItems/SingleContentItem.tsx | 31 +++++++++++++++++++ src/components/Redoc/Redoc.tsx | 8 +++-- src/services/ScrollService.ts | 4 +-- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/demo/index.tsx b/demo/index.tsx index 68d072ba..c61a045f 100644 --- a/demo/index.tsx +++ b/demo/index.tsx @@ -1,18 +1,18 @@ import * as React from 'react'; -import { render } from 'react-dom'; +import {render} from 'react-dom'; import styled from 'styled-components'; -import { resolve as urlResolve } from 'url'; -import { RedocStandalone } from '../src'; +import {resolve as urlResolve} from 'url'; +import {RedocStandalone} from '../src'; import ComboBox from './ComboBox'; const demos = [ - { value: 'https://api.apis.guru/v2/specs/instagram.com/1.0.0/swagger.yaml', label: 'Instagram' }, + {value: 'https://api.apis.guru/v2/specs/instagram.com/1.0.0/swagger.yaml', label: 'Instagram'}, { value: 'https://api.apis.guru/v2/specs/googleapis.com/calendar/v3/swagger.yaml', label: 'Google Calendar', }, - { value: 'https://api.apis.guru/v2/specs/slack.com/1.0.6/swagger.yaml', label: 'Slack' }, - { value: 'https://api.apis.guru/v2/specs/zoom.us/2.0.0/swagger.yaml', label: 'Zoom.us' }, + {value: 'https://api.apis.guru/v2/specs/slack.com/1.0.6/swagger.yaml', label: 'Slack'}, + {value: 'https://api.apis.guru/v2/specs/zoom.us/2.0.0/swagger.yaml', label: 'Zoom.us'}, { value: 'https://api.apis.guru/v2/specs/graphhopper.com/1.0/swagger.yaml', label: 'GraphHopper', @@ -21,10 +21,8 @@ const demos = [ const DEFAULT_SPEC = 'openapi.yaml'; -class DemoApp extends React.Component< - {}, - { specUrl: string; dropdownOpen: boolean; cors: boolean } -> { +class DemoApp extends React.Component<{}, + { specUrl: string; dropdownOpen: boolean; cors: boolean }> { constructor(props) { super(props); @@ -71,7 +69,7 @@ class DemoApp extends React.Component< }; render() { - const { specUrl, cors } = this.state; + const {specUrl, cors} = this.state; let proxiedUrl = specUrl; if (specUrl !== DEFAULT_SPEC) { proxiedUrl = cors @@ -82,7 +80,7 @@ class DemoApp extends React.Component< <> - + - + @@ -104,7 +102,7 @@ class DemoApp extends React.Component< height="30px" /> - + ); } diff --git a/src/components/ContentItems/SingleContentItem.tsx b/src/components/ContentItems/SingleContentItem.tsx index e69de29b..52a8a78a 100644 --- a/src/components/ContentItems/SingleContentItem.tsx +++ b/src/components/ContentItems/SingleContentItem.tsx @@ -0,0 +1,31 @@ +import {observer} from 'mobx-react'; +import * as React from 'react'; +import {IMenuItem, MenuStore} from '../../services'; +import {ContentItems} from './ContentItems'; + +@observer +export class SingleContentItem extends React.Component<{ + menu: MenuStore; +}> { + + extractActive(menu: MenuStore): IMenuItem[] { + const active = menu.flatItems[menu.activeItemIdx]; + if (!active) { + return [menu.flatItems[0]]; + } + if (active.type !== 'operation') { + return [ + {...active, items: []}, + ]; + } + return [active]; + } + + render() { + const { menu } = this.props; + const activeItems = this.extractActive(menu); + return ( + + ); + } +} diff --git a/src/components/Redoc/Redoc.tsx b/src/components/Redoc/Redoc.tsx index 2b43e77d..e6e67dd0 100644 --- a/src/components/Redoc/Redoc.tsx +++ b/src/components/Redoc/Redoc.tsx @@ -4,7 +4,7 @@ import * as React from 'react'; import { ThemeProvider } from '../../styled-components'; import { OptionsProvider } from '../OptionsProvider'; -import { AppStore } from '../../services'; +import {AppStore} from '../../services'; import { ApiInfo } from '../ApiInfo/'; import { ApiLogo } from '../ApiLogo/ApiLogo'; import { ContentItems } from '../ContentItems/ContentItems'; @@ -12,6 +12,7 @@ import { SideMenu } from '../SideMenu/SideMenu'; import { StickyResponsiveSidebar } from '../StickySidebar/StickyResponsiveSidebar'; import { ApiContentWrap, BackgroundStub, RedocWrap } from './styled.elements'; +import {SingleContentItem} from '../ContentItems/SingleContentItem'; import { SearchBox } from '../SearchBox/SearchBox'; import { StoreProvider } from '../StoreBuilder'; @@ -57,7 +58,10 @@ export class Redoc extends React.Component { - + {options.disableInfiniteScroll + ? + : + } diff --git a/src/services/ScrollService.ts b/src/services/ScrollService.ts index 3e946c37..6bcf4dd5 100644 --- a/src/services/ScrollService.ts +++ b/src/services/ScrollService.ts @@ -18,13 +18,13 @@ export class ScrollService { bind() { this._prevOffsetY = this.scrollY(); - if (this._scrollParent) { + if (this._scrollParent && !this.options.disableInfiniteScroll) { this._scrollParent.addEventListener('scroll', this.handleScroll); } } dispose() { - if (this._scrollParent) { + if (this._scrollParent && !this.options.disableInfiniteScroll) { this._scrollParent.removeEventListener('scroll', this.handleScroll); } this._emiter.removeAllListeners(EVENT);