diff --git a/src/components/GenerateRoadmap/GenerateRoadmap.tsx b/src/components/GenerateRoadmap/GenerateRoadmap.tsx index 83fe9ee68..5fd09d65c 100644 --- a/src/components/GenerateRoadmap/GenerateRoadmap.tsx +++ b/src/components/GenerateRoadmap/GenerateRoadmap.tsx @@ -15,7 +15,7 @@ import { readAIRoadmapStream } from '../../helper/read-stream'; import { isLoggedIn, removeAuthToken, visitAIRoadmap } from '../../lib/jwt'; import { RoadmapSearch } from './RoadmapSearch.tsx'; import { Spinner } from '../ReactIcons/Spinner.tsx'; -import {Ban, Download, PenSquare, Save, Wand} from 'lucide-react'; +import { Ban, Download, PenSquare, Save, Wand } from 'lucide-react'; import { ShareRoadmapButton } from '../ShareRoadmapButton.tsx'; import { httpGet, httpPost } from '../../lib/http.ts'; import { pageProgressMessage } from '../../stores/page.ts'; @@ -29,6 +29,13 @@ import { showLoginPopup } from '../../lib/popup.ts'; import { cn } from '../../lib/classname.ts'; import { RoadmapTopicDetail } from './RoadmapTopicDetail.tsx'; +export type GetAIRoadmapLimitResponse = { + used: number; + limit: number; + topicUsed: number; + topicLimit: number; +}; + const ROADMAP_ID_REGEX = new RegExp('@ROADMAPID:(\\w+)@'); export type RoadmapNodeDetails = { @@ -84,6 +91,8 @@ export function GenerateRoadmap() { const [roadmapLimit, setRoadmapLimit] = useState(0); const [roadmapLimitUsed, setRoadmapLimitUsed] = useState(0); + const [roadmapTopicLimit, setRoadmapTopicLimit] = useState(0); + const [roadmapTopicLimitUsed, setRoadmapTopicLimitUsed] = useState(0); const renderRoadmap = async (roadmap: string) => { const { nodes, edges } = generateAIRoadmapFromText(roadmap); @@ -240,19 +249,20 @@ export function GenerateRoadmap() { }; const loadAIRoadmapLimit = async () => { - const { response, error } = await httpGet<{ - limit: number; - used: number; - }>(`${import.meta.env.PUBLIC_API_URL}/v1-get-ai-roadmap-limit`); + const { response, error } = await httpGet( + `${import.meta.env.PUBLIC_API_URL}/v1-get-ai-roadmap-limit`, + ); if (error || !response) { toast.error(error?.message || 'Something went wrong'); return; } - const { limit, used } = response; + const { limit, used, topicLimit, topicUsed } = response; setRoadmapLimit(limit); setRoadmapLimitUsed(used); + setRoadmapTopicLimit(topicLimit); + setRoadmapTopicLimitUsed(topicUsed); }; const loadAIRoadmap = async (roadmapId: string) => { @@ -360,6 +370,11 @@ export function GenerateRoadmap() { parentTitle={selectedTopic.parentTitle} onClose={() => setSelectedTopic(null)} roadmapId={currentRoadmap?.id || ''} + topicLimit={roadmapTopicLimit} + topicLimitUsed={roadmapTopicLimitUsed} + onTopicContentGenerateComplete={async () => { + await loadAIRoadmapLimit(); + }} /> )} @@ -393,10 +408,14 @@ export function GenerateRoadmap() { {!isLoggedIn() && ( )} @@ -472,12 +491,14 @@ export function GenerateRoadmap() { disabled={isLoading} > - Track your Progress on this Roadmap - Track Progress + + Track your Progress on this Roadmap + + Track Progress + )} + + {isLoading && ( -
+