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

49 lines
1.3 KiB
JavaScript
Raw Normal View History

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,
normalizeURI,
2018-04-24 20:17:11 +02:00
} from 'lbry-redux';
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) => {
2019-08-27 18:05:23 +02:00
const { pathname, hash } = props.location;
const urlPath = pathname + hash;
// Remove the leading "/" added by the browser
2019-08-27 18:05:23 +02:00
const path = urlPath.slice(1).replace(/:/g, '#');
let uri;
try {
uri = normalizeURI(path);
} catch (e) {
// Probably an old channel url, redirect to the vanity channel
// @routinghax
const match = path.match(/[#/:]/);
if (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 {
claim: makeSelectClaimForUri(uri)(state),
isResolvingUri: makeSelectIsUriResolving(uri)(state),
blackListedOutpoints: selectBlackListedOutpoints(state),
totalPages: makeSelectTotalPagesForChannel(uri, PAGE_SIZE)(state),
uri,
2019-03-28 17:53:13 +01:00
};
};
2017-06-06 06:21:55 +02:00
const perform = dispatch => ({
2017-06-06 23:19:12 +02:00
resolveUri: uri => dispatch(doResolveUri(uri)),
2017-06-06 06:21:55 +02:00
});
export default connect(
select,
perform
)(ShowPage);