|
|
|
@ -1,6 +1,6 @@ |
|
|
|
|
import { useQuery } from '@tanstack/react-query'; |
|
|
|
|
import type { GetRoadmapResponse } from '../components/CustomRoadmap/CustomRoadmap'; |
|
|
|
|
import { httpGet, type FetchError } from '../lib/query-http'; |
|
|
|
|
import { httpGet, FetchError } from '../lib/query-http'; |
|
|
|
|
import { queryClient } from '../stores/query-client'; |
|
|
|
|
|
|
|
|
|
type UseCustomRoadmapOptions = { |
|
|
|
@ -22,17 +22,25 @@ export function useCustomRoadmap(options: UseCustomRoadmapOptions) { |
|
|
|
|
}, |
|
|
|
|
], |
|
|
|
|
queryFn: async () => { |
|
|
|
|
const roadmapUrl = slug |
|
|
|
|
? new URL( |
|
|
|
|
`${import.meta.env.PUBLIC_API_URL}/v1-get-roadmap-by-slug/${slug}`, |
|
|
|
|
) |
|
|
|
|
: new URL(`${import.meta.env.PUBLIC_API_URL}/v1-get-roadmap/${id}`); |
|
|
|
|
try { |
|
|
|
|
const roadmapUrl = slug |
|
|
|
|
? new URL( |
|
|
|
|
`${import.meta.env.PUBLIC_API_URL}/v1-get-roadmap-by-slug/${slug}`, |
|
|
|
|
) |
|
|
|
|
: new URL(`${import.meta.env.PUBLIC_API_URL}/v1-get-roadmap/${id}`); |
|
|
|
|
|
|
|
|
|
if (secret) { |
|
|
|
|
roadmapUrl.searchParams.set('secret', secret); |
|
|
|
|
} |
|
|
|
|
if (secret) { |
|
|
|
|
roadmapUrl.searchParams.set('secret', secret); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return await httpGet<GetRoadmapResponse>(roadmapUrl.toString()); |
|
|
|
|
} catch (error) { |
|
|
|
|
if (error instanceof SyntaxError) { |
|
|
|
|
throw new FetchError(404, 'Roadmap not found'); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return httpGet(roadmapUrl.toString()); |
|
|
|
|
throw error; |
|
|
|
|
} |
|
|
|
|
}, |
|
|
|
|
retry: false, |
|
|
|
|
enabled: !!(slug || id), |
|
|
|
|