feat/ai-rdm-slug
Arik Chakma 7 months ago
parent ed99d97468
commit b6a6d6394b
  1. 19
      src/api/ai-roadmap.ts
  2. 13
      src/components/GenerateRoadmap/GenerateRoadmap.tsx
  3. 29
      src/pages/ai/[aiRoadmapSlug]/index.astro

@ -0,0 +1,19 @@
import { type APIContext } from 'astro';
import { api } from './api.ts';
export type GetAIRoadmapBySlugResponse = {
id: string;
term: string;
title: string;
data: string;
};
export function aiRoadmapApi(context: APIContext) {
return {
getAIRoadmapBySlug: async function (roadmapSlug: string) {
return api(context).get<GetAIRoadmapBySlugResponse>(
`${import.meta.env.PUBLIC_API_URL}/v1-get-ai-roadmap-by-slug/${roadmapSlug}`,
);
},
};
}

@ -87,16 +87,21 @@ type GetAIRoadmapResponse = {
data: string; data: string;
}; };
export function GenerateRoadmap() { type GenerateRoadmapProps = {
roadmapId?: string;
};
export function GenerateRoadmap(props: GenerateRoadmapProps) {
const { roadmapId } = props;
const roadmapContainerRef = useRef<HTMLDivElement>(null); const roadmapContainerRef = useRef<HTMLDivElement>(null);
const { id: roadmapId, rc: referralCode } = getUrlParams() as { const { rc: referralCode } = getUrlParams() as {
id: string;
rc?: string; rc?: string;
}; };
const toast = useToast(); const toast = useToast();
const [hasSubmitted, setHasSubmitted] = useState<boolean>(false); const [hasSubmitted, setHasSubmitted] = useState<boolean>(Boolean(roadmapId));
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [isLoadingResults, setIsLoadingResults] = useState(false); const [isLoadingResults, setIsLoadingResults] = useState(false);
const [roadmapTerm, setRoadmapTerm] = useState(''); const [roadmapTerm, setRoadmapTerm] = useState('');

@ -0,0 +1,29 @@
---
import { aiRoadmapApi } from '../../../api/ai-roadmap';
import BaseLayout from '../../../layouts/BaseLayout.astro';
import { GenerateRoadmap } from '../../../components/GenerateRoadmap/GenerateRoadmap';
export const prerender = false;
interface Params extends Record<string, string | undefined> {
aiRoadmapSlug: string;
}
const { aiRoadmapSlug } = Astro.params as Params;
if (!aiRoadmapSlug) {
return Astro.redirect('/404');
}
const aiRoadmapClient = aiRoadmapApi(Astro as any);
const { response: roadmap, error } =
await aiRoadmapClient.getAIRoadmapBySlug(aiRoadmapSlug);
let errorMessage = '';
if (error || !roadmap) {
errorMessage = error?.message || 'Error loading AI Roadmap';
}
---
<BaseLayout title='Roadmap AI'>
<GenerateRoadmap roadmapId={roadmap?.id} client:load />
</BaseLayout>
Loading…
Cancel
Save