lbry-desktop/ui/component/claimLink/index.js

39 lines
1.3 KiB
JavaScript
Raw Normal View History

2019-06-09 08:57:51 +02:00
import { connect } from 'react-redux';
import { selectClaimForUri, selectIsUriResolving } from 'redux/selectors/claims';
import { doResolveUri } from 'redux/actions/claims';
import { doSetPlayingUri } from 'redux/actions/content';
2021-10-01 18:00:57 +02:00
import { punctuationMarks } from 'util/remark-lbry';
import { selectPlayingUri } from 'redux/selectors/content';
2019-06-09 08:57:51 +02:00
import ClaimLink from './view';
const select = (state, props) => {
let uri = props.uri;
let claim;
/* Used in case of a non-existant claim ending on a punctuation mark,
checks if the url exists without it in case the user was looking for it
and added the punctuation mark for grammatical purposes (it gets added
as part of the URI because some punctuation marks are allowed on URIs) */
function getValidClaim(testUri) {
if (testUri.replace('lbry://', '').length <= 1) return;
claim = selectClaimForUri(state, testUri);
2021-10-01 18:00:57 +02:00
if (claim === null && punctuationMarks.includes(testUri.charAt(testUri.length - 1))) {
getValidClaim(testUri.substring(0, testUri.length - 1));
} else {
uri = testUri;
}
}
getValidClaim(uri);
2019-06-09 08:57:51 +02:00
return {
uri,
claim,
fullUri: props.uri,
isResolvingUri: selectIsUriResolving(state, uri),
playingUri: selectPlayingUri(state),
2019-06-09 08:57:51 +02:00
};
};
export default connect(select, { doResolveUri, doSetPlayingUri })(ClaimLink);