Skip to content

Commit 3428f21

Browse files
authored
Merge pull request #16 from oslabs-beta/ronak/css
Ronak/css
2 parents 08b64d1 + 4abcf6a commit 3428f21

20 files changed

+239
-132
lines changed

package-lock.json

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

src/assets/splash.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
flex-direction: column;
1010
justify-content: center;
1111
align-items: center;
12+
margin: 0;
13+
border: 0.3rem solid transparent;
14+
border-image: linear-gradient(45deg, #971afa, #3bbde8);
15+
border-image-slice: 1;
1216
}
1317

1418
h3 {
@@ -30,22 +34,23 @@
3034
width: auto;
3135
}
3236

33-
.loader {
37+
/* .loader {
3438
border: 5px solid #971afa;
3539
border-radius: 50%;
3640
border-top: 5px solid #272727;
3741
width: 40px;
3842
height: 40px;
3943
-webkit-animation: spin 1s linear infinite;
40-
/* Safari */
44+
Safari
4145
animation: spin 1s linear infinite;
4246
margin: auto;
4347
left: 0;
4448
right: 0;
4549
top: 0px;
4650
bottom: 0;
4751
position: fixed;
48-
}
52+
border: 0.2rem solid #971afa;
53+
} */
4954

5055
/* Safari */
5156
@-webkit-keyframes spin {

src/components/Body.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import CodePreview from './CodePreview';
66
import '../stylesheets/BodyContainer.css';
77
import { DragDropContext } from 'react-beautiful-dnd';
88
import { useDispatch, useSelector } from 'react-redux';
9-
import { addComponent, combineComponents, refreshCode, reorderComponent } from '../redux/canvasSlice';
9+
import { addComponent, combineComponents, refreshCode, reorderComponent, saveComponentCode } from '../redux/canvasSlice';
1010
// import ExportModal from './ExportModal';
1111

1212
const Body = () => {
@@ -36,6 +36,7 @@ const Body = () => {
3636
dispatch(reorderComponent(dragItem));
3737
dispatch(refreshCode());
3838
}
39+
dispatch(saveComponentCode());
3940
}
4041

4142
// const show = useSelector((state) => state.nav.showModal);

src/components/CSSCodeEditor.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
import React from 'react';
22
import Editor from '@monaco-editor/react';
33
import { useSelector } from 'react-redux';
4+
import { useDispatch } from 'react-redux';
5+
import { updateCss } from '../redux/canvasSlice';
46

57
const CSSCodeEditor = () => {
68
const theme = useSelector((state) => state.theme.currTheme);
79
const cssCode = useSelector((state) => state.canvas.cssCode);
10+
const dispatch = useDispatch();
811

9-
const onChange = (newValue) => console.log('cssEditorCode after edits: ', newValue);
12+
const onChange = (newValue) =>{
13+
console.log('cssEditorCode after edits: ', newValue);
14+
dispatch(updateCss(newValue));
15+
}
1016

1117
console.log('code in CSSCodeEditor: ', cssCode);
1218

src/components/CanvasItem.jsx

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,21 @@ import React from 'react';
22
import DeleteCanvasItem from './DeleteCanvasItem';
33
import '../stylesheets/Canvas.css';
44
import { useDispatch, useSelector } from 'react-redux';
5-
import { renderComponentCode, saveComponentCode } from '../redux/canvasSlice';
5+
import { renderComponentCode, saveComponentCode, setCurrentFile } from '../redux/canvasSlice';
66

77
const CanvasItem = (props) => {
88
const dispatch = useDispatch();
9-
let currentFile = useSelector((state) => state.canvas.currentFile);
10-
const currentCode = useSelector((state) => state.canvas.code);
9+
// let currentFile = useSelector((state) => state.canvas.currentFile);
10+
const custom = useSelector((state) => state.canvas.customComponents);
1111

1212
function onClick(e) {
1313
const name = e.target.innerText + '.jsx';
14-
dispatch(saveComponentCode({ currentCode, currentFile }));
15-
dispatch(renderComponentCode({ name }));
14+
// dispatch(saveComponentCode({ currentCode, currentFile }));
15+
if (custom.includes(e.target.innerText)) {
16+
dispatch(saveComponentCode());
17+
dispatch(setCurrentFile(name));
18+
dispatch(renderComponentCode({ name }));
19+
}
1620
}
1721

1822
return (
@@ -26,8 +30,10 @@ const CanvasItem = (props) => {
2630
id={props.ind + '-' + props.name}
2731
onClick={onClick}
2832
>
29-
<div className='w-1/3 text-center max-w-7xl'>
30-
<p key={props.ind} id='canvas-item-label'>{props.name}</p>
33+
<div className='text-center max-w-7xl'>
34+
<p key={props.ind} id='canvas-item-label'>
35+
{props.name}
36+
</p>
3137
</div>
3238

3339
<div className='flex justify-center items-center absolute top-0 right-0 col-span-1'>

src/components/CompCreator.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { useSelector, useDispatch } from 'react-redux';
3-
import { createComponent, refreshCode } from '../redux/canvasSlice';
3+
import { createComponent, refreshCode, saveComponentCode } from '../redux/canvasSlice';
44
import '../stylesheets/CompCreator.css';
55

66
const CompCreator = () => {
@@ -15,6 +15,7 @@ const CompCreator = () => {
1515
if (!custom.includes(text)) {
1616
dispatch(createComponent({ text }));
1717
dispatch(refreshCode());
18+
dispatch(saveComponentCode());
1819
} else {
1920
alert('Component with that name already exists');
2021
}

src/components/ExportApp.jsx

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ import "./styles.css";
2525
var mountNode = document.getElementById("root");
2626
ReactDOM.render(<App />, mountNode);`;
2727

28-
const tags = snapshot.tags.map(ele => {
28+
const appFile = snapshot.files[0];
29+
const tags = appFile.fileTags.map((ele) => {
2930
return ele.slice(1);
3031
});
3132

32-
const templateAppJS = `${snapshot.imports}import { hot } from 'react-hot-loader/root';
33+
const templateAppJS = `${appFile.fileImports.join('')}import { hot } from 'react-hot-loader/root';
3334
3435
const App = () => {
3536
return (
@@ -43,33 +44,6 @@ const App = () => {
4344
4445
export default hot(App);`;
4546

46-
const templateCSS = `html {
47-
box-sizing: border-box;
48-
height: 100%;
49-
}
50-
body {
51-
margin: 0;
52-
padding-top: 20%;
53-
overflow: hidden;
54-
background-color: #272727;
55-
font-family: "Helvetica Neue";
56-
display: flex;
57-
justify-content: center;
58-
text-align: center;
59-
height: 100%;
60-
}
61-
h1 {
62-
color: white;
63-
font-size: 3rem;
64-
}
65-
p {
66-
color: white;
67-
font-size: 1.5rem;
68-
}
69-
.default-spans {
70-
color: #4338ca;
71-
}`;
72-
7347
const templatePackage = `{
7448
"name": "exported-project",
7549
"version": "1.0.0",
@@ -223,7 +197,7 @@ module.exports = config;`;
223197
]
224198
}`;
225199

226-
const path = df();
200+
const path = df(); //module to find download folder
227201
const name = 'Exported_Project_' + Math.floor(Math.random() * 100).toString();
228202

229203
//iterate through files array, create file for each, fill with its code key
@@ -235,10 +209,12 @@ module.exports = config;`;
235209
fse.outputFile(path + `/${name}/src/${curr.name}`, curr.fileCode);
236210
}
237211

212+
const css = snapshot.cssCode;
213+
238214
fse.outputFile(path + `/${name}/dist/index.html`, templateHTML);
239215
fse.outputFile(path + `/${name}/src/index.js`, templateIndexJS);
240216
fse.outputFile(path + `/${name}/src/App.js`, templateAppJS);
241-
fse.outputFile(path + `/${name}/src/styles.css`, templateCSS);
217+
fse.outputFile(path + `/${name}/src/styles.css`, css);
242218
fse.outputFile(path + `/${name}/.gitignore`, templateGitIgnore);
243219
fse.outputFile(path + `/${name}/package.json`, templatePackage);
244220
fse.outputFile(path + `/${name}/README.md`, templateReadMe);

src/components/JSCodeEditor.jsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22
import Editor, { monaco, loader } from '@monaco-editor/react';
3-
import { renderComponentCode, saveComponentCode } from '../redux/canvasSlice';
3+
import { renderComponentCode, saveComponentCode, updateJs } from '../redux/canvasSlice';
44
import { useSelector } from 'react-redux';
5+
import { useDispatch } from 'react-redux';
56

67
const path = require('path');
78

@@ -23,8 +24,14 @@ loader.config({
2324
const JSCodeEditor = () => {
2425
const theme = useSelector((state) => state.theme.currTheme);
2526
const code = useSelector((state) => state.canvas.code);
26-
27-
const onChange = (newValue) => console.log('updatedValue:', newValue);
27+
const dispatch = useDispatch();
28+
29+
const onChange = (newValue) => {
30+
console.log('updatedValue:', newValue);
31+
dispatch(updateJs(newValue));
32+
dispatch(saveComponentCode());
33+
}
34+
2835
console.log('code in JSCodeEditor: ', code);
2936

3037
return (

src/components/Navigation.jsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import '../stylesheets/Navigation.css';
3-
import { toggleLeftPanel, saveComponentCode } from '../redux/navigationSlice';
4-
import { clearProject } from '../redux/canvasSlice';
3+
import { toggleLeftPanel } from '../redux/navigationSlice';
4+
import { clearProject, saveComponentCode } from '../redux/canvasSlice';
55
import { useSelector, useDispatch } from 'react-redux';
66
import exportApp from './ExportApp';
77
import { FaPencilRuler, FaFolderOpen, FaSave, FaDownload, FaTrash, FaRegWindowRestore } from 'react-icons/fa';
@@ -28,6 +28,10 @@ const Navigation = () => {
2828
if (confirm('Are you sure you want to clear project?')) dispatch(clearProject());
2929
};
3030

31+
const exportClick = () => {
32+
exportApp(snapshot);
33+
}
34+
3135
// component code should save before exporting
3236
// let currentFile = useSelector((state) => state.canvas.currentFile);
3337
// const currentCode = useSelector((state) => state.canvas.code);

src/redux/canvasSlice.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const initialState = {
5858
fileCode: '',
5959
fileTags: [],
6060
fileImports: [],
61-
fileComponents: [],
61+
fileComponents: [],
6262
},
6363
],
6464
currentFile: 'App.js',
@@ -69,12 +69,10 @@ export const canvasSlice = createSlice({
6969
initialState,
7070
reducers: {
7171
addComponent: (state, action) => {
72-
7372
state.components.splice(action.payload.destination.index, 0, action.payload.draggableId);
7473
state.tags.splice(action.payload.destination.index, 0, '\n\t\t\t' + state.codeList[action.payload.draggableId]);
7574
},
7675
deleteComponent: (state, action) => {
77-
7876
if (confirm(`Delete this component?\n${action.payload.name + ' in position ' + action.payload.index}`)) {
7977
state.components.splice(action.payload.index, 1);
8078
state.tags.splice(action.payload.index, 1);
@@ -90,7 +88,6 @@ export const canvasSlice = createSlice({
9088
}
9189
},
9290
reorderComponent: (state, action) => {
93-
9491
const [item] = state.components.splice(action.payload.source.index, 1);
9592
state.components.splice(action.payload.destination.index, 0, item);
9693
const [tag] = state.tags.splice(action.payload.source.index, 1);
@@ -179,6 +176,12 @@ export const canvasSlice = createSlice({
179176
}
180177
});
181178
},
179+
updateCss: (state, action) => {
180+
state.cssCode = action.payload;
181+
},
182+
updateJs: (state, action) => {
183+
state.code = action.payload;
184+
},
182185
},
183186
});
184187

@@ -194,6 +197,8 @@ export const {
194197
renderComponentCode,
195198
saveComponentCode,
196199
setCurrentFile,
200+
updateCss,
201+
updateJs,
197202
} = canvasSlice.actions;
198203

199204
export default canvasSlice.reducer;

0 commit comments

Comments
 (0)