1- import React , { useState , useContext } from 'react' ;
1+ import React , { useState , useContext } from 'react'
22import styles from './Draft.module.css'
3- import { useLocation } from 'react-router-dom' ;
3+ import { useLocation } from 'react-router-dom'
44import TitleCard from '../../components/DraftCards/TitleCard'
55import SectionCard from '../../components/DraftCards/SectionCard'
6- import { Document , Packer , Paragraph , TextRun } from 'docx' ;
7- import { saveAs } from 'file-saver' ;
8- import { AppStateContext } from "../../state/AppProvider" ;
9- import { CommandBarButton , Stack } from '@fluentui/react' ;
10-
6+ import { Document , Packer , Paragraph , TextRun } from 'docx'
7+ import { saveAs } from 'file-saver'
8+ import { AppStateContext } from '../../state/AppProvider'
9+ import { CommandBarButton , Stack } from '@fluentui/react'
1110
1211const Draft = ( ) : JSX . Element => {
1312 const appStateContext = useContext ( AppStateContext )
14- const location = useLocation ( ) ;
15- const [ title , setTitle ] = useState ( '' ) ;
13+ const location = useLocation ( )
14+ const [ title , setTitle ] = useState ( '' )
1615
1716 // get draftedDocument from context
18- const draftedDocument = appStateContext ?. state . draftedDocument ;
19- const sections = draftedDocument ?. sections ?? [ ] ;
17+ const draftedDocument = appStateContext ?. state . draftedDocument
18+ const sections = draftedDocument ?. sections ?? [ ]
2019
2120 const exportToWord = ( ) => {
2221 const doc = new Document ( {
@@ -29,51 +28,54 @@ const Draft = (): JSX.Element => {
2928 new TextRun ( {
3029 text : title ,
3130 bold : true ,
32- size : 24 ,
31+ size : 24
3332 } ) ,
3433 new TextRun ( {
35- text : "\n" ,
36- break : 1 , // Add a new line after the title
37- } ) , ] ,
34+ text : '\n' ,
35+ break : 1 // Add a new line after the title
36+ } )
37+ ]
3838 } ) ,
39- ...sections . map ( ( section , index ) => (
40- new Paragraph ( {
41- children : [
42- new TextRun ( {
43- text : `Section ${ index + 1 } : ${ section . title } ` ,
44- bold : true ,
45- size : 20 ,
46- } ) ,
47- new TextRun ( {
48- text : "\n" ,
49- break : 1 , // Add a new line after the section title
50- } ) ,
51- new TextRun ( {
52- text : section . content ,
53- size : 16 ,
54- } ) ,
55- new TextRun ( {
56- text : "\n" ,
57- break : 1 , // Add a new line after the content
58- } ) , ] ,
59- } )
60- ) ) ,
61- ] ,
62- } ,
63- ] ,
64- } ) ;
39+ ...sections . map (
40+ ( section , index ) =>
41+ new Paragraph ( {
42+ children : [
43+ new TextRun ( {
44+ text : `Section ${ index + 1 } : ${ section . title } ` ,
45+ bold : true ,
46+ size : 20
47+ } ) ,
48+ new TextRun ( {
49+ text : '\n' ,
50+ break : 1 // Add a new line after the section title
51+ } ) ,
52+ new TextRun ( {
53+ text : section . content ,
54+ size : 16
55+ } ) ,
56+ new TextRun ( {
57+ text : '\n' ,
58+ break : 1 // Add a new line after the content
59+ } )
60+ ]
61+ } )
62+ )
63+ ]
64+ }
65+ ]
66+ } )
6567
6668 Packer . toBlob ( doc ) . then ( blob => {
67- saveAs ( blob , `DraftTemplate-${ sanitizeTitle ( title ) } .docx` ) ;
68- } ) ;
69- } ;
69+ saveAs ( blob , `DraftTemplate-${ sanitizeTitle ( title ) } .docx` )
70+ } )
71+ }
7072
7173 const handleTitleChange = ( newTitle : string ) => {
72- setTitle ( newTitle ) ;
73- } ;
74+ setTitle ( newTitle )
75+ }
7476
7577 function sanitizeTitle ( title : string ) : string {
76- return title . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '' ) ;
78+ return title . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '' )
7779 }
7880
7981 return (
@@ -83,31 +85,33 @@ const Draft = (): JSX.Element => {
8385 </ div >
8486
8587 < TitleCard onTitleChange = { handleTitleChange } />
86- { ( sections ?? [ ] ) . map ( ( _ , index ) => ( < SectionCard key = { index } sectionIdx = { index } /> ) ) }
88+ { ( sections ?? [ ] ) . map ( ( _ , index ) => (
89+ < SectionCard key = { index } sectionIdx = { index } />
90+ ) ) }
8791 < Stack >
8892 < CommandBarButton
89- role = "button"
90- styles = { {
91- icon : {
92- color : '#FFFFFF'
93- } ,
94- iconDisabled : {
95- color : '#BDBDBD !important'
96- } ,
97- root : {
98- color : '#FFFFFF' ,
99- background : '#1367CF'
100- } ,
101- rootDisabled : {
102- background : '#F0F0F0'
103- }
104- } }
105- className = { styles . exportDocumentIcon }
106- iconProps = { { iconName : 'WordDocument' } }
107- onClick = { exportToWord } //Update for Document Generation
108- aria-label = "export document"
109- text = "Export Document"
110- />
93+ role = "button"
94+ styles = { {
95+ icon : {
96+ color : '#FFFFFF'
97+ } ,
98+ iconDisabled : {
99+ color : '#BDBDBD !important'
100+ } ,
101+ root : {
102+ color : '#FFFFFF' ,
103+ background : '#1367CF'
104+ } ,
105+ rootDisabled : {
106+ background : '#F0F0F0'
107+ }
108+ } }
109+ className = { styles . exportDocumentIcon }
110+ iconProps = { { iconName : 'WordDocument' } }
111+ onClick = { exportToWord }
112+ aria-label = "export document"
113+ text = "Export Document"
114+ />
111115 </ Stack >
112116 </ div >
113117 )
0 commit comments