Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

use-apps.ts 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { get, post } from './base'
  2. import type { App } from '@/types/app'
  3. import type { AppListResponse } from '@/models/app'
  4. import { useInvalid } from './use-base'
  5. import { useQuery } from '@tanstack/react-query'
  6. import type { GeneratorType } from '@/app/components/app/configuration/config/automatic/types'
  7. const NAME_SPACE = 'apps'
  8. // TODO paging for list
  9. const useAppFullListKey = [NAME_SPACE, 'full-list']
  10. export const useAppFullList = () => {
  11. return useQuery<AppListResponse>({
  12. queryKey: useAppFullListKey,
  13. queryFn: () => get<AppListResponse>('/apps', { params: { page: 1, limit: 100 } }),
  14. })
  15. }
  16. export const useInvalidateAppFullList = () => {
  17. return useInvalid(useAppFullListKey)
  18. }
  19. export const useAppDetail = (appID: string) => {
  20. return useQuery<App>({
  21. queryKey: [NAME_SPACE, 'detail', appID],
  22. queryFn: () => get<App>(`/apps/${appID}`),
  23. })
  24. }
  25. export const useGenerateRuleTemplate = (type: GeneratorType, disabled?: boolean) => {
  26. return useQuery({
  27. queryKey: [NAME_SPACE, 'generate-rule-template', type],
  28. queryFn: () => post<{ data: string }>('instruction-generate/template', {
  29. body: {
  30. type,
  31. },
  32. }),
  33. enabled: !disabled,
  34. retry: 0,
  35. })
  36. }