You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

use-share.ts 1.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { useQuery } from '@tanstack/react-query'
  2. import { fetchAppInfo, fetchAppMeta, fetchAppParams, getAppAccessModeByAppCode } from './share'
  3. const NAME_SPACE = 'webapp'
  4. export const useGetWebAppAccessModeByCode = (code: string | null) => {
  5. return useQuery({
  6. queryKey: [NAME_SPACE, 'appAccessMode', code],
  7. queryFn: () => {
  8. if (!code || code.length === 0)
  9. return Promise.reject(new Error('App code is required to get access mode'))
  10. return getAppAccessModeByAppCode(code)
  11. },
  12. enabled: !!code,
  13. })
  14. }
  15. export const useGetWebAppInfo = () => {
  16. return useQuery({
  17. queryKey: [NAME_SPACE, 'appInfo'],
  18. queryFn: () => {
  19. return fetchAppInfo()
  20. },
  21. })
  22. }
  23. export const useGetWebAppParams = () => {
  24. return useQuery({
  25. queryKey: [NAME_SPACE, 'appParams'],
  26. queryFn: () => {
  27. return fetchAppParams(false)
  28. },
  29. })
  30. }
  31. export const useGetWebAppMeta = () => {
  32. return useQuery({
  33. queryKey: [NAME_SPACE, 'appMeta'],
  34. queryFn: () => {
  35. return fetchAppMeta(false)
  36. },
  37. })
  38. }