From 20c1d37b596a6be39384d59f579908f10bb7b161 Mon Sep 17 00:00:00 2001 From: Jannis Redmann Date: Thu, 5 Jan 2017 21:15:01 +0100 Subject: [PATCH] let users open urls from dapps view (#4042) * browser: better url handling * browser: pass url as param * dapps: button to open browser * dapps url button: remove url validation * PR grumbles, better URL parsing * code style :sparkles: * better URL parsing, react to changed URL fragment --- js/src/routes.js | 1 + js/src/ui/Icons/index.js | 2 + js/src/views/Dapps/UrlButton/index.js | 17 ++++ js/src/views/Dapps/UrlButton/urlButton.css | 20 +++++ js/src/views/Dapps/UrlButton/urlButton.js | 96 ++++++++++++++++++++++ js/src/views/Dapps/dapps.js | 2 + js/src/views/Web/web.js | 83 +++++++++++++------ 7 files changed, 197 insertions(+), 24 deletions(-) create mode 100644 js/src/views/Dapps/UrlButton/index.js create mode 100644 js/src/views/Dapps/UrlButton/urlButton.css create mode 100644 js/src/views/Dapps/UrlButton/urlButton.js diff --git a/js/src/routes.js b/js/src/routes.js index 6aa1304c5..20fb3dba6 100644 --- a/js/src/routes.js +++ b/js/src/routes.js @@ -113,6 +113,7 @@ const routes = [ { path: 'apps', component: Dapps }, { path: 'app/:id', component: Dapp }, { path: 'web', component: Web }, + { path: 'web/:url', component: Web }, { path: 'signer', component: Signer } ] } diff --git a/js/src/ui/Icons/index.js b/js/src/ui/Icons/index.js index 1e0f93809..a35bbb610 100644 --- a/js/src/ui/Icons/index.js +++ b/js/src/ui/Icons/index.js @@ -25,6 +25,7 @@ import DashboardIcon from 'material-ui/svg-icons/action/dashboard'; import DeleteIcon from 'material-ui/svg-icons/action/delete'; import DoneIcon from 'material-ui/svg-icons/action/done-all'; import EditIcon from 'material-ui/svg-icons/content/create'; +import LinkIcon from 'material-ui/svg-icons/content/link'; import LockedIcon from 'material-ui/svg-icons/action/lock'; import NextIcon from 'material-ui/svg-icons/navigation/arrow-forward'; import PrevIcon from 'material-ui/svg-icons/navigation/arrow-back'; @@ -47,6 +48,7 @@ export { DeleteIcon, DoneIcon, EditIcon, + LinkIcon, LockedIcon, NextIcon, PrevIcon, diff --git a/js/src/views/Dapps/UrlButton/index.js b/js/src/views/Dapps/UrlButton/index.js new file mode 100644 index 000000000..f773334ac --- /dev/null +++ b/js/src/views/Dapps/UrlButton/index.js @@ -0,0 +1,17 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +export default from './urlButton'; diff --git a/js/src/views/Dapps/UrlButton/urlButton.css b/js/src/views/Dapps/UrlButton/urlButton.css new file mode 100644 index 000000000..6b22ae1da --- /dev/null +++ b/js/src/views/Dapps/UrlButton/urlButton.css @@ -0,0 +1,20 @@ +/* Copyright 2015, 2016 Parity Technologies (UK) Ltd. +/* This file is part of Parity. +/* +/* Parity is free software: you can redistribute it and/or modify +/* it under the terms of the GNU General Public License as published by +/* the Free Software Foundation, either version 3 of the License, or +/* (at your option) any later version. +/* +/* Parity is distributed in the hope that it will be useful, +/* but WITHOUT ANY WARRANTY; without even the implied warranty of +/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +/* GNU General Public License for more details. +/* +/* You should have received a copy of the GNU General Public License +/* along with Parity. If not, see . +*/ + +.button { + vertical-align: middle; +} diff --git a/js/src/views/Dapps/UrlButton/urlButton.js b/js/src/views/Dapps/UrlButton/urlButton.js new file mode 100644 index 000000000..0a01be03b --- /dev/null +++ b/js/src/views/Dapps/UrlButton/urlButton.js @@ -0,0 +1,96 @@ +// Copyright 2015, 2016 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Parity is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Parity. If not, see . + +import React, { Component, PropTypes } from 'react'; +import { FormattedMessage } from 'react-intl'; +import { withRouter } from 'react-router'; + +import Button from '~/ui/Button'; +import { LinkIcon } from '~/ui/Icons'; +import Input from '~/ui/Form/Input'; + +import styles from './urlButton.css'; + +const INPUT_STYLE = { display: 'inline-block', width: '20em' }; + +class UrlButton extends Component { + static propTypes = { + router: PropTypes.object.isRequired // injected by withRouter + }; + + state = { + inputShown: false + }; + + render () { + const { inputShown } = this.state; + + return ( +
+ { inputShown ? this.renderInput() : null } +
+ ); + } + + renderInput () { + return ( + + } + onBlur={ this.hideInput } + onFocus={ this.showInput } + onSubmit={ this.inputOnSubmit } + style={ INPUT_STYLE } + /> + ); + } + + toggleInput = () => { + const { inputShown } = this.state; + this.setState({ + inputShown: !inputShown + }); + } + + hideInput = () => { + this.setState({ inputShown: false }); + } + + showInput = () => { + this.setState({ inputShown: true }); + } + + inputOnSubmit = (url) => { + const { router } = this.props; + + router.push(`/web/${encodeURIComponent(url)}`); + } +} + +export default withRouter(UrlButton); diff --git a/js/src/views/Dapps/dapps.js b/js/src/views/Dapps/dapps.js index fa7c44878..8ebbb602d 100644 --- a/js/src/views/Dapps/dapps.js +++ b/js/src/views/Dapps/dapps.js @@ -27,6 +27,7 @@ import PermissionStore from '~/modals/DappPermissions/store'; import { Actionbar, Button, Page } from '~/ui'; import { LockedIcon, VisibleIcon } from '~/ui/Icons'; +import UrlButton from './UrlButton'; import DappsStore from './dappsStore'; import Summary from './Summary'; @@ -88,6 +89,7 @@ class Dapps extends Component { defaultMessage='Decentralized Applications' /> } buttons={ [ + ,