Skip to content

Commit 7d3012b

Browse files
committed
Make isRestoreInProgress computed
1 parent 5a14215 commit 7d3012b

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

src/Frontend/src/components/failedmessages/DeletedMessageGroups.vue

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import { ref, watch } from "vue";
2+
import { ref, computed, watch } from "vue";
33
import { useRouter } from "vue-router";
44
import { useShowToast } from "../../composables/toast";
55
import NoData from "../NoData.vue";
@@ -18,8 +18,10 @@ import { useStoreAutoRefresh } from "@/composables/useAutoRefresh";
1818
import { storeToRefs } from "pinia";
1919
import 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);
2325
const { store } = autoRefresh();
2426
const { archiveGroups, classifiers, selectedClassifier } = storeToRefs(store);
2527
const 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

Comments
 (0)