fix: roadmap topic details

fix/ai-roadmap
Arik Chakma 9 months ago
parent f561a52a46
commit 8488e00254
  1. 17
      src/components/GenerateRoadmap/GenerateRoadmap.tsx
  2. 6
      src/components/GenerateRoadmap/RoadmapTopicDetail.tsx

@ -281,12 +281,21 @@ export function GenerateRoadmap() {
setGeneratedRoadmapContent(data); setGeneratedRoadmapContent(data);
}; };
const handleSvgClick = useCallback( const handleNodeClick = useCallback(
(e: MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => { (e: MouseEvent<HTMLDivElement, globalThis.MouseEvent>) => {
if (isLoading) {
return;
}
const target = e.target as SVGElement; const target = e.target as SVGElement;
const { nodeId, nodeType, targetGroup, nodeTitle, parentTitle } = const { nodeId, nodeType, targetGroup, nodeTitle, parentTitle } =
getNodeDetails(target) || {}; getNodeDetails(target) || {};
if (!nodeId || !nodeType || !allowedClickableNodeTypes.includes(nodeType)) if (
!nodeId ||
!nodeType ||
!allowedClickableNodeTypes.includes(nodeType) ||
!nodeTitle
)
return; return;
if (nodeType === 'button' || nodeType === 'link-item') { if (nodeType === 'button' || nodeType === 'link-item') {
@ -307,7 +316,7 @@ export function GenerateRoadmap() {
...(nodeType === 'subtopic' && { parentTitle }), ...(nodeType === 'subtopic' && { parentTitle }),
}); });
}, },
[], [isLoading],
); );
useEffect(() => { useEffect(() => {
@ -465,7 +474,7 @@ export function GenerateRoadmap() {
<div <div
ref={roadmapContainerRef} ref={roadmapContainerRef}
id="roadmap-container" id="roadmap-container"
onClick={handleSvgClick} onClick={handleNodeClick}
className="relative px-4 py-5 [&>svg]:mx-auto [&>svg]:max-w-[1300px]" className="relative px-4 py-5 [&>svg]:mx-auto [&>svg]:max-w-[1300px]"
/> />
</section> </section>

@ -28,6 +28,12 @@ export function RoadmapTopicDetail(props: RoadmapTopicDetailProps) {
setIsLoading(true); setIsLoading(true);
setError(''); setError('');
if (!roadmapId || !nodeTitle) {
setIsLoading(false);
setError('Invalid roadmap id or node title');
return;
}
const response = await fetch( const response = await fetch(
`${import.meta.env.PUBLIC_API_URL}/v1-genereate-ai-roadmap-content/${roadmapId}`, `${import.meta.env.PUBLIC_API_URL}/v1-genereate-ai-roadmap-content/${roadmapId}`,
{ {

Loading…
Cancel
Save