File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
src/components/libresplit Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ import { AppLoading } from "./AppLoading" ;
2+ import { Markdown } from "@/lib/markdown" ;
3+ import { useQuery } from "@tanstack/react-query" ;
4+
5+ async function fetchMarkdown ( url : string ) : Promise < string > {
6+ const res = await fetch ( url ) ;
7+
8+ if ( ! res . ok ) {
9+ throw new Error ( "Failed to fetch markdown from GitHub." ) ;
10+ }
11+
12+ return res . text ( ) ;
13+ }
14+
15+ type AppGitHubGenericMarkdownProps = {
16+ url : string ;
17+ } ;
18+
19+ export function AppGitHubGenericMarkdown ( {
20+ url,
21+ } : AppGitHubGenericMarkdownProps ) {
22+ const { data, isLoading, error } = useQuery ( {
23+ queryKey : [ "markdown-text" ] ,
24+ queryFn : ( ) => fetchMarkdown ( url ) ,
25+ enabled : ! ! url ,
26+ } ) ;
27+
28+ if ( isLoading ) return < AppLoading /> ;
29+ if ( error ) return < div > Failed to fetch markdown from GitHub.</ div > ;
30+ if ( ! data ) return < div > Failed to fetch markdown from GitHub.</ div > ;
31+
32+ return (
33+ < div >
34+ < Markdown content = { data } />
35+ </ div >
36+ ) ;
37+ }
You can’t perform that action at this time.
0 commit comments