2019-06-09 08:57:51 +02:00
|
|
|
import { connect } from 'react-redux';
|
2022-03-15 17:28:55 +01:00
|
|
|
import { selectClaimForUri, selectIsUriResolving } from 'redux/selectors/claims';
|
2021-10-17 10:36:14 +02:00
|
|
|
import { doResolveUri } from 'redux/actions/claims';
|
2021-09-30 23:30:32 +02:00
|
|
|
import { doSetPlayingUri } from 'redux/actions/content';
|
2021-10-01 18:00:57 +02:00
|
|
|
import { punctuationMarks } from 'util/remark-lbry';
|
2020-10-20 19:10:02 +02:00
|
|
|
import { selectPlayingUri } from 'redux/selectors/content';
|
2019-06-09 08:57:51 +02:00
|
|
|
import ClaimLink from './view';
|
|
|
|
|
|
|
|
const select = (state, props) => {
|
2021-09-30 23:30:32 +02:00
|
|
|
let uri = props.uri;
|
|
|
|
let claim;
|
|
|
|
|
2021-12-07 20:03:19 +01:00
|
|
|
/* 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) */
|
2021-09-30 23:30:32 +02:00
|
|
|
function getValidClaim(testUri) {
|
2021-12-07 20:03:19 +01:00
|
|
|
if (testUri.replace('lbry://', '').length <= 1) return;
|
|
|
|
|
2022-03-15 17:28:55 +01:00
|
|
|
claim = selectClaimForUri(state, testUri);
|
2021-10-01 18:00:57 +02:00
|
|
|
if (claim === null && punctuationMarks.includes(testUri.charAt(testUri.length - 1))) {
|
2021-09-30 23:30:32 +02:00
|
|
|
getValidClaim(testUri.substring(0, testUri.length - 1));
|
|
|
|
} else {
|
|
|
|
uri = testUri;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
getValidClaim(uri);
|
|
|
|
|
2019-06-09 08:57:51 +02:00
|
|
|
return {
|
2021-09-30 23:30:32 +02:00
|
|
|
uri,
|
|
|
|
claim,
|
|
|
|
fullUri: props.uri,
|
2021-11-16 05:43:28 +01:00
|
|
|
isResolvingUri: selectIsUriResolving(state, uri),
|
2020-10-20 19:10:02 +02:00
|
|
|
playingUri: selectPlayingUri(state),
|
2019-06-09 08:57:51 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2021-09-30 23:30:32 +02:00
|
|
|
export default connect(select, { doResolveUri, doSetPlayingUri })(ClaimLink);
|