create showSnackError function

This commit is contained in:
Sean Yesmunt 2019-03-14 19:42:49 -04:00
parent 02d8b7e5ea
commit b0ba23e49a

View file

@ -81,7 +81,7 @@ class WunderBar extends React.PureComponent<Props> {
} }
handleSubmit(value: string, suggestion?: { value: string, type: string }) { handleSubmit(value: string, suggestion?: { value: string, type: string }) {
const { onSubmit, onSearch } = this.props; const { onSubmit, onSearch, doShowSnackBar } = this.props;
const query = value.trim(); const query = value.trim();
const getParams = () => { const getParams = () => {
const parts = query.split('?'); const parts = query.split('?');
@ -94,6 +94,12 @@ class WunderBar extends React.PureComponent<Props> {
return extraParams; return extraParams;
}; };
const showSnackError = () => {
doShowSnackBar({
message: __('Invalid LBRY URL entered. Only A-Z, a-z, 0-9, and "-" allowed.'),
});
};
// User selected a suggestion // User selected a suggestion
if (suggestion) { if (suggestion) {
if (suggestion.type === 'search') { if (suggestion.type === 'search') {
@ -103,9 +109,7 @@ class WunderBar extends React.PureComponent<Props> {
const uri = normalizeURI(query); const uri = normalizeURI(query);
onSubmit(uri, params); onSubmit(uri, params);
} else { } else {
this.props.doShowSnackBar({ showSnackError();
message: __('Invalid LBRY URL entered. Only A-Z, a-z, 0-9, and - allowed.'),
});
} }
return; return;
@ -119,9 +123,7 @@ class WunderBar extends React.PureComponent<Props> {
const params = getParams(); const params = getParams();
onSubmit(uri, params); onSubmit(uri, params);
} else { } else {
this.props.doShowSnackBar({ showSnackError();
message: __('Invalid LBRY URL entered. Only A-Z, a-z, 0-9, and - allowed.'),
});
} }
} catch (e) { } catch (e) {
onSearch(query); onSearch(query);