fix winning claim for top search results

This commit is contained in:
Sean Yesmunt 2020-02-11 13:36:17 -05:00
parent 7eb340167a
commit 9343f5855c
2 changed files with 15 additions and 27 deletions

View file

@ -1,7 +1,7 @@
// @flow // @flow
import * as ICONS from 'constants/icons'; import * as ICONS from 'constants/icons';
import React, { useEffect, Fragment } from 'react'; import React, { useEffect, Fragment } from 'react';
import { isURIValid, normalizeURI, regexInvalidURI } from 'lbry-redux'; import { regexInvalidURI } from 'lbry-redux';
import ClaimPreview from 'component/claimPreview'; import ClaimPreview from 'component/claimPreview';
import ClaimList from 'component/claimList'; import ClaimList from 'component/claimList';
import Page from 'component/page'; import Page from 'component/page';
@ -27,28 +27,18 @@ type Props = {
export default function SearchPage(props: Props) { export default function SearchPage(props: Props) {
const { search, uris, onFeedbackPositive, onFeedbackNegative, location, isSearching, showNsfw } = props; const { search, uris, onFeedbackPositive, onFeedbackNegative, location, isSearching, showNsfw } = props;
const urlParams = new URLSearchParams(location.search); const urlParams = new URLSearchParams(location.search);
const urlQuery = urlParams.get('q'); const urlQuery = urlParams.get('q') || '';
const additionalOptions: AdditionalOptions = { isBackgroundSearch: false }; const additionalOptions: AdditionalOptions = { isBackgroundSearch: false };
if (!showNsfw) { if (!showNsfw) {
additionalOptions['nsfw'] = false; additionalOptions['nsfw'] = false;
} }
let normalizedUri; const INVALID_URI_CHARS = new RegExp(regexInvalidURI, 'gu');
let isUriValid; const modifiedUrlQuery = urlQuery
if (isURIValid(urlQuery)) { .trim()
isUriValid = true; .replace(/\s+/g, '-')
normalizedUri = normalizeURI(urlQuery); .replace(INVALID_URI_CHARS, '');
} else { const uriFromQuery = `lbry://${modifiedUrlQuery}`;
let INVALID_URI_CHARS = new RegExp(regexInvalidURI, 'gu');
let modifiedUrlQuery = urlQuery
? urlQuery
.trim()
.replace(/\s+/g, '-')
.replace(INVALID_URI_CHARS, '')
: '';
isUriValid = isURIValid(modifiedUrlQuery);
normalizedUri = isUriValid && normalizeURI(modifiedUrlQuery);
}
useEffect(() => { useEffect(() => {
if (urlQuery) { if (urlQuery) {
@ -61,14 +51,12 @@ export default function SearchPage(props: Props) {
<section className="search"> <section className="search">
{urlQuery && ( {urlQuery && (
<Fragment> <Fragment>
{isUriValid && ( <header className="search__header">
<header className="search__header"> <ClaimUri uri={uriFromQuery} />
<ClaimUri uri={normalizedUri} /> <div className="card">
<div className="card"> <ClaimPreview uri={uriFromQuery} type="large" placeholder="publish" />
<ClaimPreview uri={normalizedUri} type="large" placeholder="publish" /> </div>
</div> </header>
</header>
)}
<ClaimList <ClaimList
uris={uris} uris={uris}

View file

@ -121,7 +121,7 @@
.claim-preview--large { .claim-preview--large {
border: none; border: none;
padding: 0; padding: 0;
padding: var(--spacing-medium); padding: var(--spacing-small);
&:hover { &:hover {
background-color: transparent; background-color: transparent;