Skip to content

Commit 7e51c47

Browse files
authored
Merge pull request #55 from microsoft/adesousa_microsoft/fix-empty-content-bug
fix update section content bug and character limit issue
2 parents 418a8d1 + 709bfbe commit 7e51c47

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

frontend/src/components/DraftCards/SectionCard.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
116116
const [isPopoverOpen, setIsPopoverOpen] = useState(false)
117117
const appStateContext = useContext(AppStateContext)
118118
const [charCount, setCharCount] = useState(0)
119+
const [wasInitialized, setWasInitialized] = useState(false)
119120

120121
if (!appStateContext) {
121122
throw new Error('useAppState must be used within a AppStateProvider')
@@ -147,13 +148,19 @@ const SectionCard = ({ sectionIdx }: SectionCardProps) => {
147148
}
148149
appStateContext?.dispatch({ type: 'UPDATE_SECTION', payload: { sectionIdx: sectionIdx, section: updatedSection } })
149150
const content = updatedSection.content || ''
150-
setCharCount(content.length)
151+
152+
// limit the character count to 2000
153+
if (content.length > sectionCharacterLimit) {
154+
updatedSection.content = content.slice(0, sectionCharacterLimit)
155+
}
151156

157+
setCharCount(content.length)
152158
setIsLoading(false)
153159
}
154160

155-
if (sectionContent === '' && !isLoading) {
161+
if (sectionContent === '' && !isLoading && !wasInitialized) {
156162
fetchSectionContent(sectionTitle, sectionDescription)
163+
setWasInitialized(true)
157164
}
158165

159166
return (

0 commit comments

Comments
 (0)