@@ -23,6 +23,31 @@ import 'prismjs/components/prism-python';
23
23
import 'prismjs/components/prism-java' ;
24
24
import 'prismjs/components/prism-kotlin' ;
25
25
26
+ type LanguageOption = {
27
+ name : string ;
28
+ id : string ;
29
+ grammar : Grammar ;
30
+ }
31
+
32
+ const languagesDropdown : LanguageOption [ ] = [
33
+ { name : 'Auto-detect' , id : 'auto' , grammar : languages . plain } ,
34
+ { name : 'JavaScript' , id : 'javascript' , grammar : languages . javascript } ,
35
+ { name : 'TypeScript' , id : 'typescript' , grammar : languages . typescript } ,
36
+ { name : 'Java' , id : 'java' , grammar : languages . java } ,
37
+ { name : 'Kotlin' , id : 'kotlin' , grammar : languages . kotlin } ,
38
+ { name : 'Python' , id : 'python' , grammar : languages . python } ,
39
+ ] ;
40
+
41
+ const formats = [
42
+ { name : 'Auto-detect' , id : 'Auto-detect' } ,
43
+ { name : 'JSDoc' , id : 'JSDoc' } ,
44
+ { name : 'reST' , id : 'reST' } ,
45
+ { name : 'NumPy' , id : 'NumPy' } ,
46
+ { name : 'DocBlock' , id : 'DocBlock' } ,
47
+ { name : 'Javadoc' , id : 'Javadoc' } ,
48
+ { name : 'Google' , id : 'Google' } ,
49
+ ] ;
50
+
26
51
const ENDPOINT = process . env . NODE_ENV === 'development'
27
52
? 'http://localhost:5000'
28
53
: 'https://api.mintlify.com' ;
@@ -71,36 +96,42 @@ const footer = {
71
96
] ,
72
97
} ;
73
98
74
- type LanguageOption = {
75
- name : string ;
76
- id : string ;
77
- grammar : Grammar ;
78
- }
99
+ const classNames = ( ...classes : any ) => classes . filter ( Boolean ) . join ( ' ' ) ;
79
100
80
- const languagesDropdown : LanguageOption [ ] = [
81
- { name : 'Auto-detect' , id : 'auto' , grammar : languages . plain } ,
82
- { name : 'JavaScript' , id : 'javascript' , grammar : languages . javascript } ,
83
- { name : 'TypeScript' , id : 'typescript' , grammar : languages . typescript } ,
84
- { name : 'Java' , id : 'java' , grammar : languages . java } ,
85
- { name : 'Kotlin' , id : 'kotlin' , grammar : languages . kotlin } ,
86
- { name : 'Python' , id : 'python' , grammar : languages . python } ,
87
- ] ;
101
+ // Functions to check workers
102
+ const sleep = ( ms : number ) => new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
88
103
89
- const formats = [
90
- { name : 'Auto-detect' , id : 'Auto-detect' } ,
91
- { name : 'JSDoc' , id : 'JSDoc' } ,
92
- { name : 'reST' , id : 'reST' } ,
93
- { name : 'NumPy' , id : 'NumPy' } ,
94
- { name : 'DocBlock' , id : 'DocBlock' } ,
95
- { name : 'Javadoc' , id : 'Javadoc' } ,
96
- { name : 'Google' , id : 'Google' } ,
97
- ] ;
104
+ const WORKER_STATUS = ( id : string ) => `${ ENDPOINT } /docs/worker/${ id } ` ;
98
105
99
- function classNames ( ...classes : any ) {
100
- return classes . filter ( Boolean ) . join ( ' ' ) ;
101
- }
106
+ const checkWorkerStatus = async ( id : string ) : Promise < any > => {
107
+ const status = await axios . get ( WORKER_STATUS ( id ) ) ;
108
+ return status . data ;
109
+ } ;
110
+
111
+ export const monitorWorkerStatus = async ( id : string ) => {
112
+ let workerStatus = null ;
113
+ let millisecondsPassed = 0 ;
114
+ const intervalMs = 100 ;
115
+
116
+ while ( workerStatus == null && millisecondsPassed < 25000 ) {
117
+ // eslint-disable-next-line no-await-in-loop
118
+ const status = await checkWorkerStatus ( id ) ;
119
+ if ( status . state === 'completed' && status . data ) {
120
+ workerStatus = status . data ;
121
+ break ;
122
+ } else if ( status . state === 'failed' ) {
123
+ throw new Error ( 'Unable to generate documentation' ) ;
124
+ }
125
+
126
+ millisecondsPassed += intervalMs ;
127
+ // eslint-disable-next-line no-await-in-loop
128
+ await sleep ( intervalMs ) ;
129
+ }
130
+
131
+ return workerStatus ;
132
+ } ;
102
133
103
- export default function Example ( ) {
134
+ export default function App ( ) {
104
135
const [ code , setCode ] = useState ( '' ) ;
105
136
const [ outputDisplay , setOutputDisplay ] = useState ( '' ) ;
106
137
const [ lastExampleId , setLastExampleId ] = useState ( '' ) ;
@@ -167,7 +198,7 @@ export default function Example() {
167
198
setOutputDisplay ( '' ) ;
168
199
169
200
try {
170
- const { data : { docstring } } : { data : { docstring : string } } = await axios . post ( `${ ENDPOINT } /web /write` , {
201
+ const { data : { id } } : { data : { id : string } } = await axios . post ( `${ ENDPOINT } /docs /write/v3 ` , {
171
202
code,
172
203
languageId : selectedLanguage . id ,
173
204
commented : commentsEnabled ,
@@ -177,6 +208,7 @@ export default function Example() {
177
208
source : 'web' ,
178
209
} ) ;
179
210
211
+ const { docstring } = await monitorWorkerStatus ( id ) ;
180
212
setOutputDisplay ( docstring ) ;
181
213
} catch ( error : any ) {
182
214
const errorMessage = error ?. response ?. data ?. error || 'An enexpected error occurred' ;
0 commit comments