@@ -111,7 +111,7 @@ const useStyles = makeStyles({
111111 }
112112} )
113113
114- const SectionCard = ( { sectionIdx } : SectionCardProps ) => {
114+ const SectionCard = ( { sectionIdx } : SectionCardProps ) => {
115115 const location = useLocation ( )
116116 const classes = useStyles ( )
117117 const [ isLoading , setIsLoading ] = useState ( false )
@@ -141,7 +141,6 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
141141
142142 useEffect ( ( ) => {
143143 if ( appStateContext . state ?. failedSections . length > 0 && appStateContext . state ?. failedSections [ 0 ] . title === sectionTitle && isLoading && ! appStateContext . state . isFailedReqInitiated ) {
144- console . log ( "appStateContext.state?.failedSections" , appStateContext . state ?. failedSections ) ;
145144 const tempItem = {
146145 title : sectionTitle ,
147146 description : sectionDescription ,
@@ -157,13 +156,13 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
157156
158157 async function fetchSectionContent ( sectionTitle : string , sectionDescription : string , isReqFrom = '' ) {
159158 setIsLoading ( true )
159+
160160 const sectionGenerateRequest : SectionGenerateRequest = { sectionTitle, sectionDescription }
161161
162162 const response = await sectionGenerate ( sectionGenerateRequest )
163163 const responseBody = await response . json ( )
164164
165165 if ( responseBody ?. error ?. includes ( "429" ) ) {
166- console . log ( "retriggerd !!!" )
167166 const failedSectionItems = {
168167 title : sectionTitle ,
169168 description : sectionDescription ,
@@ -192,9 +191,11 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
192191
193192 setCharCount ( content . length )
194193 setIsLoading ( false )
195-
196194 appStateContext ?. dispatch ( { type : 'REMOVED_FAILED_SECTION' , payload : { section : updatedSection } } )
197195
196+ appStateContext ?. dispatch ( { type : 'UPDATE_IS_LOADED_SECTIONS' , payload : { section : updatedSection } } )
197+
198+
198199 if ( isReqFrom == 'failed' )
199200 appStateContext ?. dispatch ( { type : 'UPDATE_SECTION_API_REQ_STATUS' , payload : false } )
200201 }
@@ -207,6 +208,11 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
207208 useEffect ( ( ) => {
208209 if ( sectionContent === '' && ! isLoading && ! isManuallyCleared ) {
209210 fetchSectionContent ( sectionTitle , sectionDescription )
211+ } else {
212+ if ( sectionContent != '' && ! isLoading ) {
213+ const updatedSection : Section = { ...section }
214+ appStateContext ?. dispatch ( { type : 'UPDATE_IS_LOADED_SECTIONS' , payload : { section : updatedSection } } )
215+ }
210216 }
211217 } , [ sectionContent , isLoading , isManuallyCleared ] )
212218
@@ -256,6 +262,7 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
256262 console . error ( 'Section description is empty' )
257263 return
258264 }
265+ appStateContext ?. dispatch ( { type : 'UPDATE_IS_LOADED_SECTIONS' , payload : { section : null , 'title' : sectionTitle , 'act' :'removeItem' } } )
259266
260267 setIsPopoverOpen ( false )
261268 fetchSectionContent ( sectionTitle , updatedSectionDescription )
0 commit comments