Skip to content

Commit 765c920

Browse files
added title into draft section
1 parent 4af96ad commit 765c920

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useContext, useEffect, useState } from 'react'
1+
import { useContext, useEffect, useMemo, useState } from 'react'
22
import styles from './Draft.module.css'
33
import { useLocation, useNavigate } from 'react-router-dom'
44
import TitleCard from '../../components/DraftCards/TitleCard'
@@ -16,6 +16,8 @@ const Draft = (): JSX.Element => {
1616

1717
// get draftedDocument from context
1818
const draftedDocument = appStateContext?.state.draftedDocument
19+
const currentChat = appStateContext?.state.currentChat
20+
const draftedDocumentTitle = appStateContext?.state.draftedDocumentTitle;
1921
const sections = draftedDocument?.sections ?? []
2022

2123
const isLoadedSections = appStateContext?.state.isLoadedSections
@@ -27,7 +29,9 @@ const Draft = (): JSX.Element => {
2729

2830
const [isExportButtonDisable, setIsExportButtonDisable] = useState<boolean>(false)
2931

30-
32+
useMemo(() => {
33+
currentChat?.title && appStateContext?.dispatch({ type: 'UPDATE_DRAFTED_DOCUMENT_TITLE', payload: currentChat.title })
34+
}, [currentChat?.title])
3135

3236
useEffect(() => {
3337
sections.forEach((item, index) => {
@@ -45,13 +49,13 @@ const Draft = (): JSX.Element => {
4549

4650

4751
useEffect(() => {
48-
if (isLoadedSections?.length === sections.length) {
52+
if (isLoadedSections?.length === sections.length && draftedDocumentTitle === '') {
4953
setIsExportButtonDisable(false);
5054
}
5155
else {
5256
setIsExportButtonDisable(true);
5357
}
54-
}, [isLoadedSections])
58+
}, [isLoadedSections, draftedDocumentTitle])
5559

5660

5761
if (!draftedDocument) {

0 commit comments

Comments
 (0)