From 5908f189a7fc060f2fa53cc41cdc991eff78a362 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Thu, 1 Mar 2018 09:18:46 +0100 Subject: Fix bug where contract event anchor ids were incorrect --- packages/website/ts/pages/documentation/event_definition.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'packages/website/ts/pages') diff --git a/packages/website/ts/pages/documentation/event_definition.tsx b/packages/website/ts/pages/documentation/event_definition.tsx index 0e53e38e7..e62c9ecbd 100644 --- a/packages/website/ts/pages/documentation/event_definition.tsx +++ b/packages/website/ts/pages/documentation/event_definition.tsx @@ -25,9 +25,10 @@ export class EventDefinition extends React.Component
-- cgit v1.2.3 From 67c834841ea0f8fb4d8d194c0f68802f48e764ee Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 2 Mar 2018 14:40:26 +0100 Subject: Update react-markdown, properly scroll to section for wiki internal links, consolidate scrollTo logic and make external links open in new tabs --- .../website/ts/pages/documentation/comment.tsx | 2 +- .../ts/pages/documentation/documentation.tsx | 25 +++++-------- .../ts/pages/shared/markdown_code_block.tsx | 6 ++-- .../ts/pages/shared/markdown_link_block.tsx | 41 ++++++++++++++++++++++ .../website/ts/pages/shared/markdown_section.tsx | 10 +++++- .../website/ts/pages/shared/version_drop_down.tsx | 7 ++-- packages/website/ts/pages/wiki/wiki.tsx | 19 ++-------- 7 files changed, 68 insertions(+), 42 deletions(-) create mode 100644 packages/website/ts/pages/shared/markdown_link_block.tsx (limited to 'packages/website/ts/pages') diff --git a/packages/website/ts/pages/documentation/comment.tsx b/packages/website/ts/pages/documentation/comment.tsx index 23cfd96bd..5f177e97e 100644 --- a/packages/website/ts/pages/documentation/comment.tsx +++ b/packages/website/ts/pages/documentation/comment.tsx @@ -15,7 +15,7 @@ const defaultProps = { export const Comment: React.SFC = (props: CommentProps) => { return (
- +
); }; diff --git a/packages/website/ts/pages/documentation/documentation.tsx b/packages/website/ts/pages/documentation/documentation.tsx index 7eed78fc3..5963fe851 100644 --- a/packages/website/ts/pages/documentation/documentation.tsx +++ b/packages/website/ts/pages/documentation/documentation.tsx @@ -29,11 +29,11 @@ import { TypescriptMethod, } from 'ts/types'; import { colors } from 'ts/utils/colors'; +import { configs } from 'ts/utils/configs'; import { constants } from 'ts/utils/constants'; import { utils } from 'ts/utils/utils'; const TOP_BAR_HEIGHT = 60; -const SCROLL_TOP_ID = 'docsScrollTop'; const networkNameToColor: { [network: string]: string } = { [Networks.Kovan]: colors.purple, @@ -76,7 +76,7 @@ const styles: Styles = { export class Documentation extends React.Component { public componentDidUpdate(prevProps: DocumentationProps, prevState: DocumentationState) { if (!_.isEqual(prevProps.docAgnosticFormat, this.props.docAgnosticFormat)) { - this._scrollToHash(); + utils.scrollToHash(this.props.location.hash, configs.SCROLL_CONTAINER_ID); } } public render() { @@ -115,8 +115,12 @@ export class Documentation extends React.Component -
-
+
+
{this._renderDocumentation()}
@@ -325,17 +329,4 @@ export class Documentation extends React.Component ); } - private _scrollToHash(): void { - const hashWithPrefix = this.props.location.hash; - let hash = hashWithPrefix.slice(1); - if (_.isEmpty(hash)) { - hash = SCROLL_TOP_ID; // scroll to the top - } - - scroller.scrollTo(hash, { - duration: 0, - offset: 0, - containerId: 'documentation', - }); - } } diff --git a/packages/website/ts/pages/shared/markdown_code_block.tsx b/packages/website/ts/pages/shared/markdown_code_block.tsx index 98ca3aee6..6dfb74554 100644 --- a/packages/website/ts/pages/shared/markdown_code_block.tsx +++ b/packages/website/ts/pages/shared/markdown_code_block.tsx @@ -3,7 +3,7 @@ import * as React from 'react'; import * as HighLight from 'react-highlight'; interface MarkdownCodeBlockProps { - literal: string; + value: string; language: string; } @@ -13,12 +13,12 @@ export class MarkdownCodeBlock extends React.Component - {this.props.literal} + {this.props.value} ); } diff --git a/packages/website/ts/pages/shared/markdown_link_block.tsx b/packages/website/ts/pages/shared/markdown_link_block.tsx new file mode 100644 index 000000000..73c447636 --- /dev/null +++ b/packages/website/ts/pages/shared/markdown_link_block.tsx @@ -0,0 +1,41 @@ +import * as _ from 'lodash'; +import * as React from 'react'; +import { configs } from 'ts/utils/configs'; +import { utils } from 'ts/utils/utils'; + +interface MarkdownLinkBlockProps { + href: string; +} + +interface MarkdownLinkBlockState {} + +export class MarkdownLinkBlock extends React.Component { + // Re-rendering a linkBlock causes any use selection to become de-selected making the link unclickable. + // We therefore noop re-renders on this component if it's props haven't changed. + public shouldComponentUpdate(nextProps: MarkdownLinkBlockProps, nextState: MarkdownLinkBlockState) { + return nextProps.href !== this.props.href; + } + public render() { + const href = this.props.href; + // If protocol is http or https, we can open in a new tab, otherwise don't for security reasons + if (_.startsWith(href, 'http') || _.startsWith(href, 'https')) { + return ( + + {this.props.children} + + ); + } else if (_.startsWith(href, '#')) { + return ( + + {this.props.children} + + ); + } else { + return {this.props.children}; + } + } + private _onHashUrlClick(href: string) { + const hashWithPrefix = `#${href.split('#')[1]}`; + utils.scrollToHash(hashWithPrefix, configs.SCROLL_CONTAINER_ID); + } +} diff --git a/packages/website/ts/pages/shared/markdown_section.tsx b/packages/website/ts/pages/shared/markdown_section.tsx index 4d7d8b4ca..7253072d9 100644 --- a/packages/website/ts/pages/shared/markdown_section.tsx +++ b/packages/website/ts/pages/shared/markdown_section.tsx @@ -5,6 +5,7 @@ import * as ReactMarkdown from 'react-markdown'; import { Element as ScrollElement } from 'react-scroll'; import { AnchorTitle } from 'ts/pages/shared/anchor_title'; import { MarkdownCodeBlock } from 'ts/pages/shared/markdown_code_block'; +import { MarkdownLinkBlock } from 'ts/pages/shared/markdown_link_block'; import { HeaderSizes } from 'ts/types'; import { colors } from 'ts/utils/colors'; import { utils } from 'ts/utils/utils'; @@ -64,7 +65,14 @@ export class MarkdownSection extends React.Component

- +
); diff --git a/packages/website/ts/pages/shared/version_drop_down.tsx b/packages/website/ts/pages/shared/version_drop_down.tsx index 3b331af9b..1b4dbb375 100644 --- a/packages/website/ts/pages/shared/version_drop_down.tsx +++ b/packages/website/ts/pages/shared/version_drop_down.tsx @@ -2,6 +2,7 @@ import * as _ from 'lodash'; import DropDownMenu from 'material-ui/DropDownMenu'; import MenuItem from 'material-ui/MenuItem'; import * as React from 'react'; +import { utils } from 'ts/utils/utils'; interface VersionDropDownProps { selectedVersion: string; @@ -31,8 +32,6 @@ export class VersionDropDown extends React.Component { }} >
-
+
{this._renderWikiArticles()}
@@ -188,19 +188,6 @@ export class Wiki extends React.Component {
); } - private _scrollToHash(): void { - const hashWithPrefix = this.props.location.hash; - let hash = hashWithPrefix.slice(1); - if (_.isEmpty(hash)) { - hash = '0xProtocolWiki'; // scroll to the top - } - - scroller.scrollTo(hash, { - duration: 0, - offset: 0, - containerId: 'documentation', - }); - } private async _fetchArticlesBySectionAsync(): Promise { const endpoint = `${configs.BACKEND_BASE_URL}${WebsitePaths.Wiki}`; const response = await fetch(endpoint); @@ -225,7 +212,7 @@ export class Wiki extends React.Component { articlesBySection, }, () => { - this._scrollToHash(); + utils.scrollToHash(this.props.location.hash, configs.SCROLL_CONTAINER_ID); }, ); } -- cgit v1.2.3 From 5906f4c9953b65421a16b947a5e03898281483bc Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 2 Mar 2018 15:02:50 +0100 Subject: Add underline to internal linksx --- packages/website/ts/pages/shared/markdown_link_block.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'packages/website/ts/pages') diff --git a/packages/website/ts/pages/shared/markdown_link_block.tsx b/packages/website/ts/pages/shared/markdown_link_block.tsx index 73c447636..a8246f654 100644 --- a/packages/website/ts/pages/shared/markdown_link_block.tsx +++ b/packages/website/ts/pages/shared/markdown_link_block.tsx @@ -26,7 +26,10 @@ export class MarkdownLinkBlock extends React.Component + {this.props.children} ); -- cgit v1.2.3 From a2b262c9df127102a4508273d2a3564c5c004788 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Fri, 2 Mar 2018 15:10:44 +0100 Subject: Add hash to URL onClick --- packages/website/ts/pages/shared/markdown_link_block.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'packages/website/ts/pages') diff --git a/packages/website/ts/pages/shared/markdown_link_block.tsx b/packages/website/ts/pages/shared/markdown_link_block.tsx index a8246f654..45bb41478 100644 --- a/packages/website/ts/pages/shared/markdown_link_block.tsx +++ b/packages/website/ts/pages/shared/markdown_link_block.tsx @@ -38,7 +38,9 @@ export class MarkdownLinkBlock extends React.Component Date: Fri, 2 Mar 2018 17:02:14 +0100 Subject: Make sure the page has loaded (including all images) before scrolling to hash --- packages/website/ts/pages/wiki/wiki.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'packages/website/ts/pages') diff --git a/packages/website/ts/pages/wiki/wiki.tsx b/packages/website/ts/pages/wiki/wiki.tsx index d0cbf0d3e..66fa960d7 100644 --- a/packages/website/ts/pages/wiki/wiki.tsx +++ b/packages/website/ts/pages/wiki/wiki.tsx @@ -211,7 +211,8 @@ export class Wiki extends React.Component { { articlesBySection, }, - () => { + async () => { + await utils.onPageLoadAsync(); utils.scrollToHash(this.props.location.hash, configs.SCROLL_CONTAINER_ID); }, ); -- cgit v1.2.3 From 0afe45b3a830bfefc4f9b51823891b99be5261fa Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sat, 3 Mar 2018 05:36:08 +0100 Subject: Hash hash instead of prefixedHash to scrollToHash function --- packages/website/ts/pages/documentation/documentation.tsx | 3 ++- packages/website/ts/pages/shared/markdown_link_block.tsx | 3 +-- packages/website/ts/pages/wiki/wiki.tsx | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'packages/website/ts/pages') diff --git a/packages/website/ts/pages/documentation/documentation.tsx b/packages/website/ts/pages/documentation/documentation.tsx index 5963fe851..699bef7a8 100644 --- a/packages/website/ts/pages/documentation/documentation.tsx +++ b/packages/website/ts/pages/documentation/documentation.tsx @@ -76,7 +76,8 @@ const styles: Styles = { export class Documentation extends React.Component { public componentDidUpdate(prevProps: DocumentationProps, prevState: DocumentationState) { if (!_.isEqual(prevProps.docAgnosticFormat, this.props.docAgnosticFormat)) { - utils.scrollToHash(this.props.location.hash, configs.SCROLL_CONTAINER_ID); + const hash = this.props.location.hash.slice(1); + utils.scrollToHash(hash, configs.SCROLL_CONTAINER_ID); } } public render() { diff --git a/packages/website/ts/pages/shared/markdown_link_block.tsx b/packages/website/ts/pages/shared/markdown_link_block.tsx index 45bb41478..ed78e4e53 100644 --- a/packages/website/ts/pages/shared/markdown_link_block.tsx +++ b/packages/website/ts/pages/shared/markdown_link_block.tsx @@ -39,8 +39,7 @@ export class MarkdownLinkBlock extends React.Component { }, async () => { await utils.onPageLoadAsync(); - utils.scrollToHash(this.props.location.hash, configs.SCROLL_CONTAINER_ID); + const hash = this.props.location.hash.slice(1); + utils.scrollToHash(hash, configs.SCROLL_CONTAINER_ID); }, ); } -- cgit v1.2.3 From fdaf9f0bfc24a93933fb492d727d970d8c82d8ee Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sat, 3 Mar 2018 05:36:26 +0100 Subject: Fix comment and use named variable in conditional --- packages/website/ts/pages/shared/markdown_link_block.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'packages/website/ts/pages') diff --git a/packages/website/ts/pages/shared/markdown_link_block.tsx b/packages/website/ts/pages/shared/markdown_link_block.tsx index ed78e4e53..e4553c87f 100644 --- a/packages/website/ts/pages/shared/markdown_link_block.tsx +++ b/packages/website/ts/pages/shared/markdown_link_block.tsx @@ -10,13 +10,14 @@ interface MarkdownLinkBlockProps { interface MarkdownLinkBlockState {} export class MarkdownLinkBlock extends React.Component { - // Re-rendering a linkBlock causes any use selection to become de-selected making the link unclickable. + // Re-rendering a linkBlock causes it to remain unclickable. // We therefore noop re-renders on this component if it's props haven't changed. public shouldComponentUpdate(nextProps: MarkdownLinkBlockProps, nextState: MarkdownLinkBlockState) { return nextProps.href !== this.props.href; } public render() { const href = this.props.href; + const isLinkToSection = _.startsWith(href, '#'); // If protocol is http or https, we can open in a new tab, otherwise don't for security reasons if (_.startsWith(href, 'http') || _.startsWith(href, 'https')) { return ( @@ -24,7 +25,7 @@ export class MarkdownLinkBlock extends React.Component ); - } else if (_.startsWith(href, '#')) { + } else if (isLinkToSection) { return ( Date: Sat, 3 Mar 2018 05:46:12 +0100 Subject: Small stylistic improvements --- packages/website/ts/pages/shared/nested_sidebar_menu.tsx | 6 +++--- packages/website/ts/pages/shared/section_header.tsx | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'packages/website/ts/pages') diff --git a/packages/website/ts/pages/shared/nested_sidebar_menu.tsx b/packages/website/ts/pages/shared/nested_sidebar_menu.tsx index 1a08ca9f9..82a40eb7e 100644 --- a/packages/website/ts/pages/shared/nested_sidebar_menu.tsx +++ b/packages/website/ts/pages/shared/nested_sidebar_menu.tsx @@ -86,14 +86,14 @@ export class NestedSidebarMenu extends React.Component
-
+
|
- +
-
+
{this.props.title}
diff --git a/packages/website/ts/pages/shared/section_header.tsx b/packages/website/ts/pages/shared/section_header.tsx index a5f5f52cf..52a1f30d9 100644 --- a/packages/website/ts/pages/shared/section_header.tsx +++ b/packages/website/ts/pages/shared/section_header.tsx @@ -2,6 +2,7 @@ import * as React from 'react'; import { Element as ScrollElement } from 'react-scroll'; import { AnchorTitle } from 'ts/pages/shared/anchor_title'; import { HeaderSizes } from 'ts/types'; +import { colors } from 'ts/utils/colors'; import { utils } from 'ts/utils/utils'; interface SectionHeaderProps { @@ -34,7 +35,19 @@ export class SectionHeader extends React.Component {sectionName}} + title={ + + {sectionName} + + } id={id} shouldShowAnchor={this.state.shouldShowAnchor} /> -- cgit v1.2.3