mirror of
https://github.com/Stremio/stremio-web.git
synced 2026-04-19 09:42:13 +00:00
refactor: dispatch ctx api actions on window focus instead
This commit is contained in:
parent
b2890ab9a1
commit
43f3481632
2 changed files with 25 additions and 33 deletions
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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')}>
|
||||
|
|
|
|||
Loading…
Reference in a new issue