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

55 lines
1.6 KiB
JavaScript
Raw Normal View History

import { connect } from 'react-redux';
2019-02-18 12:33:02 -05:00
import { PAGE_SIZE } from 'constants/claim';
2018-04-24 14:17:11 -04:00
import {
doResolveUri,
makeSelectClaimForUri,
makeSelectIsUriResolving,
2019-02-18 12:33:02 -05:00
makeSelectTotalPagesForChannel,
2019-10-17 15:09:03 -04:00
makeSelectTitleForUri,
normalizeURI,
makeSelectClaimIsMine,
2020-07-02 12:47:36 -04:00
makeSelectClaimIsPending,
2018-04-24 14:17:11 -04:00
} from 'lbry-redux';
import { makeSelectChannelInSubscriptions } from 'redux/selectors/subscriptions';
2019-03-12 15:53:55 -04:00
import { selectBlackListedOutpoints } from 'lbryinc';
import ShowPage from './view';
2019-03-28 12:53:13 -04:00
const select = (state, props) => {
2019-08-27 12:05:23 -04:00
const { pathname, hash } = props.location;
const urlPath = pathname + hash;
// Remove the leading "/" added by the browser
2019-08-27 12:05:23 -04:00
const path = urlPath.slice(1).replace(/:/g, '#');
let uri;
try {
uri = normalizeURI(path);
} catch (e) {
const match = path.match(/[#/:]/);
2019-09-26 12:07:11 -04: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 17:05:23 -04:00
2019-03-28 12:53:13 -04:00
return {
claim: makeSelectClaimForUri(uri)(state),
isResolvingUri: makeSelectIsUriResolving(uri)(state),
blackListedOutpoints: selectBlackListedOutpoints(state),
totalPages: makeSelectTotalPagesForChannel(uri, PAGE_SIZE)(state),
isSubscribed: makeSelectChannelInSubscriptions(uri)(state),
uri,
2019-10-17 15:09:03 -04:00
title: makeSelectTitleForUri(uri)(state),
claimIsMine: makeSelectClaimIsMine(uri)(state),
2020-07-02 12:47:36 -04:00
claimIsPending: makeSelectClaimIsPending(uri)(state),
2019-03-28 12:53:13 -04:00
};
};
2017-06-05 21:21:55 -07:00
const perform = dispatch => ({
2017-06-06 17:19:12 -04:00
resolveUri: uri => dispatch(doResolveUri(uri)),
2017-06-05 21:21:55 -07:00
});
2020-05-21 11:38:28 -04:00
export default connect(select, perform)(ShowPage);