Refactor titleToIcon mapping to idToIcon and move to docPage

This commit is contained in:
Fabio Berger 2018-03-20 12:26:04 +00:00
parent a3c31f4f4a
commit 72671c1014
4 changed files with 23 additions and 18 deletions

View File

@ -4,20 +4,9 @@ import * as React from 'react';
const SHOW_DURATION_MS = 4000; const SHOW_DURATION_MS = 4000;
const titleToIcon: { [title: string]: string } = {
'0x.js': 'zeroExJs.png',
Web3Wrapper: 'zeroExJs.png',
Deployer: 'zeroExJs.png',
'Sol-cov': 'zeroExJs.png',
'JSON Schemas': 'zeroExJs.png',
Subproviders: 'zeroExJs.png',
'0x Connect': 'connect.png',
'0x Smart Contracts': 'contracts.png',
Wiki: 'wiki.png',
};
interface SidebarHeaderProps { interface SidebarHeaderProps {
title: string; title: string;
iconUrl: string;
} }
interface SidebarHeaderState {} interface SidebarHeaderState {}
@ -37,7 +26,7 @@ export class SidebarHeader extends React.Component<SidebarHeaderProps, SidebarHe
</div> </div>
<div className="flex"> <div className="flex">
<div> <div>
<img src={`/images/doc_icons/${titleToIcon[this.props.title]}`} width="22" /> <img src={`/images/doc_icons/${this.props.iconUrl}`} width="22" />
</div> </div>
<div className="pl1" style={{ fontWeight: 600, fontSize: 20, lineHeight: 1.2 }}> <div className="pl1" style={{ fontWeight: 600, fontSize: 20, lineHeight: 1.2 }}>
{this.props.title} {this.props.title}

View File

@ -39,6 +39,7 @@ interface TopBarProps {
style?: React.CSSProperties; style?: React.CSSProperties;
isNightVersion?: boolean; isNightVersion?: boolean;
onVersionSelected?: (semver: string) => void; onVersionSelected?: (semver: string) => void;
sidebarHeader?: React.ReactNode;
} }
interface TopBarState { interface TopBarState {
@ -393,7 +394,7 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
<NestedSidebarMenu <NestedSidebarMenu
topLevelMenu={this.props.menu} topLevelMenu={this.props.menu}
menuSubsectionsBySection={this.props.menuSubsectionsBySection} menuSubsectionsBySection={this.props.menuSubsectionsBySection}
sidebarHeader={<SidebarHeader title={this.props.docsInfo.displayName} />} sidebarHeader={this.props.sidebarHeader}
shouldDisplaySectionHeaders={false} shouldDisplaySectionHeaders={false}
onMenuItemClick={this._onMenuButtonClick.bind(this)} onMenuItemClick={this._onMenuButtonClick.bind(this)}
selectedVersion={this.props.docsVersion} selectedVersion={this.props.docsVersion}
@ -413,7 +414,7 @@ export class TopBar extends React.Component<TopBarProps, TopBarState> {
<NestedSidebarMenu <NestedSidebarMenu
topLevelMenu={this.props.menuSubsectionsBySection} topLevelMenu={this.props.menuSubsectionsBySection}
menuSubsectionsBySection={this.props.menuSubsectionsBySection} menuSubsectionsBySection={this.props.menuSubsectionsBySection}
sidebarHeader={<SidebarHeader title="Wiki" />} sidebarHeader={this.props.sidebarHeader}
shouldDisplaySectionHeaders={false} shouldDisplaySectionHeaders={false}
onMenuItemClick={this._onMenuButtonClick.bind(this)} onMenuItemClick={this._onMenuButtonClick.bind(this)}
/> />

View File

@ -15,9 +15,20 @@ import { docUtils } from 'ts/utils/doc_utils';
import { Translate } from 'ts/utils/translate'; import { Translate } from 'ts/utils/translate';
import { utils } from 'ts/utils/utils'; import { utils } from 'ts/utils/utils';
const isDevelopment = configs.ENVIRONMENT === Environments.DEVELOPMENT;
const ZERO_EX_JS_VERSION_MISSING_TOPLEVEL_PATH = '0.32.4'; const ZERO_EX_JS_VERSION_MISSING_TOPLEVEL_PATH = '0.32.4';
const isDevelopment = configs.ENVIRONMENT === Environments.DEVELOPMENT; const idToIcon: { [id: string]: string } = {
[DocPackages.ZeroExJs]: 'zeroExJs.png',
[DocPackages.Web3Wrapper]: 'zeroExJs.png',
[DocPackages.Deployer]: 'zeroExJs.png',
[DocPackages.SolCov]: 'zeroExJs.png',
[DocPackages.JSONSchemas]: 'zeroExJs.png',
[DocPackages.Subproviders]: 'zeroExJs.png',
[DocPackages.Connect]: 'connect.png',
[DocPackages.SmartContracts]: 'contracts.png',
};
const docIdToS3FolderName: { [id: string]: string } = { const docIdToS3FolderName: { [id: string]: string } = {
[DocPackages.ZeroExJs]: '0xjs', [DocPackages.ZeroExJs]: '0xjs',
[DocPackages.SmartContracts]: 'smart-contracts', [DocPackages.SmartContracts]: 'smart-contracts',
@ -79,6 +90,7 @@ export class DocPage extends React.Component<DocPageProps, DocPageState> {
? {} ? {}
: this.props.docsInfo.getMenuSubsectionsBySection(this.state.docAgnosticFormat); : this.props.docsInfo.getMenuSubsectionsBySection(this.state.docAgnosticFormat);
const sourceUrl = this._getSourceUrl(); const sourceUrl = this._getSourceUrl();
const iconUrl = idToIcon[this.props.docsInfo.id];
return ( return (
<div> <div>
<DocumentTitle title={`${this.props.docsInfo.displayName} Documentation`} /> <DocumentTitle title={`${this.props.docsInfo.displayName} Documentation`} />
@ -92,13 +104,14 @@ export class DocPage extends React.Component<DocPageProps, DocPageState> {
docsInfo={this.props.docsInfo} docsInfo={this.props.docsInfo}
translate={this.props.translate} translate={this.props.translate}
onVersionSelected={this._onVersionSelected.bind(this)} onVersionSelected={this._onVersionSelected.bind(this)}
sidebarHeader={<SidebarHeader title={this.props.docsInfo.displayName} iconUrl={iconUrl} />}
/> />
<Documentation <Documentation
selectedVersion={this.props.docsVersion} selectedVersion={this.props.docsVersion}
availableVersions={this.props.availableDocVersions} availableVersions={this.props.availableDocVersions}
docsInfo={this.props.docsInfo} docsInfo={this.props.docsInfo}
docAgnosticFormat={this.state.docAgnosticFormat} docAgnosticFormat={this.state.docAgnosticFormat}
sidebarHeader={<SidebarHeader title={this.props.docsInfo.displayName} />} sidebarHeader={<SidebarHeader title={this.props.docsInfo.displayName} iconUrl={iconUrl} />}
sourceUrl={sourceUrl} sourceUrl={sourceUrl}
topBarHeight={60} topBarHeight={60}
onVersionSelected={this._onVersionSelected.bind(this)} onVersionSelected={this._onVersionSelected.bind(this)}

View File

@ -88,6 +88,7 @@ export class Wiki extends React.Component<WikiProps, WikiState> {
...styles.mainContainers, ...styles.mainContainers,
overflow: this.state.isHoveringSidebar ? 'auto' : 'hidden', overflow: this.state.isHoveringSidebar ? 'auto' : 'hidden',
}; };
const sidebarHeader = <SidebarHeader title="Wiki" iconUrl="wiki.png" />;
return ( return (
<div> <div>
<DocumentTitle title="0x Protocol Wiki" /> <DocumentTitle title="0x Protocol Wiki" />
@ -96,6 +97,7 @@ export class Wiki extends React.Component<WikiProps, WikiState> {
location={this.props.location} location={this.props.location}
menuSubsectionsBySection={menuSubsectionsBySection} menuSubsectionsBySection={menuSubsectionsBySection}
translate={this.props.translate} translate={this.props.translate}
sidebarHeader={sidebarHeader}
/> />
{_.isUndefined(this.state.articlesBySection) ? ( {_.isUndefined(this.state.articlesBySection) ? (
<div className="col col-12" style={mainContainersStyle}> <div className="col col-12" style={mainContainersStyle}>
@ -134,7 +136,7 @@ export class Wiki extends React.Component<WikiProps, WikiState> {
<NestedSidebarMenu <NestedSidebarMenu
topLevelMenu={menuSubsectionsBySection} topLevelMenu={menuSubsectionsBySection}
menuSubsectionsBySection={menuSubsectionsBySection} menuSubsectionsBySection={menuSubsectionsBySection}
sidebarHeader={<SidebarHeader title="Wiki" />} sidebarHeader={sidebarHeader}
/> />
</div> </div>
</div> </div>