useOnlineNotificationSeen.ts 741 B

1234567891011121314151617181920212223
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { watch } from 'vue'
  3. import { useOnlineNotificationSeenMutation } from '#shared/entities/online-notification/graphql/mutations/seen.api.ts'
  4. import { MutationHandler } from '#shared/server/apollo/handler/index.ts'
  5. import type { ObjectWithId } from '#shared/types/utils.ts'
  6. import type { Ref } from 'vue'
  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. }