This commit is contained in:
zeppi 2021-10-13 09:30:50 -04:00 committed by jessopb
parent 1981f16715
commit 6c3ed54d87
9 changed files with 18 additions and 29 deletions

View file

@ -5,7 +5,7 @@ import { NavLink, withRouter } from 'react-router-dom';
import { isEmpty } from 'util/object'; import { isEmpty } from 'util/object';
import { lazyImport } from 'util/lazyImport'; import { lazyImport } from 'util/lazyImport';
import classnames from 'classnames'; import classnames from 'classnames';
import { parseURI, isURIEqual } from 'util/lbryURI'; import { isURIEqual, isURIValid } from 'util/lbryURI';
import * as COLLECTIONS_CONSTS from 'constants/collections'; import * as COLLECTIONS_CONSTS from 'constants/collections';
import { formatLbryUrlForWeb } from 'util/url'; import { formatLbryUrlForWeb } from 'util/url';
import { formatClaimPreviewTitle } from 'util/formatAriaLabel'; import { formatClaimPreviewTitle } from 'util/formatAriaLabel';
@ -180,15 +180,8 @@ const ClaimPreview = forwardRef<any, {}>((props: Props, ref: any) => {
</span> </span>
); );
}, [channelSubCount]); }, [channelSubCount]);
let isValid = false; const isValid = uri && isURIValid(uri);
if (uri) {
try {
parseURI(uri);
isValid = true;
} catch (e) {
isValid = false;
}
}
// $FlowFixMe // $FlowFixMe
const isPlayable = const isPlayable =
claim && claim &&

View file

@ -8,6 +8,7 @@ import usePrevious from 'effects/use-previous';
type SearchOptions = { type SearchOptions = {
page_size: number, page_size: number,
page: number,
no_totals: boolean, no_totals: boolean,
any_tags: Array<string>, any_tags: Array<string>,
channel_ids: Array<string>, channel_ids: Array<string>,

View file

@ -249,7 +249,7 @@ function CollectionForm(props: Props) {
let nameError; let nameError;
if (!name && name !== undefined) { if (!name && name !== undefined) {
nameError = __('A name is required for your url'); nameError = __('A name is required for your url');
} else if (!isNameValid(name, false)) { } else if (!isNameValid(name)) {
nameError = INVALID_NAME_ERROR; nameError = INVALID_NAME_ERROR;
} }

View file

@ -94,7 +94,7 @@ function CommentMenuList(props: Props) {
function assignAsModerator() { function assignAsModerator() {
if (activeChannelClaim && authorUri) { if (activeChannelClaim && authorUri) {
const { channelName, channelClaimId } = parseURI(authorUri); const { channelName, channelClaimId } = parseURI(authorUri);
commentModAddDelegate(channelClaimId, channelName, activeChannelClaim); if (channelName && channelClaimId) commentModAddDelegate(channelClaimId, channelName, activeChannelClaim);
} }
} }

View file

@ -14,8 +14,9 @@ type Props = {
export default function NotificationContentChannelMenu(props: Props) { export default function NotificationContentChannelMenu(props: Props) {
const { uri, notificationsDisabled, doToast, doChannelSubscribe } = props; const { uri, notificationsDisabled, doToast, doChannelSubscribe } = props;
const { claimName } = parseURI(uri); let claimName;
const { claimName: name } = parseURI(uri);
claimName = name || '';
function handleClick() { function handleClick() {
doChannelSubscribe({ doChannelSubscribe({
uri, uri,

View file

@ -43,7 +43,7 @@ function PublishFormErrors(props: Props) {
{waitForFile && <div>{__('Choose a replay file, or select None')}</div>} {waitForFile && <div>{__('Choose a replay file, or select None')}</div>}
{!title && <div>{__('A title is required')}</div>} {!title && <div>{__('A title is required')}</div>}
{!name && <div>{__('A URL is required')}</div>} {!name && <div>{__('A URL is required')}</div>}
{!isNameValid(name, false) && INVALID_NAME_ERROR} {name && !isNameValid(name) && INVALID_NAME_ERROR}
{!bid && <div>{__('A deposit amount is required')}</div>} {!bid && <div>{__('A deposit amount is required')}</div>}
{bidError && <div>{__('Please check your deposit amount.')}</div>} {bidError && <div>{__('Please check your deposit amount.')}</div>}
{isUploadingThumbnail && <div>{__('Please wait for thumbnail to finish uploading')}</div>} {isUploadingThumbnail && <div>{__('Please wait for thumbnail to finish uploading')}</div>}

View file

@ -165,7 +165,7 @@ function RepostCreate(props: Props) {
let repostNameError; let repostNameError;
if (!enteredRepostName) { if (!enteredRepostName) {
repostNameError = __('A name is required'); repostNameError = __('A name is required');
} else if (!isNameValid(enteredRepostName, false)) { } else if (!isNameValid(enteredRepostName)) {
repostNameError = INVALID_NAME_ERROR; repostNameError = INVALID_NAME_ERROR;
} else if (!available) { } else if (!available) {
repostNameError = __('You already have a claim with this name.'); repostNameError = __('You already have a claim with this name.');
@ -178,7 +178,7 @@ function RepostCreate(props: Props) {
} }
React.useEffect(() => { React.useEffect(() => {
if (enteredRepostName && isNameValid(enteredRepostName, false)) { if (enteredRepostName && isNameValid(enteredRepostName)) {
doCheckPublishNameAvailability(enteredRepostName).then((r) => setAvailable(r)); doCheckPublishNameAvailability(enteredRepostName).then((r) => setAvailable(r));
} }
}, [enteredRepostName, doCheckPublishNameAvailability]); }, [enteredRepostName, doCheckPublishNameAvailability]);
@ -262,14 +262,14 @@ function RepostCreate(props: Props) {
} else if (entered) { } else if (entered) {
try { try {
const { claimName } = parseURI(entered); const { claimName } = parseURI(entered);
return `/${claimName}`; return claimName ? `/${claimName}` : '/';
} catch (e) { } catch (e) {
return '/'; return '/';
} }
} else if (passed) { } else if (passed) {
try { try {
const { claimName } = parseURI(passed); const { claimName } = parseURI(passed);
return `/${claimName}`; return claimName ? `/${claimName}` : '/';
} catch (e) { } catch (e) {
return '/'; return '/';
} }

View file

@ -605,7 +605,7 @@ export function doFetchCollectionListMine(page: number = 1, pageSize: number = 9
export function doClaimSearch( export function doClaimSearch(
options: { options: {
page_size: number, page_size?: number,
page: number, page: number,
no_totals?: boolean, no_totals?: boolean,
any_tags?: Array<string>, any_tags?: Array<string>,

View file

@ -1,5 +1,5 @@
// @flow // @flow
import { normalizeURI, parseURI } from 'util/lbryURI'; import { normalizeURI, parseURI, isURIValid } from 'util/lbryURI';
import { selectSupportsByOutpoint } from 'redux/selectors/wallet'; import { selectSupportsByOutpoint } from 'redux/selectors/wallet';
import { createSelector } from 'reselect'; import { createSelector } from 'reselect';
import { isClaimNsfw, filterClaims } from 'util/claim'; import { isClaimNsfw, filterClaims } from 'util/claim';
@ -76,11 +76,7 @@ export const makeSelectClaimForClaimId = (claimId: string) => createSelector(sel
export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) => export const makeSelectClaimForUri = (uri: string, returnRepost: boolean = true) =>
createSelector(selectClaimIdsByUri, selectClaimsById, (byUri, byId) => { createSelector(selectClaimIdsByUri, selectClaimsById, (byUri, byId) => {
let validUri; const validUri = isURIValid(uri);
try {
parseURI(uri);
validUri = true;
} catch (e) {}
if (validUri && byUri) { if (validUri && byUri) {
const claimId = uri && byUri[normalizeURI(uri)]; const claimId = uri && byUri[normalizeURI(uri)];
@ -154,9 +150,7 @@ export const makeSelectClaimIsMine = (rawUri: string) => {
} catch (e) {} } catch (e) {}
return createSelector(selectClaimsByUri, selectMyActiveClaims, (claims, myClaims) => { return createSelector(selectClaimsByUri, selectMyActiveClaims, (claims, myClaims) => {
try { if (!isURIValid(uri)) {
parseURI(uri);
} catch (e) {
return false; return false;
} }