entering lbry url with colon goes to url, doesnt error

This commit is contained in:
zeppi 2021-02-22 22:00:25 -05:00 committed by Sean Yesmunt
parent 1c14928f44
commit f0912f9051

View file

@ -19,6 +19,7 @@ import useThrottle from 'effects/use-throttle';
import Yrbl from 'component/yrbl'; import Yrbl from 'component/yrbl';
import type { ElementRef } from 'react'; import type { ElementRef } from 'react';
const LBRY_PROTOCOL = 'lbry://';
const WEB_DEV_PREFIX = `${URL_DEV}/`; const WEB_DEV_PREFIX = `${URL_DEV}/`;
const WEB_LOCAL_PREFIX = `${URL_LOCAL}/`; const WEB_LOCAL_PREFIX = `${URL_LOCAL}/`;
const WEB_PROD_PREFIX = `${URL}/`; const WEB_PROD_PREFIX = `${URL}/`;
@ -30,10 +31,10 @@ const ESC_KEY_CODE = 27;
type Props = { type Props = {
searchQuery: ?string, searchQuery: ?string,
onSearch: string => void, onSearch: (string) => void,
navigateToSearchPage: string => void, navigateToSearchPage: (string) => void,
doResolveUris: string => void, doResolveUris: (string) => void,
doShowSnackBar: string => void, doShowSnackBar: (string) => void,
showMature: boolean, showMature: boolean,
isMobile: boolean, isMobile: boolean,
doCloseMobileSearch: () => void, doCloseMobileSearch: () => void,
@ -55,10 +56,7 @@ export default function WunderBarSuggestions(props: Props) {
const searchSize = isMobile ? 20 : 5; const searchSize = isMobile ? 20 : 5;
const { results, loading } = useLighthouse(throttledTerm, showMature, searchSize); const { results, loading } = useLighthouse(throttledTerm, showMature, searchSize);
const noResults = throttledTerm && !loading && results && results.length === 0; const noResults = throttledTerm && !loading && results && results.length === 0;
const nameFromQuery = throttledTerm const nameFromQuery = throttledTerm.trim().replace(/\s+/g, '').replace(/:/g, '#');
.trim()
.replace(/\s+/g, '')
.replace(/:/g, '#');
const uriFromQuery = `lbry://${nameFromQuery}`; const uriFromQuery = `lbry://${nameFromQuery}`;
let uriFromQueryIsValid = false; let uriFromQueryIsValid = false;
let channelUrlForTopTest; let channelUrlForTopTest;
@ -117,9 +115,10 @@ export default function WunderBarSuggestions(props: Props) {
if (!isLbryUrl) { if (!isLbryUrl) {
navigateToSearchPage(value); navigateToSearchPage(value);
} else { } else {
let query = 'lbry://' + value.slice(LBRY_PROTOCOL.length).replace(/:/g, '#');
try { try {
if (isURIValid(value)) { if (isURIValid(query)) {
const uri = normalizeURI(value); const uri = normalizeURI(query);
const normalizedWebUrl = formatLbryUrlForWeb(uri); const normalizedWebUrl = formatLbryUrlForWeb(uri);
push(normalizedWebUrl); push(normalizedWebUrl);
} else { } else {
@ -204,7 +203,7 @@ export default function WunderBarSuggestions(props: Props) {
ref={inputRef} ref={inputRef}
className="wunderbar__input" className="wunderbar__input"
placeholder={__('Search')} placeholder={__('Search')}
onChange={e => setTerm(e.target.value)} onChange={(e) => setTerm(e.target.value)}
value={term} value={term}
/> />
@ -217,7 +216,7 @@ export default function WunderBarSuggestions(props: Props) {
{uriFromQueryIsValid ? <WunderbarTopSuggestion query={nameFromQuery} /> : null} {uriFromQueryIsValid ? <WunderbarTopSuggestion query={nameFromQuery} /> : null}
<div className="wunderbar__label">{__('Search Results')}</div> <div className="wunderbar__label">{__('Search Results')}</div>
{results.slice(0, isMobile ? 20 : 5).map(uri => ( {results.slice(0, isMobile ? 20 : 5).map((uri) => (
<WunderbarSuggestion key={uri} uri={uri} /> <WunderbarSuggestion key={uri} uri={uri} />
))} ))}
<ComboboxOption value={term} className="wunderbar__more-results"> <ComboboxOption value={term} className="wunderbar__more-results">