2020-12-03 18:29:47 +01:00
|
|
|
import { connect } from 'react-redux';
|
2021-09-18 16:23:30 +02:00
|
|
|
import {
|
|
|
|
makeSelectClaimForUri,
|
2021-11-16 05:43:28 +01:00
|
|
|
selectIsUriResolving,
|
2021-09-18 16:23:30 +02:00
|
|
|
makeSelectTagInClaimOrChannelForUri,
|
2021-10-17 10:36:14 +02:00
|
|
|
} from 'redux/selectors/claims';
|
|
|
|
import { doResolveUris } from 'redux/actions/claims';
|
|
|
|
import { parseURI } from 'util/lbryURI';
|
2020-12-03 18:29:47 +01:00
|
|
|
import { makeSelectWinningUriForQuery } from 'redux/selectors/search';
|
|
|
|
import WunderbarTopSuggestion from './view';
|
2021-09-18 16:23:30 +02:00
|
|
|
import { PREFERENCE_EMBED } from 'constants/tags';
|
2020-12-03 18:29:47 +01:00
|
|
|
|
|
|
|
const select = (state, props) => {
|
2020-12-03 21:42:41 +01:00
|
|
|
const uriFromQuery = `lbry://${props.query}`;
|
|
|
|
|
|
|
|
let uris = [uriFromQuery];
|
|
|
|
try {
|
|
|
|
const { isChannel } = parseURI(uriFromQuery);
|
|
|
|
|
|
|
|
if (!isChannel) {
|
2020-12-03 22:06:54 +01:00
|
|
|
const channelUriFromQuery = `lbry://@${props.query}`;
|
2020-12-03 21:42:41 +01:00
|
|
|
uris.push(channelUriFromQuery);
|
|
|
|
}
|
|
|
|
} catch (e) {}
|
|
|
|
|
2021-11-16 05:43:28 +01:00
|
|
|
const resolvingUris = uris.some((uri) => selectIsUriResolving(state, uri));
|
2020-12-03 18:29:47 +01:00
|
|
|
const winningUri = makeSelectWinningUriForQuery(props.query)(state);
|
|
|
|
const winningClaim = winningUri ? makeSelectClaimForUri(winningUri)(state) : undefined;
|
2021-09-18 16:23:30 +02:00
|
|
|
const preferEmbed = makeSelectTagInClaimOrChannelForUri(winningUri, PREFERENCE_EMBED)(state);
|
2020-12-03 18:29:47 +01:00
|
|
|
|
2021-09-18 16:23:30 +02:00
|
|
|
return { resolvingUris, winningUri, winningClaim, uris, preferEmbed };
|
2020-12-03 18:29:47 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
export default connect(select, {
|
|
|
|
doResolveUris,
|
|
|
|
})(WunderbarTopSuggestion);
|