useOnlineNotificationSeen.ts 739 B

123456789101112131415161718192021
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import type { Ref } from 'vue'
  3. import { watch } from 'vue'
  4. import { useOnlineNotificationSeenMutation } from '#shared/entities/online-notification/graphql/mutations/seen.api.ts'
  5. import { MutationHandler } from '#shared/server/apollo/handler/index.ts'
  6. import type { ObjectWithId } from '#shared/types/utils.ts'
  7. export const useOnlineNotificationSeen = (
  8. object: Ref<ObjectWithId | undefined>,
  9. ) => {
  10. const seenMutation = new MutationHandler(useOnlineNotificationSeenMutation())
  11. const setAsSeen = async () => {
  12. if (!object.value?.id) return
  13. await seenMutation.send({ objectId: object.value.id })
  14. }
  15. watch(() => object.value?.id, setAsSeen)
  16. }