useOnlineNotificationList.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { computed } from 'vue'
  3. import { useOnlineNotificationsQuery } from '#shared/entities/online-notification/graphql/queries/onlineNotifications.api.ts'
  4. import type { OnlineNotification } from '#shared/graphql/types.ts'
  5. import { QueryHandler } from '#shared/server/apollo/handler/index.ts'
  6. import { edgesToArray } from '#shared/utils/helpers.ts'
  7. export const useOnlineNotificationList = () => {
  8. const notificationsQuery = new QueryHandler(useOnlineNotificationsQuery())
  9. const loading = notificationsQuery.loading()
  10. const result = notificationsQuery.result()
  11. const notificationList = computed(
  12. () =>
  13. edgesToArray(result.value?.onlineNotifications) as OnlineNotification[],
  14. )
  15. const isLoading = computed(() => {
  16. if (result.value !== undefined) return false
  17. return loading.value
  18. })
  19. const hasUnseenNotification = computed(() =>
  20. notificationList.value.some((notification) => !notification.seen),
  21. )
  22. const refetch = () => notificationsQuery.refetch()
  23. return {
  24. notificationList,
  25. hasUnseenNotification,
  26. refetch,
  27. loading: isLoading,
  28. }
  29. }