From 970911536c0c5ec4b0be36f8197418b49cb647e3 Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Fri, 22 Feb 2019 13:51:07 +0100 Subject: [PATCH] Share functionality for app-js api playground (#740) * First WIP * Move all action buttons to component * More WIP * removed query-string module, share example through location.hash * Copy over deep clone * Fixed onload behaviour * Working example 'read from url' <-> 'write to url' * Populate location.hash to state * comment * Add selected option to dropdown * Dropdown WIP debugging * Removed attempted workaround for MUI Dropdown component Bug, added Fixme * Added copy to clipboard functionality * Added feedback animation on copy & switched component back to PureComponent * Tslint fixes & yarn.lock dump * Added hash router types * More type fixes * Attempt to fix strictNullChecks for document.getSelection() * Fixed wrong conditional * prettier links * Tiny styling tweaks * Added routing to index * Removed empty devDependencies from package.json * Fix sharing * Try `history` without typing * Yarn.lock dump * Removed leftover LocalStorage component * Removed HashRouterProps * Code formatting changes * addressing tslint errors * Added match ro Props * Added history: any to Props declaration --- packages/app-js/src/ActionButtons.tsx | 156 ++++++++++ packages/app-js/src/LocalStorage.tsx | 111 ------- packages/app-js/src/Playground.tsx | 354 +++++++++++++++++++++++ packages/app-js/src/index.css | 4 + packages/app-js/src/index.tsx | 265 +---------------- packages/app-js/src/snippets/wrapping.ts | 3 +- packages/app-js/src/types.ts | 2 +- packages/ui-app/src/Dropdown.tsx | 2 +- yarn.lock | 182 ++++++------ 9 files changed, 619 insertions(+), 460 deletions(-) create mode 100644 packages/app-js/src/ActionButtons.tsx delete mode 100644 packages/app-js/src/LocalStorage.tsx create mode 100644 packages/app-js/src/Playground.tsx diff --git a/packages/app-js/src/ActionButtons.tsx b/packages/app-js/src/ActionButtons.tsx new file mode 100644 index 0000000000..26a089a223 --- /dev/null +++ b/packages/app-js/src/ActionButtons.tsx @@ -0,0 +1,156 @@ +// Copyright 2017-2019 @polkadot/app-js authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +import { BareProps, I18nProps } from '@polkadot/ui-app/types'; + +import React from 'react'; +import { Button as SUIB, Popup } from 'semantic-ui-react'; +import { Button, Input } from '@polkadot/ui-app/index'; + +import translate from './translate'; + +type Props = BareProps & I18nProps & { + isCustomExample: boolean, + isRunning: boolean, + saveSnippet: (snippetName: string) => void, + generateLink: () => void, + removeSnippet: () => void, + runJs: () => void, + snippetName?: string, + stopJs: () => void +}; + +type State = { + isOpen: boolean, + shareText: string, + snippetName: string +}; + +class ActionButtons extends React.PureComponent { + state: State = { + isOpen: false, + shareText: this.props.t('Generate link to share code example'), + snippetName: '' + }; + + render () { + const { + props: { isCustomExample, isRunning,removeSnippet, runJs, stopJs, t }, + state: { isOpen, snippetName } + } = this; + + return ( +
+ + } + wide={'very'} + /> + { + // FIXME: The event trigger on='hover' does not work together with the ui-app' + //
+ ); + } + + private generateLink = (): void => { + const { generateLink, t } = this.props; + this.setState({ shareText: t('Copied to clipboard') } as State); + generateLink(); + } + + private onShareClose = (): void => { + this.setState({ shareText: this.props.t('Generate link to share code example') } as State); + } + + private onChangeName = (snippetName: string): void => { + this.setState({ snippetName } as State); + } + + private saveSnippet = (): void => { + const { state: { snippetName }, props: { saveSnippet } } = this; + + saveSnippet(snippetName); + this.setState({ snippetName: '', isOpen: false } as State); + } + + private onPopupOpen = (): void => { + this.setState({ isOpen: true, snippetName: this.props.snippetName || '' } as State); + } + + private onPopupClose = (): void => { + this.setState({ snippetName: '', isOpen: false } as State); + } +} + +export default translate(ActionButtons); diff --git a/packages/app-js/src/LocalStorage.tsx b/packages/app-js/src/LocalStorage.tsx deleted file mode 100644 index 2b3323f411..0000000000 --- a/packages/app-js/src/LocalStorage.tsx +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2017-2019 @polkadot/app-js authors & contributors -// This software may be modified and distributed under the terms -// of the Apache-2.0 license. See the LICENSE file for details. - -import { BareProps, I18nProps } from '@polkadot/ui-app/types'; - -import React from 'react'; -import { Button as SUIB, Popup } from 'semantic-ui-react'; -import { Button, Input } from '@polkadot/ui-app/index'; - -import translate from './translate'; - -type Props = BareProps & I18nProps & { - isCustomExample: boolean, - saveSnippet: (snippetName: string) => void, - removeSnippet: () => void, - snippetName?: string -}; - -type State = { - snippetName: string, - isOpen: boolean -}; - -class LocalStorage extends React.PureComponent { - state: State = { - snippetName: '', - isOpen: false - }; - - render () { - const { - props: { isCustomExample, removeSnippet, t }, - state: { isOpen, snippetName } - } = this; - - if (isCustomExample) { - return ( - // FIXME: The event trigger on='hover' does not work together with the ui-app' - //