useTicketOverviews.ts 936 B

12345678910111213141516171819202122232425262728293031323334
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { useTimeoutFn } from '@vueuse/shared'
  3. import { onMounted } from 'vue'
  4. import { QueryHandler } from '#shared/server/apollo/handler/index.ts'
  5. import { useTicketOverviewTicketCountLazyQuery } from '../graphql/queries/ticketOverviewTicketCount.api.ts'
  6. import { useTicketOverviewsStore } from '../stores/ticketOverviews.ts'
  7. const POLLING_INTERVAL = 60000
  8. export const useTicketOverviews = () => {
  9. const overviews = useTicketOverviewsStore()
  10. const ticketOverviewTicketCountHandler = new QueryHandler(
  11. useTicketOverviewTicketCountLazyQuery({
  12. pollInterval: POLLING_INTERVAL,
  13. }),
  14. )
  15. onMounted(() => {
  16. if (!overviews.loading) {
  17. ticketOverviewTicketCountHandler.load()
  18. } else {
  19. useTimeoutFn(
  20. () => ticketOverviewTicketCountHandler.load(),
  21. POLLING_INTERVAL,
  22. )
  23. }
  24. })
  25. return overviews
  26. }