2019-07-17 16:49:06 -04:00
|
|
|
import { connect } from 'react-redux';
|
2020-06-15 16:33:03 -04:00
|
|
|
import { selectUserVerifiedEmail } from 'redux/selectors/user';
|
2020-07-10 17:04:36 -04:00
|
|
|
import { selectHasNavigated, selectScrollStartingPosition, selectWelcomeVersion } from 'redux/selectors/app';
|
2018-04-18 00:03:01 -04:00
|
|
|
import Router from './view';
|
2020-01-25 14:37:02 -06:00
|
|
|
import { normalizeURI, makeSelectTitleForUri } from 'lbry-redux';
|
2020-07-31 17:09:05 -04:00
|
|
|
import { doSetHasNavigated, doSyncWithPreferences } from 'redux/actions/app';
|
2020-07-30 15:14:22 -04:00
|
|
|
import { doSyncClientSettings } from 'redux/actions/settings';
|
2020-01-25 14:37:02 -06: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),
|
2020-02-19 01:31:40 -05:00
|
|
|
welcomeVersion: selectWelcomeVersion(state),
|
2020-07-10 17:04:36 -04:00
|
|
|
hasNavigated: selectHasNavigated(state),
|
2020-01-25 14:37:02 -06:00
|
|
|
};
|
|
|
|
};
|
2019-07-17 16:49:06 -04:00
|
|
|
|
2020-07-10 17:04:36 -04:00
|
|
|
const perform = dispatch => ({
|
|
|
|
setHasNavigated: () => dispatch(doSetHasNavigated()),
|
2020-07-30 15:14:22 -04:00
|
|
|
syncSettings: () => dispatch(doSyncClientSettings()),
|
2020-07-31 17:09:05 -04:00
|
|
|
checkSync: () => dispatch(doSyncWithPreferences()),
|
2020-07-10 17:04:36 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
export default connect(select, perform)(Router);
|