From 2707210744dde052e0b1da64414287ad6538fbda Mon Sep 17 00:00:00 2001 From: Thomas Zarebczan Date: Thu, 11 Oct 2018 01:56:47 -0400 Subject: [PATCH 1/3] fix 1972 Adds a snackbar if the lbry:// URL is invalid I tried to do the doNotify similar to most of the other pages, but failed. --- src/renderer/component/wunderbar/view.jsx | 32 ++++++++++++++++++----- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/renderer/component/wunderbar/view.jsx b/src/renderer/component/wunderbar/view.jsx index 1736fb1d5..9ffb32fc8 100644 --- a/src/renderer/component/wunderbar/view.jsx +++ b/src/renderer/component/wunderbar/view.jsx @@ -1,7 +1,7 @@ // @flow import React from 'react'; import classnames from 'classnames'; -import { normalizeURI, SEARCH_TYPES } from 'lbry-redux'; +import { normalizeURI, SEARCH_TYPES, doNotify, isURIValid } from 'lbry-redux'; import Icon from 'component/common/icon'; import { parseQueryParams } from 'util/query_params'; import * as icons from 'constants/icons'; @@ -101,9 +101,18 @@ class WunderBar extends React.PureComponent { if (suggestion.type === 'search') { onSearch(query, resultCount); } else { - const params = getParams(); - const uri = normalizeURI(query); - onSubmit(uri, params); + if (isURIValid(query)) { + const params = getParams(); + const uri = normalizeURI(query); + onSubmit(uri, params); + } else { + window.app.store.dispatch( + doNotify({ + message: __('Invalid LBRY URL requested. Only A-Z, a-z, and - allowed.'), + displayType: ['snackbar'], + }) + ); + } } return; @@ -112,9 +121,18 @@ class WunderBar extends React.PureComponent { // Currently no suggestion is highlighted. The user may have started // typing, then lost focus and came back later on the same page try { - const uri = normalizeURI(query); - const params = getParams(); - onSubmit(uri, params); + if (isURIValid(query)) { + const uri = normalizeURI(query); + const params = getParams(); + onSubmit(uri, params); + } else { + window.app.store.dispatch( + doNotify({ + message: __('Invalid LBRY URL entered. Only A-Z, a-z, and - allowed.'), + displayType: ['snackbar'], + }) + ); + } } catch (e) { onSearch(query, resultCount); } From 9b1797c1ab974184c05eaa0d8e136ea47452ff6b Mon Sep 17 00:00:00 2001 From: Thomas Zarebczan Date: Thu, 11 Oct 2018 02:38:27 -0400 Subject: [PATCH 2/3] take 2 Fixing up per Sean's recommendations --- src/renderer/component/wunderbar/index.js | 2 ++ src/renderer/component/wunderbar/view.jsx | 10 +++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/renderer/component/wunderbar/index.js b/src/renderer/component/wunderbar/index.js index 1bbcd3b26..13dcc37d7 100644 --- a/src/renderer/component/wunderbar/index.js +++ b/src/renderer/component/wunderbar/index.js @@ -7,6 +7,7 @@ import { doFocusSearchInput, doBlurSearchInput, doSearch, + doNotify, } from 'lbry-redux'; import { makeSelectClientSetting } from 'redux/selectors/settings'; import * as settings from 'constants/settings'; @@ -38,6 +39,7 @@ const perform = dispatch => ({ updateSearchQuery: query => dispatch(doUpdateSearchQuery(query)), doFocus: () => dispatch(doFocusSearchInput()), doBlur: () => dispatch(doBlurSearchInput()), + doShowSnackBar: (modal, props) => dispatch(doNotify(modal, props)), }); export default connect( diff --git a/src/renderer/component/wunderbar/view.jsx b/src/renderer/component/wunderbar/view.jsx index 9ffb32fc8..e18c9bc65 100644 --- a/src/renderer/component/wunderbar/view.jsx +++ b/src/renderer/component/wunderbar/view.jsx @@ -1,7 +1,7 @@ // @flow import React from 'react'; import classnames from 'classnames'; -import { normalizeURI, SEARCH_TYPES, doNotify, isURIValid } from 'lbry-redux'; +import { normalizeURI, SEARCH_TYPES, isURIValid } from 'lbry-redux'; import Icon from 'component/common/icon'; import { parseQueryParams } from 'util/query_params'; import * as icons from 'constants/icons'; @@ -106,12 +106,10 @@ class WunderBar extends React.PureComponent { const uri = normalizeURI(query); onSubmit(uri, params); } else { - window.app.store.dispatch( - doNotify({ + this.props.doShowSnackBar({ message: __('Invalid LBRY URL requested. Only A-Z, a-z, and - allowed.'), displayType: ['snackbar'], }) - ); } } @@ -126,12 +124,10 @@ class WunderBar extends React.PureComponent { const params = getParams(); onSubmit(uri, params); } else { - window.app.store.dispatch( - doNotify({ + this.props.doShowSnackBar({ message: __('Invalid LBRY URL entered. Only A-Z, a-z, and - allowed.'), displayType: ['snackbar'], }) - ); } } catch (e) { onSearch(query, resultCount); From 45961e7d76f2e56b091f059705f559ebce21fdc4 Mon Sep 17 00:00:00 2001 From: Thomas Zarebczan Date: Thu, 11 Oct 2018 02:39:58 -0400 Subject: [PATCH 3/3] Update view.jsx --- src/renderer/component/wunderbar/view.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/component/wunderbar/view.jsx b/src/renderer/component/wunderbar/view.jsx index e18c9bc65..daace0ec9 100644 --- a/src/renderer/component/wunderbar/view.jsx +++ b/src/renderer/component/wunderbar/view.jsx @@ -107,7 +107,7 @@ class WunderBar extends React.PureComponent { onSubmit(uri, params); } else { this.props.doShowSnackBar({ - message: __('Invalid LBRY URL requested. Only A-Z, a-z, and - allowed.'), + message: __('Invalid LBRY URL entered. Only A-Z, a-z, and - allowed.'), displayType: ['snackbar'], }) }