refactor: dispatch ctx api actions on window focus instead

This commit is contained in:
Tim 2022-12-29 09:31:01 +01:00
parent b2890ab9a1
commit 43f3481632
2 changed files with 25 additions and 33 deletions

View file

@ -90,26 +90,30 @@ const App = () => {
};
}, []);
React.useEffect(() => {
if (services.core.active) {
services.core.transport.dispatch({
action: 'Ctx',
args: {
action: 'PullAddonsFromAPI'
}
});
services.core.transport.dispatch({
action: 'Ctx',
args: {
action: 'PullUserFromAPI'
}
});
services.core.transport.dispatch({
action: 'Ctx',
args: {
action: 'SyncLibraryWithAPI'
}
});
}
const onWindowFocus = () => {
if (services.core.active) {
services.core.transport.dispatch({
action: 'Ctx',
args: {
action: 'PullAddonsFromAPI'
}
});
services.core.transport.dispatch({
action: 'Ctx',
args: {
action: 'PullUserFromAPI'
}
});
services.core.transport.dispatch({
action: 'Ctx',
args: {
action: 'SyncLibraryWithAPI'
}
});
}
};
window.addEventListener('focus', onWindowFocus);
return () => window.removeEventListener('focus', onWindowFocus);
}, [initialized]);
return (
<React.StrictMode>

View file

@ -162,19 +162,7 @@ const Settings = () => {
updateSelectedSectionId();
}
closeConfigureServerUrlModal();
const onWindowFocus = () => {
if (!isTraktAuthenticated && traktAuthStarted) {
core.transport.dispatch({
action: 'Ctx',
args: {
action: 'PullUserFromAPI'
}
});
}
};
window.addEventListener('focus', onWindowFocus);
return () => window.removeEventListener('focus', onWindowFocus);
}, [routeFocused, isTraktAuthenticated, traktAuthStarted]);
}, [routeFocused]);
return (
<MainNavBars className={styles['settings-container']} route={'settings'}>
<div className={classnames(styles['settings-content'], 'animation-fade-in')}>