Skip to content

Commit ff584d6

Browse files
commit disable fixes
1 parent 773a704 commit ff584d6

File tree

10 files changed

+106
-5
lines changed

10 files changed

+106
-5
lines changed

src/frontend/src/components/ChatHistory/ChatHistoryList.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const mockState = {
2828
failedSections : [],
2929
isFailedReqInitiated : false,
3030
isLoading : false,
31+
isLoadedSections : []
3132
};
3233

3334
const renderChatHistoryList = (stateOverride = {}) => {

src/frontend/src/components/ChatHistory/ChatHistoryPanel.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const mockState = {
5555
failedSections : [],
5656
isFailedReqInitiated : false,
5757
isLoading : false,
58+
isLoadedSections: []
5859
};
5960

6061
const mockDispatch = jest.fn();

src/frontend/src/components/DraftCards/SectionCard.test.tsx

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ const mockState = {
5757
failedSections : [],
5858
isFailedReqInitiated : false,
5959
isLoading : false,
60+
isLoadedSections: []
6061
}
6162

6263
const renderWithContext = (idx = 0) =>
@@ -210,4 +211,20 @@ describe('SectionCard Component', () => {
210211
}
211212
})
212213
})
214+
//////
215+
it('displays pre-filled section content', async () => {
216+
mockState.draftedDocument.sections[0].content = 'Pre-filled content'
217+
218+
renderWithContext()
219+
220+
await waitFor(() => {
221+
expect(screen.getByText('Pre-filled content')).toBeInTheDocument()
222+
expect(sectionGenerate).not.toHaveBeenCalled()
223+
})
224+
})
225+
226+
////
227+
228+
229+
213230
})

src/frontend/src/components/DraftCards/SectionCard.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useLocation } from 'react-router-dom'
1212

1313
interface SectionCardProps {
1414
sectionIdx: number
15+
// onLoadingChange: (isLoading: boolean) => void
1516
}
1617

1718
const useStyles = makeStyles({
@@ -111,7 +112,7 @@ const useStyles = makeStyles({
111112
}
112113
})
113114

114-
const SectionCard = ({ sectionIdx }: SectionCardProps) => {
115+
const SectionCard = ({ sectionIdx }: SectionCardProps) => {
115116
const location = useLocation()
116117
const classes = useStyles()
117118
const [isLoading, setIsLoading] = useState(false)
@@ -157,6 +158,7 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
157158

158159
async function fetchSectionContent(sectionTitle: string, sectionDescription: string , isReqFrom = '') {
159160
setIsLoading(true)
161+
//onLoadingChange(true)
160162
const sectionGenerateRequest: SectionGenerateRequest = { sectionTitle, sectionDescription }
161163

162164
const response = await sectionGenerate(sectionGenerateRequest)
@@ -192,9 +194,12 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
192194

193195
setCharCount(content.length)
194196
setIsLoading(false)
195-
197+
//onLoadingChange(false)
196198
appStateContext?.dispatch({ type: 'REMOVED_FAILED_SECTION', payload: {section : updatedSection} })
197199

200+
appStateContext?.dispatch({ type: 'UPDATE_IS_LOADED_SECTIONS', payload: {section : updatedSection} })
201+
202+
198203
if(isReqFrom == 'failed')
199204
appStateContext?.dispatch({ type: 'UPDATE_SECTION_API_REQ_STATUS', payload: false })
200205
}

src/frontend/src/components/Sidebar/Sidebar.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const mockState = {
5555
failedSections : [],
5656
isFailedReqInitiated : false,
5757
isLoading : false,
58+
isLoadedSections : []
5859
};
5960
const mockState2 = {
6061
isChatHistoryOpen: false,

src/frontend/src/pages/draft/Draft.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,5 @@ describe('Draft Component', () => {
175175
expect(screen.getByDisplayValue('Sample Draft')).toBeInTheDocument()
176176
})
177177

178+
178179
})

src/frontend/src/pages/draft/Draft.tsx

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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-zA-Z0-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>

src/frontend/src/state/AppProvider.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export interface AppState {
3434
failedSections : Section[],
3535
isFailedReqInitiated : boolean,
3636
isLoading: boolean,
37+
isLoadedSections: Section[]
3738
}
3839

3940
export type Action =
@@ -66,7 +67,8 @@ export type Action =
6667
| { type: 'REMOVED_FAILED_SECTION'; payload: {section : Section} }
6768
| { type: 'UPDATE_SECTION_API_REQ_STATUS'; payload: boolean }
6869
| { type: 'SET_LOADING'; payload: boolean }
69-
70+
| { type: 'UPDATE_IS_LOADED_SECTIONS'; payload: {section : Section | null ,'act'?: string} }
71+
7072
const initialState: AppState = {
7173
isChatHistoryOpen: false,
7274
chatHistoryLoadingState: ChatHistoryLoadingState.Loading,
@@ -88,6 +90,8 @@ const initialState: AppState = {
8890
failedSections : [],
8991
isFailedReqInitiated : false,
9092
isLoading: false,
93+
isLoadedSections: []
94+
9195
}
9296

9397
export const AppStateContext = createContext<

src/frontend/src/state/AppReducer.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,18 @@ export const appStateReducer = (state: AppState, action: Action): AppState => {
119119
return { ...state , failedSections : [...tempFailedSections] }
120120
case 'UPDATE_SECTION_API_REQ_STATUS' :
121121
return {...state, isFailedReqInitiated : action.payload}
122+
123+
case 'UPDATE_IS_LOADED_SECTIONS' :
124+
let tempLoadedSection:any = [];
125+
if(action.payload.act === 'removeAll')
126+
{
127+
tempLoadedSection = [];
128+
}else
129+
{
130+
tempLoadedSection = [...state.isLoadedSections];
131+
tempLoadedSection.push(action.payload.section)
132+
}
133+
return {...state, isLoadedSections: tempLoadedSection}
122134

123135
default:
124136
return state

src/frontend/src/test/test.utils.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const defaultMockState = {
2222
failedSections : [],
2323
isFailedReqInitiated : false,
2424
isLoading : false,
25+
isLoadedSections : []
2526
};
2627

2728
// Create a custom render function

0 commit comments

Comments
 (0)