@@ -9,14 +9,15 @@ import {
99 Chip ,
1010 Link ,
1111 Image ,
12- Avatar
12+ Avatar ,
13+ Spinner
1314} from '@heroui/react'
1415import ReactMarkdown from 'react-markdown'
1516import { classIcon , roleIcon } from '@/utils/classIcon'
1617import remarkGfm from 'remark-gfm'
1718import rehypeRaw from 'rehype-raw'
1819import hljs from 'highlight.js'
19- import { useEffect } from 'react'
20+ import { useEffect , useState } from 'react'
2021import { GroupIcon } from '@/assets/Icons'
2122interface AddonsDetailsProps {
2223 addon : any
@@ -25,6 +26,34 @@ interface AddonsDetailsProps {
2526}
2627
2728const AddonsDetails = ( { addon, isOpen, onOpenChange } : AddonsDetailsProps ) => {
29+ const [ markdownContent , setMarkdownContent ] = useState < string | null > ( null )
30+ const [ isLoading , setIsLoading ] = useState ( false )
31+
32+ useEffect ( ( ) => {
33+ if ( isOpen && addon . md ) {
34+ setIsLoading ( true )
35+ fetch ( addon . 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 , addon . md ] )
56+
2857 useEffect ( ( ) => {
2958 document . querySelectorAll ( 'pre code' ) . forEach ( ( block ) => {
3059 hljs . highlightElement ( block as HTMLElement )
@@ -120,13 +149,17 @@ const AddonsDetails = ({ addon, isOpen, onOpenChange }: AddonsDetailsProps) => {
120149 < Divider className = "my-2" />
121150 < h1 className = "text-lg font-extrabold" > Description</ h1 >
122151 < article className = "markdown-body p-1 !bg-transparent" >
123- < ReactMarkdown
124- remarkPlugins = { [ remarkGfm ] }
125- rehypePlugins = { [ rehypeRaw ] }
126- className = "text-default-900 gap-4 w-auto p-4 mx-auto flex-col lg:flex-row rounded-md"
127- >
128- { addon . md }
129- </ ReactMarkdown >
152+ { isLoading ? (
153+ < Spinner className = "items-center justify-center" />
154+ ) : (
155+ < ReactMarkdown
156+ remarkPlugins = { [ remarkGfm ] }
157+ rehypePlugins = { [ rehypeRaw ] }
158+ className = "text-default-900 gap-4 w-auto p-4 mx-auto flex-col lg:flex-row rounded-md"
159+ >
160+ { markdownContent || 'No content available.' }
161+ </ ReactMarkdown >
162+ ) }
130163 </ article >
131164 </ DrawerBody >
132165 < DrawerFooter >
0 commit comments