Skip to content

Commit 9dd9c35

Browse files
Jobs list auto-refresh could be restored from the route without restoring its timer. After a reload or route change, the checkbox could appear enabled while polling was actually stopped.
Start or stop the subscription through a shared helper and use it from initialization, route updates, and the toggle handler. The component now keeps and in sync whenever route params are applied.
1 parent edca97c commit 9dd9c35

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

dashboard/src/Dashboard/Component/JobsList.purs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,9 @@ renderPagination state
629629

630630
handleAction :: forall m. MonadAff m => Action -> H.HalogenM State Action () Output m Unit
631631
handleAction = case _ of
632-
Initialize ->
632+
Initialize -> do
633+
state <- H.get
634+
syncAutoRefresh state.autoRefresh
633635
handleAction FetchJobs
634636

635637
-- When the parent passes new params (e.g. the user clicked the title to
@@ -642,6 +644,7 @@ handleAction = case _ of
642644
let p = input.params
643645
H.modify_ _
644646
{ timeRange = parseTimeRange (fromMaybe "" p.range)
647+
, autoRefresh = fromMaybe false p.autoRefresh
645648
, filters =
646649
{ jobType: p.jobType >>= parseJobType
647650
, packageName: fromMaybe "" p.package
@@ -662,6 +665,7 @@ handleAction = case _ of
662665
_, _ -> Nothing
663666
, hasNextPage = true
664667
}
668+
syncAutoRefresh (fromMaybe false p.autoRefresh)
665669
handleAction FetchJobs
666670

667671
FetchJobs -> do
@@ -733,13 +737,7 @@ handleAction = case _ of
733737
updateCustomUntil newUntil
734738

735739
ToggleAutoRefresh enabled -> do
736-
state <- H.get
737-
for_ state.refreshSubId H.unsubscribe
738-
if enabled then do
739-
subId <- H.subscribe =<< Job.timerEmitter refreshInterval Tick
740-
H.modify_ _ { autoRefresh = true, refreshSubId = Just subId }
741-
else
742-
H.modify_ _ { autoRefresh = false, refreshSubId = Nothing }
740+
syncAutoRefresh enabled
743741
notifyFiltersChanged
744742

745743
SetFilterJobType val -> updateFilter _ { jobType = parseJobType val }
@@ -886,6 +884,16 @@ notifyFiltersChanged = do
886884
state <- H.get
887885
H.raise (FiltersChanged (stateToParams state))
888886

887+
syncAutoRefresh :: forall m. MonadAff m => Boolean -> H.HalogenM State Action () Output m Unit
888+
syncAutoRefresh enabled = do
889+
state <- H.get
890+
for_ state.refreshSubId H.unsubscribe
891+
if enabled then do
892+
subId <- H.subscribe =<< Job.timerEmitter refreshInterval Tick
893+
H.modify_ _ { autoRefresh = true, refreshSubId = Just subId }
894+
else
895+
H.modify_ _ { autoRefresh = false, refreshSubId = Nothing }
896+
889897
refreshInterval :: Milliseconds
890898
refreshInterval = Milliseconds 5000.0
891899

0 commit comments

Comments
 (0)