11<script setup lang="ts">
2- import { ref , watch } from " vue" ;
2+ import { ref , computed , watch } from " vue" ;
33import { useRouter } from " vue-router" ;
44import { useShowToast } from " ../../composables/toast" ;
55import NoData from " ../NoData.vue" ;
@@ -18,8 +18,10 @@ import { useStoreAutoRefresh } from "@/composables/useAutoRefresh";
1818import { storeToRefs } from " pinia" ;
1919import LoadingSpinner from " ../LoadingSpinner.vue" ;
2020
21- let pollingFaster = false ;
22- const { autoRefresh, isRefreshing, updateInterval } = useStoreAutoRefresh (" deletedMessageGroups" , useDeletedMessageGroupsStore , 5000 );
21+ const POLLING_INTERVAL_NORMAL = 5000 ;
22+ const POLLING_INTERVAL_FAST = 1000 ;
23+
24+ const { autoRefresh, isRefreshing, updateInterval } = useStoreAutoRefresh (" deletedMessageGroups" , useDeletedMessageGroupsStore , POLLING_INTERVAL_NORMAL );
2325const { store } = autoRefresh ();
2426const { archiveGroups, classifiers, selectedClassifier } = storeToRefs (store );
2527const router = useRouter ();
@@ -50,8 +52,7 @@ async function restoreGroup() {
5052 useShowToast (TYPE .ERROR , " Error" , ` Failed to restore the group: ${errorMessage } ` );
5153 } else {
5254 // We're starting a restore, poll more frequently
53- pollingFaster = true ;
54- updateInterval (1000 );
55+ updateInterval (POLLING_INTERVAL_FAST );
5556 groupRestoreSuccessful .value = true ;
5657 useShowToast (TYPE .INFO , " Info" , " Group restore started..." );
5758 }
@@ -83,19 +84,17 @@ function navigateToGroup(groupId: string) {
8384 router .push (routeLinks .failedMessage .deletedGroup .link (groupId ));
8485}
8586
86- function isRestoreInProgress() {
87+ const isRestoreInProgress = computed (() => {
8788 return archiveGroups .value .some ((group ) => group .workflow_state .status !== " none" && group .workflow_state .status !== " restorecompleted" );
88- }
89+ });
8990
90- watch (isRefreshing , () => {
91- // If we're currently polling at 5 seconds and there is a restore in progress, then change the polling interval to poll every 1 second
92- if (! pollingFaster && isRestoreInProgress ()) {
93- pollingFaster = true ;
94- updateInterval (1000 );
95- } else if (pollingFaster && ! isRestoreInProgress ()) {
96- // if we're currently polling every 1 second and all restores are done, change polling frequency back to every 5 seconds
97- pollingFaster = false ;
98- updateInterval (5000 );
91+ watch (isRestoreInProgress , (restoreInProgress ) => {
92+ if (restoreInProgress ) {
93+ // If there is a restore in progress, poll every 1 second
94+ updateInterval (POLLING_INTERVAL_FAST );
95+ } else {
96+ // If all restores are done, change polling frequency back to every 5 seconds
97+ updateInterval (POLLING_INTERVAL_NORMAL );
9998 }
10099});
101100 </script >
0 commit comments