@@ -18,22 +18,50 @@ const Draft = (): JSX.Element => {
1818 const draftedDocument = appStateContext ?. state . draftedDocument
1919 const sections = draftedDocument ?. sections ?? [ ]
2020
21+ const isLoadedSections = appStateContext ?. state . isLoadedSections
22+
23+
2124 const [ sectionItems , setSectionItems ] = useState < Section [ ] > ( [ ] )
2225 const aiWarningLabel = 'AI-generated content may be incorrect'
2326
27+
28+ const [ isExportButtonDisable , setIsExportButtonDisable ] = useState < boolean > ( false )
29+
30+
31+
2432 // redirect to home page if draftedDocument is empty
2533
34+
35+
2636 useEffect ( ( ) => {
37+
2738 sections . forEach ( ( item , index ) => {
2839 setTimeout ( ( ) => {
2940 setSectionItems ( ( prev ) => [ ...prev , item ] ) ;
3041 } , index * 500 ) ;
3142 } ) ;
43+
44+ //appStateContext?.dispatch({ type: 'UPDATE_IS_LOADED_SECTIONS', payload: {section : null, 'act': 'removeAll' } })
45+
3246 } , [ ] ) ;
3347
3448 useEffect ( ( ) => {
35- console . log ( "sectionItems" , sectionItems )
36- } , [ sectionItems ] )
49+ if ( isLoadedSections ?. length === sections . length )
50+ {
51+ setIsExportButtonDisable ( false ) ;
52+ }
53+ else {
54+ setIsExportButtonDisable ( true ) ;
55+ }
56+
57+ } , [ isLoadedSections ] )
58+
59+
60+ useEffect ( ( ) => {
61+ console . log ( "is loaded?" , isLoadedSections )
62+
63+ console . log ( "sectionItems" , sectionItems )
64+ } , [ sectionItems , isLoadedSections ] )
3765
3866 if ( ! draftedDocument ) {
3967 navigate ( '/' )
@@ -113,6 +141,35 @@ const Draft = (): JSX.Element => {
113141 return title . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '' )
114142 }
115143
144+ // const handleLoadingChange = (isSectionLoading: boolean) => {
145+ // setLoadingCount((prev) => {
146+ // const newCount = isSectionLoading ? prev + 1 : prev - 1
147+ // return newCount
148+ // })
149+ // }
150+ // useEffect(() => {
151+ // const failedSections = appStateContext?.state?.failedSections ?? []
152+ // if (failedSections.length > 0) {
153+
154+ // setTimeout(() => {
155+ // setIsFailLoading(true);
156+ // }, 5000);
157+
158+ // if(failedSections.length>1)
159+ // {
160+ // setTimeout(() => {
161+ // setLoadingCount(0)
162+ // },5000);
163+ // }
164+ // }
165+ // else
166+ // {
167+ // setTimeout(() => {
168+ // setIsFailLoading(false)
169+ // }, 5000);
170+ // }
171+ // }, [appStateContext?.state?.failedSections])
172+
116173 return (
117174 < Stack className = { styles . container } >
118175 < TitleCard />
@@ -142,6 +199,7 @@ const Draft = (): JSX.Element => {
142199 onClick = { exportToWord }
143200 aria-label = "export document"
144201 text = "Export Document"
202+ disabled = { isExportButtonDisable }
145203 />
146204 </ Stack >
147205 </ Stack >
0 commit comments