@@ -8,14 +8,15 @@ import {
88 Divider ,
99 Chip ,
1010 Image ,
11- Avatar
11+ Avatar ,
12+ Spinner
1213} from '@heroui/react'
1314import ReactMarkdown from 'react-markdown'
1415import { classIcon , roleIcon } from '@/utils/classIcon'
1516import remarkGfm from 'remark-gfm'
1617import rehypeRaw from 'rehype-raw'
1718import hljs from 'highlight.js'
18- import { useEffect } from 'react'
19+ import { useEffect , useState } from 'react'
1920import { GroupIcon } from '@/assets/Icons'
2021
2122interface ProfilesDetailsProps {
@@ -25,6 +26,34 @@ interface ProfilesDetailsProps {
2526}
2627
2728const ProfilesDetails = ( { data, isOpen, onOpenChange } : ProfilesDetailsProps ) => {
29+ const [ markdownContent , setMarkdownContent ] = useState < string | null > ( null )
30+ const [ isLoading , setIsLoading ] = useState ( false )
31+
32+ useEffect ( ( ) => {
33+ if ( isOpen && data . md ) {
34+ setIsLoading ( true )
35+ fetch ( data . md )
36+ . then ( ( response ) => {
37+ if ( ! response . ok ) {
38+ throw new Error ( 'Failed to fetch markdown content.' )
39+ }
40+ return response . text ( )
41+ } )
42+ . then ( ( data ) => {
43+ setMarkdownContent ( data )
44+ } )
45+ . catch ( ( error ) => {
46+ console . error ( 'Error fetching markdown content:' , error )
47+ setMarkdownContent ( 'Failed to load content.' )
48+ } )
49+ . finally ( ( ) => {
50+ setIsLoading ( false )
51+ } )
52+ } else {
53+ setMarkdownContent ( null )
54+ }
55+ } , [ isOpen , data . md ] )
56+
2857 useEffect ( ( ) => {
2958 document . querySelectorAll ( 'pre code' ) . forEach ( ( block ) => {
3059 hljs . highlightElement ( block as HTMLElement )
@@ -118,13 +147,17 @@ const ProfilesDetails = ({ data, isOpen, onOpenChange }: ProfilesDetailsProps) =
118147 < Divider className = "my-2" />
119148 < h2 className = "text-lg font-extrabold" > Description</ h2 >
120149 < article className = "markdown-body p-1 !bg-transparent" >
121- < ReactMarkdown
122- remarkPlugins = { [ remarkGfm ] }
123- rehypePlugins = { [ rehypeRaw ] }
124- className = "text-default-900 gap-4 w-auto p-4 mx-auto flex-col lg:flex-row rounded-md"
125- >
126- { data . md }
127- </ ReactMarkdown >
150+ { isLoading ? (
151+ < Spinner className = "items-center justify-center" />
152+ ) : (
153+ < ReactMarkdown
154+ remarkPlugins = { [ remarkGfm ] }
155+ rehypePlugins = { [ rehypeRaw ] }
156+ className = "text-default-900 gap-4 w-auto p-4 mx-auto flex-col lg:flex-row rounded-md"
157+ >
158+ { markdownContent || 'No content available.' }
159+ </ ReactMarkdown >
160+ ) }
128161 </ article >
129162 </ DrawerBody >
130163 < DrawerFooter >
0 commit comments