diff --git a/src/components/RoadmapAIChat/RoadmapTopicList.tsx b/src/components/RoadmapAIChat/RoadmapTopicList.tsx index 4fdb02eb6..ad4e9035f 100644 --- a/src/components/RoadmapAIChat/RoadmapTopicList.tsx +++ b/src/components/RoadmapAIChat/RoadmapTopicList.tsx @@ -1,7 +1,8 @@ import { useMutation, useQuery } from '@tanstack/react-query'; import { roadmapTreeMappingOptions } from '../../queries/roadmap-tree'; import { queryClient } from '../../stores/query-client'; -import { useMemo } from 'react'; +import { useMemo, useState } from 'react'; +import { TopicResourcesModal } from './TopicResourcesModal'; type TopicListType = { topicId: string; @@ -40,6 +41,7 @@ export function RoadmapTopicList(props: RoadmapTopicListProps) { const { roadmapId, content } = props; const topicListItems = parseTopicList(content); + const [selectedTopicId, setSelectedTopicId] = useState(null); const { data: roadmapTreeData } = useQuery( roadmapTreeMappingOptions(roadmapId), @@ -63,15 +65,26 @@ export function RoadmapTopicList(props: RoadmapTopicListProps) { }, [topicListItems, roadmapTreeData]); return ( -
- {progressItemWithText.map((item) => ( - - ))} -
+ <> + {selectedTopicId && ( + setSelectedTopicId(null)} + /> + )} + +
+ {progressItemWithText.map((item) => ( + + ))} +
+ ); } diff --git a/src/components/RoadmapAIChat/TopicResourcesModal.tsx b/src/components/RoadmapAIChat/TopicResourcesModal.tsx new file mode 100644 index 000000000..95bbe2ba4 --- /dev/null +++ b/src/components/RoadmapAIChat/TopicResourcesModal.tsx @@ -0,0 +1,57 @@ +import { useQuery } from '@tanstack/react-query'; +import { Modal } from '../Modal'; +import { roadmapTreeMappingOptions } from '../../queries/roadmap-tree'; +import { queryClient } from '../../stores/query-client'; +import { roadmapContentOptions } from '../../queries/roadmap'; +import { ModalLoader } from '../UserProgress/ModalLoader'; +import { TopicDetailLink } from '../TopicDetail/TopicDetailLink'; + +type TopicResourcesModalProps = { + roadmapId: string; + topicId: string; + onClose: () => void; +}; + +export function TopicResourcesModal(props: TopicResourcesModalProps) { + const { roadmapId, topicId, onClose } = props; + + const { + data: roadmapContentData, + isLoading: isLoadingRoadmapContent, + error, + } = useQuery(roadmapContentOptions(roadmapId), queryClient); + + const topicContent = roadmapContentData?.[topicId]; + const links = topicContent?.links || []; + + if (isLoadingRoadmapContent || error) { + return ( + + ); + } + + return ( + +
+

{topicContent?.title}

+
    + {links.map((link, index) => { + return ( +
  • + +
  • + ); + })} +
+
+
+ ); +} diff --git a/src/queries/roadmap.ts b/src/queries/roadmap.ts index 30c511026..de683a36f 100644 --- a/src/queries/roadmap.ts +++ b/src/queries/roadmap.ts @@ -19,6 +19,7 @@ export function roadmapJSONOptions(roadmapId: string) { svg, }; }, + refetchOnMount: false, }); } @@ -57,5 +58,40 @@ export function roadmapDetailsOptions(roadmapId: string) { return roadmapDetails; }, + refetchOnMount: false, + }); +} + +export const allowedLinkTypes = [ + 'video', + 'article', + 'opensource', + 'course', + 'website', + 'podcast', +] as const; +export type AllowedLinkTypes = (typeof allowedLinkTypes)[number]; + +export function roadmapContentOptions(roadmapId: string) { + return queryOptions({ + queryKey: ['roadmap-content', { roadmapId }], + queryFn: async () => { + const baseUrl = import.meta.env.PUBLIC_APP_URL; + return httpGet< + Record< + string, + { + title: string; + description: string; + links: { + title: string; + url: string; + type: AllowedLinkTypes; + }[]; + } + > + >(`${baseUrl}/roadmap-content/${roadmapId}.json`); + }, + refetchOnMount: false, }); }