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

37 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2020-12-03 18:29:47 +01:00
import { connect } from 'react-redux';
import {
doResolveUris,
makeSelectClaimForUri,
makeSelectIsUriResolving,
makeSelectTagInClaimOrChannelForUri,
parseURI,
} from 'lbry-redux';
2020-12-03 18:29:47 +01:00
import { makeSelectWinningUriForQuery } from 'redux/selectors/search';
import WunderbarTopSuggestion from './view';
import { PREFERENCE_EMBED } from 'constants/tags';
2020-12-03 18:29:47 +01:00
const select = (state, props) => {
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}`;
uris.push(channelUriFromQuery);
}
} catch (e) {}
const resolvingUris = uris.some((uri) => makeSelectIsUriResolving(uri)(state));
2020-12-03 18:29:47 +01:00
const winningUri = makeSelectWinningUriForQuery(props.query)(state);
const winningClaim = winningUri ? makeSelectClaimForUri(winningUri)(state) : undefined;
const preferEmbed = makeSelectTagInClaimOrChannelForUri(winningUri, PREFERENCE_EMBED)(state);
2020-12-03 18:29:47 +01:00
return { resolvingUris, winningUri, winningClaim, uris, preferEmbed };
2020-12-03 18:29:47 +01:00
};
export default connect(select, {
doResolveUris,
})(WunderbarTopSuggestion);