lbry-desktop/ui/page/show/index.js

73 lines
2.4 KiB
JavaScript
Raw Normal View History

2020-08-19 23:25:50 +02:00
import { DOMAIN } from 'config';
import { connect } from 'react-redux';
2019-02-18 18:33:02 +01:00
import { PAGE_SIZE } from 'constants/claim';
2018-04-24 20:17:11 +02:00
import {
doResolveUri,
makeSelectClaimForUri,
makeSelectIsUriResolving,
2019-02-18 18:33:02 +01:00
makeSelectTotalPagesForChannel,
2019-10-17 21:09:03 +02:00
makeSelectTitleForUri,
normalizeURI,
makeSelectClaimIsMine,
2020-07-02 18:47:36 +02:00
makeSelectClaimIsPending,
makeSelectClaimHasSource,
2018-04-24 20:17:11 +02:00
} from 'lbry-redux';
import { makeSelectChannelInSubscriptions } from 'redux/selectors/subscriptions';
2019-03-12 20:53:55 +01:00
import { selectBlackListedOutpoints } from 'lbryinc';
import ShowPage from './view';
2019-03-28 17:53:13 +01:00
const select = (state, props) => {
2020-08-19 23:25:50 +02:00
const { pathname, hash, search } = props.location;
2019-08-27 18:05:23 +02:00
const urlPath = pathname + hash;
// Remove the leading "/" added by the browser
2020-08-19 23:25:50 +02:00
let path = urlPath.slice(1).replace(/:/g, '#');
// Google cache url
// ex: webcache.googleusercontent.com/search?q=cache:MLwN3a8fCbYJ:https://lbry.tv/%40Bombards_Body_Language:f+&cd=12&hl=en&ct=clnk&gl=us
// Extract the lbry url and use that instead
// Without this it will try to render lbry://search
if (search && search.startsWith('?q=cache:')) {
const googleCacheRegex = new RegExp(`(https://${DOMAIN}/)([^+]*)`);
const [x, y, googleCachedUrl] = search.match(googleCacheRegex); // eslint-disable-line
if (googleCachedUrl) {
const actualUrl = decodeURIComponent(googleCachedUrl);
if (actualUrl) {
2020-08-19 23:40:12 +02:00
path = actualUrl.replace(/:/g, '#');
2020-08-19 23:25:50 +02:00
}
}
}
let uri;
try {
uri = normalizeURI(path);
} catch (e) {
const match = path.match(/[#/:]/);
2019-09-26 18:07:11 +02:00
if (path === '$/') {
props.history.replace(`/`);
} else if (!path.startsWith('$/') && match && match.index) {
uri = `lbry://${path.slice(0, match.index)}`;
props.history.replace(`/${path.slice(0, match.index)}`);
}
}
2019-04-04 23:05:23 +02:00
2019-03-28 17:53:13 +01:00
return {
uri,
2019-03-28 17:53:13 +01:00
claim: makeSelectClaimForUri(uri)(state),
isResolvingUri: makeSelectIsUriResolving(uri)(state),
blackListedOutpoints: selectBlackListedOutpoints(state),
totalPages: makeSelectTotalPagesForChannel(uri, PAGE_SIZE)(state),
isSubscribed: makeSelectChannelInSubscriptions(uri)(state),
2019-10-17 21:09:03 +02:00
title: makeSelectTitleForUri(uri)(state),
claimIsMine: makeSelectClaimIsMine(uri)(state),
2020-07-02 18:47:36 +02:00
claimIsPending: makeSelectClaimIsPending(uri)(state),
isLivestream: !makeSelectClaimHasSource(uri)(state),
2019-03-28 17:53:13 +01:00
};
};
const perform = (dispatch) => ({
resolveUri: (uri) => dispatch(doResolveUri(uri)),
2017-06-06 06:21:55 +02:00
});
2020-05-21 17:38:28 +02:00
export default connect(select, perform)(ShowPage);