sync settings generally based on navigation and settings paths

This commit is contained in:
jessop 2020-07-30 15:14:22 -04:00 committed by Sean Yesmunt
parent 9acbdf9825
commit c33ce28805
6 changed files with 28 additions and 29 deletions

View file

@ -42,7 +42,6 @@ type Props = {
authHeader: boolean, authHeader: boolean,
backout: { backout: {
backLabel?: string, backLabel?: string,
backCB?: () => void,
backNavDefault?: string, backNavDefault?: string,
title: string, title: string,
simpleTitle: string, // Just use the same value as `title` if `title` is already short (~< 10 chars), unless you have a better idea for title overlfow on mobile simpleTitle: string, // Just use the same value as `title` if `title` is already short (~< 10 chars), unless you have a better idea for title overlfow on mobile
@ -87,7 +86,7 @@ const Header = (props: Props) => {
const isSignInPage = history.location.pathname.includes(PAGES.AUTH_SIGNIN); const isSignInPage = history.location.pathname.includes(PAGES.AUTH_SIGNIN);
const isPwdResetPage = history.location.pathname.includes(PAGES.AUTH_PASSWORD_RESET); const isPwdResetPage = history.location.pathname.includes(PAGES.AUTH_PASSWORD_RESET);
const hasBackout = Boolean(backout); const hasBackout = Boolean(backout);
const { backLabel, backCB, backNavDefault, title: backTitle, simpleTitle: simpleBackTitle } = backout || {}; const { backLabel, backNavDefault, title: backTitle, simpleTitle: simpleBackTitle } = backout || {};
// Sign out if they click the "x" when they are on the password prompt // Sign out if they click the "x" when they are on the password prompt
const authHeaderAction = syncError ? { onClick: signOut } : { navigate: '/' }; const authHeaderAction = syncError ? { onClick: signOut } : { navigate: '/' };
@ -121,9 +120,6 @@ const Header = (props: Props) => {
window.removeEventListener('popstate', onBackout); window.removeEventListener('popstate', onBackout);
if (backCB) {
backCB();
}
if (e.type !== 'popstate') { if (e.type !== 'popstate') {
// if not initiated by pop (back button) // if not initiated by pop (back button)
if (hasNavigated && !backNavDefault) { if (hasNavigated && !backNavDefault) {

View file

@ -21,7 +21,6 @@ type Props = {
noSideNavigation: boolean, noSideNavigation: boolean,
backout: { backout: {
backLabel?: string, backLabel?: string,
backCB?: () => void,
backNavDefault?: string, backNavDefault?: string,
title: string, title: string,
simpleTitle: string, // Just use the same value as `title` if `title` is already short (~< 10 chars), unless you have a better idea for title overlfow on mobile simpleTitle: string, // Just use the same value as `title` if `title` is already short (~< 10 chars), unless you have a better idea for title overlfow on mobile

View file

@ -4,7 +4,7 @@ import { selectHasNavigated, selectScrollStartingPosition, selectWelcomeVersion
import Router from './view'; import Router from './view';
import { normalizeURI, makeSelectTitleForUri } from 'lbry-redux'; import { normalizeURI, makeSelectTitleForUri } from 'lbry-redux';
import { doSetHasNavigated } from 'redux/actions/app'; import { doSetHasNavigated } from 'redux/actions/app';
import { doSyncClientSettings } from 'redux/actions/settings';
const select = state => { const select = state => {
const { pathname, hash } = state.router.location; const { pathname, hash } = state.router.location;
const urlPath = pathname + hash; const urlPath = pathname + hash;
@ -34,6 +34,7 @@ const select = state => {
const perform = dispatch => ({ const perform = dispatch => ({
setHasNavigated: () => dispatch(doSetHasNavigated()), setHasNavigated: () => dispatch(doSetHasNavigated()),
syncSettings: () => dispatch(doSyncClientSettings()),
}); });
export default connect(select, perform)(Router); export default connect(select, perform)(Router);

View file

@ -97,6 +97,7 @@ type Props = {
welcomeVersion: number, welcomeVersion: number,
hasNavigated: boolean, hasNavigated: boolean,
setHasNavigated: () => void, setHasNavigated: () => void,
syncSettings: () => void,
}; };
function AppRouter(props: Props) { function AppRouter(props: Props) {
@ -110,13 +111,15 @@ function AppRouter(props: Props) {
welcomeVersion, welcomeVersion,
hasNavigated, hasNavigated,
setHasNavigated, setHasNavigated,
syncSettings,
} = props; } = props;
const { entries } = history; const { entries } = history;
const entryIndex = history.index; const entryIndex = history.index;
const urlParams = new URLSearchParams(search); const urlParams = new URLSearchParams(search);
const resetScroll = urlParams.get('reset_scroll'); const resetScroll = urlParams.get('reset_scroll');
const [prevPath, setPrevPath] = React.useState(pathname);
// for people arriving at settings page from deeplinks, know whether they can "go back" // For people arriving at settings page from deeplinks, know whether they can "go back"
useEffect(() => { useEffect(() => {
const unlisten = history.listen((location, action) => { const unlisten = history.listen((location, action) => {
if (action === 'PUSH') { if (action === 'PUSH') {
@ -126,6 +129,27 @@ function AppRouter(props: Props) {
return unlisten; return unlisten;
}, [hasNavigated, setHasNavigated]); }, [hasNavigated, setHasNavigated]);
// Sync when no longer on a settings page, or when entering settings pages
useEffect(() => {
const unlisten = history.listen(location => {
if (!location.pathname.includes(PAGES.SETTINGS) && prevPath.includes(PAGES.SETTINGS)) {
syncSettings();
} else if (location.pathname.includes(PAGES.SETTINGS) && !prevPath.includes(PAGES.SETTINGS)) {
syncSettings();
}
});
return unlisten;
}, [prevPath, syncSettings]);
useEffect(() => {
const unlisten = history.listen(location => {
if (prevPath !== location.pathname && setPrevPath) {
setPrevPath(location.pathname);
}
});
return unlisten;
}, [prevPath, setPrevPath]);
useEffect(() => { useEffect(() => {
if (uri) { if (uri) {
const { channelName, streamName } = parseURI(uri); const { channelName, streamName } = parseURI(uri);

View file

@ -66,7 +66,6 @@ type Props = {
openModal: string => void, openModal: string => void,
language?: string, language?: string,
syncEnabled: boolean, syncEnabled: boolean,
syncSettings: () => void,
}; };
type State = { type State = {
@ -87,7 +86,6 @@ class SettingsPage extends React.PureComponent<Props, State> {
(this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this); (this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this);
(this: any).onChangeTime = this.onChangeTime.bind(this); (this: any).onChangeTime = this.onChangeTime.bind(this);
(this: any).onConfirmForgetPassword = this.onConfirmForgetPassword.bind(this); (this: any).onConfirmForgetPassword = this.onConfirmForgetPassword.bind(this);
(this: any).onDone = this.onDone.bind(this);
} }
componentDidMount() { componentDidMount() {
@ -103,14 +101,6 @@ class SettingsPage extends React.PureComponent<Props, State> {
} }
} }
onDone() {
const { syncSettings } = this.props;
if (this.props.syncEnabled) {
syncSettings();
}
}
onThemeChange(event: SyntheticInputEvent<*>) { onThemeChange(event: SyntheticInputEvent<*>) {
const { value } = event.target; const { value } = event.target;
@ -189,7 +179,6 @@ class SettingsPage extends React.PureComponent<Props, State> {
noFooter noFooter
noSideNavigation noSideNavigation
backout={{ backout={{
backCB: () => this.onDone(),
title: __('Settings'), title: __('Settings'),
backLabel: __('Done'), backLabel: __('Done'),
}} }}

View file

@ -77,7 +77,6 @@ class SettingsPage extends React.PureComponent<Props, State> {
(this: any).onThemeChange = this.onThemeChange.bind(this); (this: any).onThemeChange = this.onThemeChange.bind(this);
(this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this); (this: any).onAutomaticDarkModeChange = this.onAutomaticDarkModeChange.bind(this);
(this: any).onConfirmForgetPassword = this.onConfirmForgetPassword.bind(this); (this: any).onConfirmForgetPassword = this.onConfirmForgetPassword.bind(this);
(this: any).onDone = this.onDone.bind(this);
} }
componentDidMount() { componentDidMount() {
@ -104,14 +103,6 @@ class SettingsPage extends React.PureComponent<Props, State> {
} }
} }
onDone() {
const { syncSettings } = this.props;
if (this.props.syncEnabled) {
syncSettings();
}
}
onFFmpegFolder(path: string) { onFFmpegFolder(path: string) {
this.setDaemonSetting('ffmpeg_path', path); this.setDaemonSetting('ffmpeg_path', path);
this.findFFmpeg(); this.findFFmpeg();
@ -211,7 +202,6 @@ class SettingsPage extends React.PureComponent<Props, State> {
noFooter noFooter
noSideNavigation noSideNavigation
backout={{ backout={{
backCB: () => this.onDone(),
title: __('Advanced Settings'), title: __('Advanced Settings'),
backLabel: __('Done'), backLabel: __('Done'),
}} }}