Skip to content

Commit 728621f

Browse files
Rachel Kucharskisophia-buiMatteoDiteratvanek
committed
Export button working with components stored in zip
Co-authored-by: Sophia Bui <[email protected]> Co-authored-by: Matteo <[email protected]> Co-authored-by: Adam Vanek <[email protected]>
1 parent 70eee1f commit 728621f

File tree

3 files changed

+26
-34
lines changed

3 files changed

+26
-34
lines changed

app/src/components/right/ExportButton.tsx

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import Button from '@mui/material/Button';
77
import exportProject from '../../utils/exportProject.util';
88
import createModal from './createModal';
99
import { useSelector } from 'react-redux';
10-
10+
import { RootState } from '../../redux/store';
11+
const JSZip = require("jszip");
12+
import { saveAs } from 'file-saver';
1113

1214
export default function ExportButton() {
1315
const [modal, setModal] = useState(null);
14-
const state = useSelector(store => store.appState)
16+
const state = useSelector((store: RootState) => store.appState);
1517

1618
const genOptions: string[] = [
1719
'Export components',
@@ -53,41 +55,22 @@ export default function ExportButton() {
5355

5456
//This is exclusive to the electron app
5557
// 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+
5971
closeModal();
6072
};
6173

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-
9174
setModal(
9275
createModal({
9376
closeModal,

package-lock.json

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,12 @@
157157
"esbuild-wasm": "^0.14.51",
158158
"eslint-plugin-react-hooks": "^4.6.0",
159159
"express-session": "^1.17.3",
160+
"file-saver": "^2.0.5",
160161
"fs": "^0.0.1-security",
161162
"graphql": "^16.6.0",
162163
"identity-obj-proxy": "^3.0.0",
163164
"js-cookie": "^3.0.1",
165+
"jszip": "^3.10.1",
164166
"localforage": "^1.10.0",
165167
"lodash": "^4.17.21",
166168
"mongoose": "^5.9.22",

0 commit comments

Comments
 (0)