Skip to content

Commit

Permalink
fix(target): add back target auto-refresh option (#577)
Browse files Browse the repository at this point in the history
* fix(target): add back target auto-refresh option

* chore(hooks): remove unused hook deps
  • Loading branch information
Thuan Vo authored Oct 27, 2022
1 parent 1155826 commit 8dd429d
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/app/TargetSelect/TargetSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,22 @@ export const TargetSelect: React.FunctionComponent<TargetSelectProps> = (props)
addSubscription(context.target.target().subscribe(setSelected));
}, [addSubscription, context.target, setSelected]);

const refreshTargetList = React.useCallback(() => {
setLoading(true);
addSubscription(context.targets.queryForTargets().subscribe(() => setLoading(false)));
}, [addSubscription, context.targets, setLoading]);

React.useEffect(() => {
if (!context.settings.autoRefreshEnabled()) {
return;
}
const id = window.setInterval(
() => refreshTargetList(),
context.settings.autoRefreshPeriod() * context.settings.autoRefreshUnits()
);
return () => window.clearInterval(id);
}, [context.settings, refreshTargetList]);

const showCreateTargetModal = React.useCallback(() => {
setModalOpen(true);
}, [setModalOpen]);
Expand Down

0 comments on commit 8dd429d

Please sign in to comment.