11<script setup lang="ts">
2- import { onMounted , ref , useTemplateRef , watch } from " vue" ;
2+ import { computed , onMounted , ref , useTemplateRef , watch } from " vue" ;
33import { useShowToast } from " ../../composables/toast" ;
44import { downloadFileFromString } from " ../../composables/fileDownloadCreator" ;
55import { onBeforeRouteLeave } from " vue-router" ;
@@ -22,14 +22,16 @@ import { useStoreAutoRefresh } from "@/composables/useAutoRefresh";
2222import { storeToRefs } from " pinia" ;
2323import LoadingSpinner from " ../LoadingSpinner.vue" ;
2424
25+ const POLLING_INTERVAL_NORMAL = 5000 ;
26+ const POLLING_INTERVAL_FAST = 1000 ;
27+
2528const messageStore = useMessageStore ();
2629const messageGroupClient = createMessageGroupClient ();
2730const loading = ref (false );
28- const { autoRefresh, isRefreshing, updateInterval } = useStoreAutoRefresh (" messagesStore" , useMessagesStore , 5000 );
31+ const { autoRefresh, isRefreshing, updateInterval } = useStoreAutoRefresh (" messagesStore" , useMessagesStore , POLLING_INTERVAL_NORMAL );
2932const { store } = autoRefresh ();
3033const { messages, groupId, groupName, totalCount, pageNumber } = storeToRefs (store );
3134
32- let pollingFaster = false ;
3335const showDelete = ref (false );
3436const showConfirmRetryAll = ref (false );
3537const showConfirmDeleteAll = ref (false );
@@ -55,8 +57,7 @@ async function sortGroups(sort: SortOptions<GroupOperation>) {
5557
5658async function retryRequested(id : string ) {
5759 // We're starting a retry, poll more frequently
58- pollingFaster = true ;
59- updateInterval (1000 );
60+ updateInterval (POLLING_INTERVAL_FAST );
6061 useShowToast (TYPE .INFO , " Info" , " Message retry requested..." );
6162 await messageStore .retryMessages ([id ]);
6263 const message = messages .value .find ((m ) => m .id === id );
@@ -68,8 +69,7 @@ async function retryRequested(id: string) {
6869
6970async function retrySelected() {
7071 // We're starting a retry, poll more frequently
71- pollingFaster = true ;
72- updateInterval (1000 );
72+ updateInterval (POLLING_INTERVAL_FAST );
7373 const selectedMessages = messageList .value ?.getSelectedMessages () ?? [];
7474 useShowToast (TYPE .INFO , " Info" , " Retrying " + selectedMessages .length + " messages..." );
7575 await messageStore .retryMessages (selectedMessages .map ((m ) => m .id ));
@@ -153,8 +153,7 @@ function isAnythingSelected() {
153153
154154async function deleteSelectedMessages() {
155155 // We're starting a delete, poll more frequently
156- pollingFaster = true ;
157- updateInterval (1000 );
156+ updateInterval (POLLING_INTERVAL_FAST );
158157 const selectedMessages = messageList .value ?.getSelectedMessages () ?? [];
159158
160159 useShowToast (TYPE .INFO , " Info" , " Deleting " + selectedMessages .length + " messages..." );
@@ -175,26 +174,19 @@ async function deleteGroup() {
175174 messages .value .forEach ((m ) => (m .deleteInProgress = true ));
176175}
177176
178- function isRetryOrDeleteOperationInProgress() {
179- return messages .value .some ((message ) => {
180- return message .retryInProgress || message .deleteInProgress ;
181- });
182- }
183-
184177onBeforeRouteLeave (() => {
185178 groupId .value = " " ;
186179 groupName .value = " " ;
187180});
188181
189- watch (isRefreshing , () => {
190- // If we're currently polling at 5 seconds and there is a retry or delete in progress, then change the polling interval to poll every 1 second
191- if (! pollingFaster && isRetryOrDeleteOperationInProgress ()) {
192- pollingFaster = true ;
193- updateInterval (1000 );
194- } else if (pollingFaster && ! isRetryOrDeleteOperationInProgress ()) {
195- // if we're currently polling every 1 second but all retries or deletes are done, change polling frequency back to every 5 seconds
196- pollingFaster = false ;
197- updateInterval (5000 );
182+ const isRetryOrDeleteOperationInProgress = computed (() => messages .value .some ((message ) => message .retryInProgress || message .deleteInProgress ));
183+ watch (isRetryOrDeleteOperationInProgress , (retryOrDeleteOperationInProgress ) => {
184+ // If there is a retry or delete in progress, then change the polling interval to poll every 1 second
185+ if (retryOrDeleteOperationInProgress ) {
186+ updateInterval (POLLING_INTERVAL_FAST );
187+ } else {
188+ // if all retries or deletes are done, change polling frequency back to every 5 seconds
189+ updateInterval (POLLING_INTERVAL_NORMAL );
198190 }
199191});
200192
0 commit comments