useApplyTemplate.ts 873 B

12345678910111213141516171819202122232425262728293031
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { storeToRefs } from 'pinia'
  3. import { onBeforeUnmount } from 'vue'
  4. import { useRoute } from 'vue-router'
  5. import { useTicketTemplateStore } from '../stores/ticketTemplate.ts'
  6. export const useApplyTemplate = () => {
  7. const templateStore = useTicketTemplateStore()
  8. const { templateList } = storeToRefs(templateStore)
  9. const { activate, deactivate } = templateStore
  10. const route = useRoute()
  11. // TODO: Drop this mechanism once Apollo implements an effective deduplication of subscriptions on the client level.
  12. // More information: https://github.com/apollographql/apollo-client/issues/10117
  13. const usageKey = route.meta.taskbarTabEntityKey ?? 'apply-template'
  14. activate(usageKey)
  15. onBeforeUnmount(() => {
  16. deactivate(usageKey)
  17. })
  18. return {
  19. templateList,
  20. }
  21. }