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

34 lines
990 B
JavaScript
Raw Normal View History

2019-07-17 22:49:06 +02:00
import { connect } from 'react-redux';
2019-09-26 18:07:11 +02:00
import { selectUserVerifiedEmail } from 'lbryinc';
import { selectScrollStartingPosition, selectWelcomeVersion } from 'redux/selectors/app';
2018-04-18 06:03:01 +02:00
import Router from './view';
2020-01-25 21:37:02 +01:00
import { normalizeURI, makeSelectTitleForUri } from 'lbry-redux';
2019-07-17 22:49:06 +02:00
2020-01-25 21:37:02 +01:00
const select = state => {
const { pathname, hash } = state.router.location;
const urlPath = pathname + hash;
// Remove the leading "/" added by the browser
const path = urlPath.slice(1).replace(/:/g, '#');
let uri;
try {
uri = normalizeURI(path);
} catch (e) {
const match = path.match(/[#/:]/);
if (!path.startsWith('$/') && match && match.index) {
uri = `lbry://${path.slice(0, match.index)}`;
}
}
return {
uri,
title: makeSelectTitleForUri(uri)(state),
currentScroll: selectScrollStartingPosition(state),
isAuthenticated: selectUserVerifiedEmail(state),
welcomeVersion: selectWelcomeVersion(state),
2020-01-25 21:37:02 +01:00
};
};
2019-07-17 22:49:06 +02:00
export default connect(select)(Router);