mirror of
				https://github.com/lingble/chatwoot.git
				synced 2025-11-04 04:57:51 +00:00 
			
		
		
		
	<img width="989" alt="Screenshot 2025-02-05 at 6 34 12 PM" src="https://github.com/user-attachments/assets/ae811842-23f7-4bbc-8a42-7cbe4849d287" /> View heatmaps for last 30 days based on the filter.
		
			
				
	
	
		
			29 lines
		
	
	
		
			549 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
		
			549 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
import { ref, onBeforeUnmount } from 'vue';
 | 
						|
 | 
						|
export const useLiveRefresh = (callback, interval = 60000) => {
 | 
						|
  const timeoutId = ref(null);
 | 
						|
 | 
						|
  const startRefetching = () => {
 | 
						|
    timeoutId.value = setTimeout(async () => {
 | 
						|
      await callback();
 | 
						|
      startRefetching();
 | 
						|
    }, interval);
 | 
						|
  };
 | 
						|
 | 
						|
  const stopRefetching = () => {
 | 
						|
    if (timeoutId.value) {
 | 
						|
      clearTimeout(timeoutId.value);
 | 
						|
      timeoutId.value = null;
 | 
						|
    }
 | 
						|
  };
 | 
						|
 | 
						|
  onBeforeUnmount(() => {
 | 
						|
    stopRefetching();
 | 
						|
  });
 | 
						|
 | 
						|
  return {
 | 
						|
    startRefetching,
 | 
						|
    stopRefetching,
 | 
						|
  };
 | 
						|
};
 |