diff --git a/src/components/GenerateRoadmap/GenerateRoadmap.tsx b/src/components/GenerateRoadmap/GenerateRoadmap.tsx index 5c0460c7d..bdb6c1c18 100644 --- a/src/components/GenerateRoadmap/GenerateRoadmap.tsx +++ b/src/components/GenerateRoadmap/GenerateRoadmap.tsx @@ -12,7 +12,7 @@ import { generateAIRoadmapFromText } from '../../../editor/utils/roadmap-generat import { renderFlowJSON } from '../../../editor/renderer/renderer'; import { replaceChildren } from '../../lib/dom'; import { readAIRoadmapStream } from '../../helper/read-stream'; -import { isLoggedIn, removeAuthToken } from '../../lib/jwt'; +import { isLoggedIn, removeAuthToken, visitAIRoadmap } from '../../lib/jwt'; import { RoadmapSearch } from './RoadmapSearch.tsx'; import { Spinner } from '../ReactIcons/Spinner.tsx'; import { Ban, Download, PenSquare, Wand } from 'lucide-react'; @@ -176,7 +176,7 @@ export function GenerateRoadmap() { setIsLoading(false); }; - const editGeneratedRoadmapContent = async () => { + const addToCustomRoadmap = async () => { if (!isLoggedIn()) { showLoginPopup(); return; @@ -188,23 +188,26 @@ export function GenerateRoadmap() { const { response, error } = await httpPost<{ roadmapId: string; - }>(`${import.meta.env.PUBLIC_API_URL}/v1-edit-ai-generated-roadmap`, { - title: roadmapTopic, - nodes: nodes.map((node) => ({ - ...node, - - // To reset the width and height of the node - // so that it can be calculated based on the content in the editor - width: undefined, - height: undefined, - style: { - ...node.style, + }>( + `${import.meta.env.PUBLIC_API_URL}/v1-edit-ai-generated-roadmap/${currentRoadmap?.id}`, + { + title: roadmapTopic, + nodes: nodes.map((node) => ({ + ...node, + + // To reset the width and height of the node + // so that it can be calculated based on the content in the editor width: undefined, height: undefined, - }, - })), - edges, - }); + style: { + ...node.style, + width: undefined, + height: undefined, + }, + })), + edges, + }, + ); if (error || !response) { toast.error(error?.message || 'Something went wrong'); @@ -215,10 +218,7 @@ export function GenerateRoadmap() { setIsLoading(false); pageProgressMessage.set(''); - window.open( - `${import.meta.env.PUBLIC_EDITOR_APP_URL}/${response.roadmapId}`, - '_blank', - ); + return response.roadmapId; }; const downloadGeneratedRoadmapContent = async () => { @@ -279,6 +279,7 @@ export function GenerateRoadmap() { }); setRoadmapTopic(topic); setGeneratedRoadmapContent(data); + visitAIRoadmap(roadmapId); }; const handleNodeClick = useCallback( @@ -372,7 +373,10 @@ export function GenerateRoadmap() { )} {!isLoading && (
-
+

+ AI Roadmap Generator +

+
)}
- + +
+ + + +
)} diff --git a/src/lib/jwt.ts b/src/lib/jwt.ts index 911c46312..b8fd57caf 100644 --- a/src/lib/jwt.ts +++ b/src/lib/jwt.ts @@ -48,3 +48,18 @@ export function removeAuthToken() { domain: import.meta.env.DEV ? 'localhost' : '.roadmap.sh', }); } + +export function visitAIRoadmap(roadmapId: string) { + const isAlreadyVisited = Number(Cookies.get(`crv-${roadmapId}`) || 0) === 1; + if (isAlreadyVisited) { + return; + } + + Cookies.set(`crv-${roadmapId}`, '1', { + path: '/', + expires: 30, + sameSite: 'lax', + secure: !import.meta.env.DEV, + domain: import.meta.env.DEV ? 'localhost' : '.roadmap.sh', + }); +}