Skip to content

Commit 8250068

Browse files
authored
Merge pull request #24 from MadinventorZero/stylehotloading
Stylehotloading
2 parents 7b0b96f + 27b853b commit 8250068

File tree

4 files changed

+27
-7
lines changed

4 files changed

+27
-7
lines changed

app/src/components/bottom/StylesEditor.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ import useResizeObserver from '../../tree/useResizeObserver';
1313
import { string } from 'prop-types';
1414
import Fab from '@material-ui/core/Fab';
1515
import SaveIcon from '@material-ui/icons/Save';
16+
import cssRefresher from '../../helperFunctions/cssRefresh';
1617

1718
const StylesEditor: React.FC<{
1819
theme: string | null;
1920
setTheme: any | null;
2021
}> = ({ theme, setTheme }) => {
2122
const wrapper = useRef();
2223
const [css, setCss] = useState();
23-
// const [state, dispatch] = useContext(StateContext);
2424

2525
useEffect(() => {
26-
loadFile();
26+
loadFile();
2727
}, []);
2828

2929
const loadFile = () => {
@@ -52,8 +52,8 @@ const StylesEditor: React.FC<{
5252
})
5353
.then(response => response.text())
5454
.then((data) => {
55-
// setCss(data);
56-
//message save!
55+
// Removes old link to css and creates a new stylesheet link on demo render
56+
cssRefresher();
5757
});
5858
}
5959
const saveCss = (e) => {

app/src/components/main/DemoRender.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@ import React, {
44
} from 'react';
55
import Button from '@material-ui/core/Button';
66
import Box from '@material-ui/core/Box';
7-
import './renderDemo.css';
87
import StateContext from '../../context/context';
9-
8+
import cssRefresher from '../../helperFunctions/cssRefresh';
109

1110
const DemoRender = (props): JSX.Element => {
1211
const [components, setComponents] = useState([]);
@@ -50,6 +49,11 @@ const DemoRender = (props): JSX.Element => {
5049
setComponents(renderedComponents);
5150
}, [state.components, state.canvasFocus]);
5251

52+
useEffect(() => {
53+
cssRefresher();
54+
}, [])
55+
56+
5357
return (
5458
<div id={'renderFocus'} style={demoContainerStyle}>
5559
{components.map((component, index) => component)}

app/src/components/main/renderDemo.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
.btn {
55
height: 20px;
66
width: 100px;
7-
background-color: #cc0707;
7+
background-color: #ffffff
88
}
99

1010

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// 100% Caret
2+
// Removes old link to css and creates a new stylesheet link on demo render
3+
const cssRefresher = () => {
4+
const oldStylesheet = document.getElementById('Render Stylesheet')
5+
if (oldStylesheet !== null) oldStylesheet.remove();
6+
const rando = Math.random() * 100000;
7+
const newStylesheet = document.createElement("LINK");
8+
newStylesheet.setAttribute("rel", "stylesheet")
9+
newStylesheet.setAttribute("type", "text/css");
10+
newStylesheet.setAttribute("href", `/demoRender?${rando}`);
11+
newStylesheet.setAttribute("id", 'Render Stylesheet');
12+
document.getElementById('renderFocus').append(newStylesheet);
13+
}
14+
15+
16+
export default cssRefresher;

0 commit comments

Comments
 (0)