@@ -7,11 +7,13 @@ import Button from '@mui/material/Button';
7
7
import exportProject from '../../utils/exportProject.util' ;
8
8
import createModal from './createModal' ;
9
9
import { useSelector } from 'react-redux' ;
10
-
10
+ import { RootState } from '../../redux/store' ;
11
+ const JSZip = require ( "jszip" ) ;
12
+ import { saveAs } from 'file-saver' ;
11
13
12
14
export default function ExportButton ( ) {
13
15
const [ modal , setModal ] = useState ( null ) ;
14
- const state = useSelector ( store => store . appState )
16
+ const state = useSelector ( ( store : RootState ) => store . appState ) ;
15
17
16
18
const genOptions : string [ ] = [
17
19
'Export components' ,
@@ -53,41 +55,22 @@ export default function ExportButton() {
53
55
54
56
//This is exclusive to the electron app
55
57
// window.api.chooseAppDir();
56
- testchecked = document . getElementById ( 'tests' ) . checked ;
57
- console . log ( ) ;
58
- localStorage . setItem ( 'myCat' , 'Tom' ) ;
58
+ // testchecked = document.getElementById('tests').checked;
59
+
60
+ var zip = new JSZip ( ) ;
61
+ let componentFolder = zip . folder ( 'componentfolder' )
62
+ for ( let i in state . components ) {
63
+ componentFolder . file ( `${ state . components [ i ] . name } .jsx` , state . components [ i ] . code )
64
+ }
65
+ zip . generateAsync ( { type :"blob" } )
66
+ . then ( function ( content ) {
67
+ // see FileSaver.js
68
+ saveAs ( content , "ReacTypeApp.zip" ) ;
69
+ } ) ;
70
+
59
71
closeModal ( ) ;
60
72
} ;
61
73
62
- // const testerFunc = () => {
63
- // exportProject(
64
- // path,
65
- // state.name
66
- // ? state.name
67
- // : 'New_ReacType_Project_' + Math.ceil(Math.random() * 99).toString(),
68
- // genOption,
69
- // testchecked,
70
- // state.projectType,
71
- // state.components,
72
- // state.rootComponents
73
- // )
74
- // }
75
-
76
- // const testerFunc2 = () => {
77
- // const myFile = new File([])
78
- // exportProject(
79
- // path,
80
- // state.name
81
- // ? state.name
82
- // : 'New_ReacType_Project_' + Math.ceil(Math.random() * 99).toString(),
83
- // genOption,
84
- // testchecked,
85
- // state.projectType,
86
- // state.components,
87
- // state.rootComponents
88
- // )
89
- // }
90
-
91
74
setModal (
92
75
createModal ( {
93
76
closeModal,
0 commit comments