useArticleContext.ts 738 B

123456789101112131415161718192021222324
  1. // Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. import { type ComputedRef, inject, type InjectionKey } from 'vue'
  3. import type {
  4. TicketArticlesQuery,
  5. TicketArticlesQueryVariables,
  6. } from '#shared/graphql/types.ts'
  7. import type { QueryHandler } from '#shared/server/apollo/handler/index.ts'
  8. export type ArticleContext = {
  9. articles: ComputedRef<TicketArticlesQuery | undefined>
  10. articlesQuery: QueryHandler<TicketArticlesQuery, TicketArticlesQueryVariables>
  11. }
  12. export const ARTICLES_INFORMATION_KEY = Symbol(
  13. 'article-context-key',
  14. ) as InjectionKey<ArticleContext>
  15. export const useArticleContext = () => {
  16. const context = inject(ARTICLES_INFORMATION_KEY) as ArticleContext
  17. return { context }
  18. }