Skip to content

Commit df8c1cb

Browse files
author
Rachel Kucharski
committed
CSS save & export working
1 parent 294060f commit df8c1cb

File tree

4 files changed

+63
-48
lines changed

4 files changed

+63
-48
lines changed

app/src/components/bottom/StylesEditor.tsx

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -20,45 +20,50 @@ const StylesEditor: React.FC<{
2020
}> = ({ theme, setTheme }) => {
2121
const wrapper = useRef();
2222
const [css, setCss] = useState();
23+
24+
let currentCss = localStorage.getItem('css');
25+
26+
//This was being used for the demo
2327

24-
useEffect(() => {
25-
loadFile();
26-
}, []);
28+
// useEffect(() => {
29+
// loadFile();
30+
// }, []);
2731

28-
const loadFile = () => {
29-
const myHeaders = new Headers({
30-
'Content-Type': 'text/css',
31-
Accept: 'text/css',
32-
});
33-
fetch(`${serverURL}/demoRender`, {
34-
headers: myHeaders,
35-
})
36-
.then(response => response.text())
37-
.then((data) => {
38-
setCss(data);
39-
});
40-
}
32+
// const loadFile = () => {
33+
// const myHeaders = new Headers({
34+
// 'Content-Type': 'text/css',
35+
// Accept: 'text/css',
36+
// });
37+
// fetch(`${serverURL}/demoRender`, {
38+
// headers: myHeaders,
39+
// })
40+
// .then(response => response.text())
41+
// .then((data) => {
42+
// setCss(data);
43+
// });
44+
// }
4145

42-
const saveFile = () => {
43-
console.log(css)
44-
fetch(`${serverURL}/user-styles/save`, {
45-
method: 'POST',
46-
headers: { 'Content-Type': 'application/json' },
47-
body: JSON.stringify({ data: css }),
48-
})
49-
.then(response => response.text())
50-
.then((data) => {
51-
// Removes old link to css and creates a new stylesheet link on demo render
52-
cssRefresher();
53-
});
54-
}
46+
// const saveFile = () => {
47+
// fetch(`${serverURL}/user-styles/save`, {
48+
// method: 'POST',
49+
// headers: { 'Content-Type': 'application/json' },
50+
// body: JSON.stringify({ data: css }),
51+
// })
52+
// .then(response => response.text())
53+
// .then((data) => {
54+
// // Removes old link to css and creates a new stylesheet link on demo render
55+
// cssRefresher();
56+
// });
57+
// }
58+
59+
//refactored this function to store the css on local storage rather than invoke saveFile()
5560
const saveCss = (e) => {
5661
e.preventDefault();
57-
saveFile();
62+
localStorage.setItem('css', currentCss)
5863
}
5964

6065
const handleChange = (text) => {
61-
setCss(text);
66+
currentCss = text;
6267
}
6368

6469
return (
@@ -77,7 +82,7 @@ const StylesEditor: React.FC<{
7782
width="100%"
7883
height="100%"
7984
onChange={handleChange}
80-
value={css}
85+
value={currentCss}
8186
name="Css_div"
8287
fontSize={16}
8388
tabSize={2}

app/src/components/main/DemoRender.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ const DemoRender = (): JSX.Element => {
175175
}
176176
});
177177

178-
useEffect(() => {
179-
cssRefresher();
180-
}, []);
178+
// useEffect(() => {
179+
// cssRefresher();
180+
// }, []);
181181

182182
useEffect(() => {
183183
iframe.current.contentWindow.postMessage(code, '*');

app/src/components/right/ExportButton.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import exportProject from '../../utils/exportProject.util';
88
import createModal from './createModal';
99
import { useSelector } from 'react-redux';
1010
import { RootState } from '../../redux/store';
11-
const JSZip = require("jszip");
12-
import { saveAs } from 'file-saver';
11+
import zipFiles from '../../helperFunctions/zipFiles';
1312

1413
export default function ExportButton() {
1514
const [modal, setModal] = useState(null);
@@ -56,17 +55,7 @@ export default function ExportButton() {
5655
//This is exclusive to the electron app
5756
// window.api.chooseAppDir();
5857
// 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-
});
58+
zipFiles(state);
7059

7160
closeModal();
7261
};

app/src/helperFunctions/zipFiles.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { saveAs } from 'file-saver';
2+
const JSZip = require("jszip");
3+
4+
const zipFiles = (state) => {
5+
var zip = new JSZip();
6+
let reacTypeApp = zip.folder('ReacTypeApp');
7+
let componentFolder = reacTypeApp.folder('componentfolder');
8+
for (let i in state.components){
9+
componentFolder.file(`${state.components[i].name}.jsx`, state.components[i].code);
10+
}
11+
if(localStorage.getItem('css')){
12+
reacTypeApp.file('style.css', localStorage.getItem('css'));
13+
}
14+
zip.generateAsync({type:"blob"})
15+
.then(function(content) {
16+
// see FileSaver.js
17+
saveAs(content, "ReacTypeApp.zip");
18+
});
19+
};
20+
21+
export default zipFiles;

0 commit comments

Comments
 (0)