useTicketArticlesVariables.ts 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { computed } from 'vue'
  3. import { useApplicationStore } from '#shared/stores/application.ts'
  4. const ticketArticlesLoaded = new Set<string>()
  5. export const clearTicketArticlesLoadedState = () => {
  6. ticketArticlesLoaded.clear()
  7. }
  8. export const useTicketArticlesQueryVariables = () => {
  9. const application = useApplicationStore()
  10. const ticketArticlesMin = computed(() => {
  11. return Number(application.config.ticket_articles_min ?? 5)
  12. })
  13. const getTicketArticlesQueryVariables = (ticketId: string) => {
  14. if (ticketArticlesLoaded.has(ticketId)) {
  15. return {
  16. ticketId,
  17. loadDescription: false,
  18. pageSize: null,
  19. }
  20. }
  21. return {
  22. ticketId,
  23. pageSize: ticketArticlesMin.value,
  24. }
  25. }
  26. const markTicketArticlesLoaded = (ticketId: string) => {
  27. ticketArticlesLoaded.add(ticketId)
  28. }
  29. const allTicketArticlesLoaded = (ticketId: string) =>
  30. ticketArticlesLoaded.has(ticketId)
  31. return {
  32. ticketArticlesMin,
  33. allTicketArticlesLoaded,
  34. markTicketArticlesLoaded,
  35. getTicketArticlesQueryVariables,
  36. }
  37. }