From 5444bbe80e529278474f21f06ad0e26c124b747d Mon Sep 17 00:00:00 2001 From: Thuan Vo Date: Thu, 27 Oct 2022 06:57:35 -0700 Subject: [PATCH] fix(target): add back target auto-refresh option (#577) * fix(target): add back target auto-refresh option * chore(hooks): remove unused hook deps (cherry picked from commit 8dd429d23978cad9f8f7b5f06139434ca06d0efe) --- src/app/TargetSelect/TargetSelect.tsx | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/app/TargetSelect/TargetSelect.tsx b/src/app/TargetSelect/TargetSelect.tsx index d00404708..8f35e9504 100644 --- a/src/app/TargetSelect/TargetSelect.tsx +++ b/src/app/TargetSelect/TargetSelect.tsx @@ -141,6 +141,22 @@ export const TargetSelect: React.FunctionComponent = (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]);